Skip to content

Commit 75831fe

Browse files
committed
Solve rubocop issues
1 parent cd1f919 commit 75831fe

13 files changed

Lines changed: 53 additions & 57 deletions

Gemfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,16 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
66

77
# Specify your gem's dependencies in zoho_hub.gemspec
88
gemspec
9+
10+
group :development, :test do
11+
gem 'activesupport'
12+
gem 'bundler'
13+
gem 'dotenv'
14+
gem 'pry-byebug'
15+
gem 'rake'
16+
gem 'rspec'
17+
gem 'rubocop'
18+
gem 'rubocop-rspec'
19+
gem 'simplecov'
20+
gem 'webmock'
21+
end

bin/console

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ require 'dotenv'
88
Dotenv.load
99

1010
ZohoHub.configure do |config|
11-
config.client_id = ENV['ZOHO_CLIENT_ID']
12-
config.secret = ENV['ZOHO_SECRET']
13-
config.redirect_uri = ENV['ZOHO_REDIRECT_URI']
11+
config.client_id = ENV.fetch('ZOHO_CLIENT_ID', nil)
12+
config.secret = ENV.fetch('ZOHO_SECRET', nil)
13+
config.redirect_uri = ENV.fetch('ZOHO_REDIRECT_URI', nil)
1414
config.api_domain = ENV['ZOHO_API_DOMAIN'] if ENV['ZOHO_API_DOMAIN']
1515
config.debug = ENV['ZOHO_DEBUG'] || false
1616
end
1717

1818
# We assume that we already have a refresh token, to make things easier here.
1919
puts 'Refreshing token...'
20-
token_params = ZohoHub::Auth.refresh_token(ENV['ZOHO_REFRESH_TOKEN'])
20+
token_params = ZohoHub::Auth.refresh_token(ENV.fetch('ZOHO_REFRESH_TOKEN', nil))
2121
ZohoHub.setup_connection(token_params)
2222

2323
send(:include, ZohoHub)

bin/read

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ require 'dotenv'
1111
Dotenv.load
1212

1313
ZohoHub.configure do |config|
14-
config.client_id = ENV['ZOHO_CLIENT_ID']
15-
config.secret = ENV['ZOHO_SECRET']
14+
config.client_id = ENV.fetch('ZOHO_CLIENT_ID', nil)
15+
config.secret = ENV.fetch('ZOHO_SECRET', nil)
1616
end
1717

18-
token_params = ZohoHub::Auth.refresh_token(ENV['ZOHO_REFRESH_TOKEN'])
18+
token_params = ZohoHub::Auth.refresh_token(ENV.fetch('ZOHO_REFRESH_TOKEN', nil))
1919
ZohoHub.setup_connection(token_params)
2020

21-
puts "Reading modules for client ID: #{ENV['ZOHO_CLIENT_ID']}..."
21+
puts "Reading modules for client ID: #{ENV.fetch('ZOHO_CLIENT_ID', nil)}..."
2222

2323
modules_hashes = ZohoHub::Settings::Module.all_json
2424

@@ -31,9 +31,7 @@ modules_hashes.each do |hash|
3131
FileUtils.mkdir_p(modules_path)
3232
file_name = File.join(modules_path, "#{hash[:api_name]}.json")
3333

34-
File.open(file_name, 'w') do |file|
35-
file.write(JSON.pretty_generate(hash))
36-
end
34+
File.write(file_name, JSON.pretty_generate(hash))
3735

3836
next unless hash[:api_supported]
3937

@@ -42,7 +40,5 @@ modules_hashes.each do |hash|
4240
FileUtils.mkdir_p(fields_path)
4341
file_name = File.join(fields_path, "#{hash[:api_name]}.json")
4442

45-
File.open(file_name, 'w') do |file|
46-
file.write(JSON.pretty_generate(fields_array))
47-
end
43+
File.write(file_name, JSON.pretty_generate(fields_array))
4844
end

bin/zoho_hub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ end
3131

3232
case command
3333
when 'callback-server'
34-
ZohoHub::Cli::CallbackServer.new.run(ARGV[1..-1])
34+
ZohoHub::Cli::CallbackServer.new.run(ARGV[1..])
3535
when 'read-modules'
36-
ZohoHub::Cli::ReadModules.new.run(ARGV[1..-1])
36+
ZohoHub::Cli::ReadModules.new.run(ARGV[1..])
3737
else
3838
$stdout.puts 'Usage:'
3939
$stdout.puts " zoho_hub [command] [options]\n"

