@@ -33,11 +33,11 @@ def parser
3333 end
3434
3535 def run ( argv = ARGV , env = ENV )
36- exit 1 unless good_run ( argv , env )
36+ exit 1 unless good_run? ( argv , env )
3737
3838 setup_connection
3939
40- client_id = @options [ :client_id ] || ENV [ 'ZOHO_CLIENT_ID' ]
40+ client_id = @options [ :client_id ] || ENV . fetch ( 'ZOHO_CLIENT_ID' , nil )
4141 puts "Reading modules for client ID: #{ client_id } ..."
4242
4343 modules_hashes = ZohoHub ::Settings ::Module . all_json
@@ -50,19 +50,19 @@ def run(argv = ARGV, env = ENV)
5050 end
5151 end
5252
53- def good_run ( argv , env )
53+ def good_run? ( argv , env )
5454 return false unless parse ( argv , env )
5555
5656 true
5757 end
5858
5959 def setup_connection
6060 ZohoHub . configure do |config |
61- config . client_id = @options [ :client_id ] || ENV [ 'ZOHO_CLIENT_ID' ]
62- config . secret = @options [ :secret ] || ENV [ 'ZOHO_SECRET' ]
61+ config . client_id = @options [ :client_id ] || ENV . fetch ( 'ZOHO_CLIENT_ID' , nil )
62+ config . secret = @options [ :secret ] || ENV . fetch ( 'ZOHO_SECRET' , nil )
6363 end
6464
65- refresh_token = @options [ :refresh_token ] || ENV [ 'ZOHO_REFRESH_TOKEN' ]
65+ refresh_token = @options [ :refresh_token ] || ENV . fetch ( 'ZOHO_REFRESH_TOKEN' , nil )
6666 token_params = ZohoHub ::Auth . refresh_token ( refresh_token )
6767
6868 if configuration_incomplete? ( refresh_token )
@@ -84,9 +84,7 @@ def cache_module_info(info)
8484 FileUtils . mkdir_p ( modules_path )
8585 file_name = File . join ( modules_path , "#{ info [ :api_name ] } .json" )
8686
87- File . open ( file_name , 'w' ) do |file |
88- file . write ( JSON . pretty_generate ( info ) )
89- end
87+ File . write ( file_name , JSON . pretty_generate ( info ) )
9088
9189 return unless info [ :api_supported ]
9290
@@ -99,23 +97,20 @@ def cache_module_fields(info)
9997 FileUtils . mkdir_p ( fields_path )
10098 file_name = File . join ( fields_path , "#{ info [ :api_name ] } .json" )
10199
102- File . open ( file_name , 'w' ) do |file |
103- file . write ( JSON . pretty_generate ( fields_array ) )
104- end
100+ File . write ( file_name , JSON . pretty_generate ( fields_array ) )
105101 end
106102
107103 def parse ( argv , _env )
108104 parser . parse! ( argv )
109105 true
110106 rescue OptionParser ::ParseError => e
111107 error_output ( e )
108+ false
112109 end
113110
114111 def error_output ( error )
115112 warn "Error: #{ error } "
116113 warn "Try `#{ parser . program_name } server --help' for more information"
117-
118- false
119114 end
120115 end
121116 end
0 commit comments