lib/zoho_hub/cli/callback_server.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def default_port
3636
end
3737

3838
def run(argv = ARGV, env = ENV)
39-
exit 1 unless good_run(argv, env)
39+
exit 1 unless good_run?(argv, env)
4040

4141
ZohoHub::OauthCallbackServer.set(:port, @options[:port]) if @options[:port]
4242

@@ -47,8 +47,8 @@ def run(argv = ARGV, env = ENV)
4747
callback_url = "http://#{bind_address}:#{bind_port}/#{callback_path}"
4848

4949
ZohoHub.configure do |config|
50-
config.client_id = @options[:client_id] || ENV['ZOHO_CLIENT_ID']
51-
config.secret = @options[:secret] || ENV['ZOHO_SECRET']
50+
config.client_id = @options[:client_id] || ENV.fetch('ZOHO_CLIENT_ID', nil)
51+
config.secret = @options[:secret] || ENV.fetch('ZOHO_SECRET', nil)
5252
config.redirect_uri = callback_url
5353
end
5454

@@ -70,7 +70,7 @@ def configuration_incomplete?
7070
!ZohoHub.configuration.client_id || !ZohoHub.configuration.secret
7171
end
7272

73-
def good_run(argv, env)
73+
def good_run?(argv, env)
7474
return false unless parse(argv, env)
7575

7676
true
@@ -81,13 +81,12 @@ def parse(argv, _env)
8181
true
8282
rescue OptionParser::ParseError => e
8383
error_output(e)
84+
false
8485
end
8586

8687
def error_output(error)
8788
warn "Error: #{error}"
8889
warn "Try `#{parser.program_name} server --help' for more information"
89-
90-
false
9190
end
9291
end
9392
end

lib/zoho_hub/cli/read_modules.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/zoho_hub/with_attributes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def attr_to_zoho_key(attr_name)
5252
end
5353

5454
def zoho_key_translation
55-
@attribute_translation.to_a.map(&:rotate).to_h
55+
@attribute_translation.to_a.to_h { |k, v| [v, k] }
5656
end
5757
end
5858

spec/spec_helper.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
require 'zoho_hub'
1212

1313
ZohoHub.configure do |config|
14-
config.client_id = ENV['ZOHO_CLIENT_ID']
15-
config.secret = ENV['ZOHO_SECRET']
16-
config.redirect_uri = ENV['ZOHO_REDIRECT_URI']
14+
config.client_id = ENV.fetch('ZOHO_CLIENT_ID', nil)
15+
config.secret = ENV.fetch('ZOHO_SECRET', nil)
16+
config.redirect_uri = ENV.fetch('ZOHO_REDIRECT_URI', nil)
1717
end
1818

19-
ZohoHub.setup_connection(access_token: ENV['ZOHO_ACCESS_TOKEN'],
20-
refresh_token: ENV['ZOHO_REFRESH_TOKEN'],
21-
expires_in: ENV['ZOHO_EXPIRES_IN'],
19+
ZohoHub.setup_connection(access_token: ENV.fetch('ZOHO_ACCESS_TOKEN', nil),
20+
refresh_token: ENV.fetch('ZOHO_REFRESH_TOKEN', nil),
21+
expires_in: ENV.fetch('ZOHO_EXPIRES_IN', nil),
2222
api_domain: ENV['ZOHO_API_DOMAIN'] || 'https://crmsandbox.zoho.eu')
2323

2424
RSpec.configure do |config|

spec/zoho_hub/base_record_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
record = test_class.new(response.data.first)
1717

1818
expect(record.my_string).to eq('')
19-
expect(record.my_bool).to eq(false)
19+
expect(record.my_bool).to be(false)
2020
end
2121
end
2222
end

spec/zoho_hub/with_attributes_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
test.assign_attributes(one: 1, two: 2)
4949
expect(test.one).to eq(1)
5050
expect(test.two).to eq(2)
51-
expect(test.three).to eq(nil)
51+
expect(test.three).to be_nil
5252
end
5353
end
5454
end

0 commit comments

Comments
 (0)