Skip to content

Commit 74b7bff

Browse files
Merge pull request #80 from sendgrid/issue#79
Missing Dev Dependencies + rubocop #79
2 parents efc7af6 + ce0376d commit 74b7bff

File tree

6 files changed

+106
-37
lines changed

6 files changed

+106
-37
lines changed

.rubocop.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
AllCops:
2+
Exclude:
3+
- bin/**/*
4+
- script/**/*
5+
- vendor/**/*
6+
- cookbooks/**/*
7+
8+
ClassLength:
9+
Enabled: false
10+
CyclomaticComplexity:
11+
Enabled: false
12+
Documentation:
13+
Enabled: false
14+
Encoding:
15+
Enabled: false
16+
LineLength:
17+
Enabled: false
18+
MethodLength:
19+
Enabled: false
20+
Metrics/AbcSize:
21+
Enabled: false
22+
Metrics/ModuleLength:
23+
Enabled: false
24+
PerceivedComplexity:
25+
Enabled: false
26+
Style/SpaceBeforeFirstArg:
27+
Enabled: true
28+
Style/ClassAndModuleChildren:
29+
Enabled: false
30+
Style/EmptyLinesAroundBlockBody:
31+
Enabled: true
32+
Style/FileName:
33+
Enabled: true
34+
Style/RescueModifier:
35+
Enabled: true
36+
Style/StringLiterals:
37+
Enabled: true
38+
Metrics/BlockLength:
39+
Enabled: false
40+
Style/NumericLiterals:
41+
Enabled: false
42+
Style/ExtraSpacing:
43+
Enabled: true
44+
AllowForAlignment: false
45+
ForceEqualSignAlignment: false

Rakefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,28 @@ Rake::TestTask.new do |t|
44
t.libs << 'test'
55
end
66

7+
desc 'run rubocop'
8+
task :rubocop do
9+
sh 'rubocop -c .rubocop.yml --display-only-fail-level-offenses -D'
10+
end
11+
12+
desc 'run rubocop w/autocorrect'
13+
task :rubocorrect do
14+
sh 'rubocop -c .rubocop.yml -a'
15+
end
16+
17+
desc 'run minitest'
18+
task :minitest do
19+
Rake::Task[:test].invoke
20+
end
21+
722
desc 'Run tests'
8-
task default: :test
23+
task default: 'test:quick'
24+
25+
namespace :test do
26+
desc 'Run all the quick tests'
27+
task :quick do
28+
Rake::Task['rubocop'].invoke
29+
Rake::Task['minitest'].invoke
30+
end
31+
end

lib/ruby_http_client.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Client
3838
# - +proxy_options+ -> A hash of proxy settings.
3939
# (e.g. { host: '127.0.0.1', port: 8080 })
4040
#
41-
def initialize(host: nil, request_headers: nil, version: nil, url_path: nil, http_options: {}, proxy_options: {})
41+
def initialize(host: nil, request_headers: nil, version: nil, url_path: nil, http_options: {}, proxy_options: {}) # rubocop:disable Metrics/ParameterLists
4242
@host = host
4343
@request_headers = request_headers || {}
4444
@version = version
@@ -182,7 +182,7 @@ def make_request(http, request)
182182
# - Request object
183183
def build_http(host, port)
184184
params = [host, port]
185-
params = params + @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
185+
params += @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
186186
add_ssl(Net::HTTP.new(*params))
187187
end
188188

@@ -227,6 +227,8 @@ def _(name = nil)
227227
# * *Returns* :
228228
# - Client object or Response object
229229
#
230+
# rubocop:disable Style/MethodMissingSuper
231+
# rubocop:disable Style/MissingRespondToMissing
230232
def method_missing(name, *args, &_block)
231233
# Capture the version
232234
if name.to_s == 'version'
@@ -235,8 +237,11 @@ def method_missing(name, *args, &_block)
235237
end
236238
# We have reached the end of the method chain, make the API call
237239
return build_request(name, args) if @methods.include?(name.to_s)
240+
238241
# Add a segment to the URL
239242
_(name)
240243
end
244+
# rubocop:enable Style/MethodMissingSuper
245+
# rubocop:enable Style/MissingRespondToMissing
241246
end
242247
end

ruby_http_client.gemspec

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
2-
lib = File.expand_path('../lib', __FILE__)
1+
lib = File.expand_path('lib', __dir__)
32
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
43

54
Gem::Specification.new do |spec|
6-
spec.name = 'ruby_http_client'
7-
spec.version = '3.3.0'
8-
spec.authors = ['Elmer Thomas']
9-
spec.email = '[email protected]'
10-
spec.summary = 'A simple REST client'
5+
spec.name = 'ruby_http_client'
6+
spec.version = '3.3.0'
7+
spec.authors = ['Elmer Thomas']
8+
spec.email = '[email protected]'
9+
spec.summary = 'A simple REST client'
1110
spec.description = 'Quickly and easily access any REST or REST-like API.'
12-
spec.homepage = 'http://github.com/sendgrid/ruby-http-client'
13-
spec.license = 'MIT'
14-
spec.files = `git ls-files -z`.split("\x0")
15-
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
16-
spec.test_files = spec.files.grep(/^(test|spec|features)/)
11+
spec.homepage = 'http://github.com/sendgrid/ruby-http-client'
12+
spec.license = 'MIT'
13+
spec.files = `git ls-files -z`.split("\x0")
14+
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
15+
spec.test_files = spec.files.grep(/^(test|spec|features)/)
1716
spec.require_paths = ['lib']
1817

19-
spec.add_development_dependency 'rake', '~> 0'
20-
spec.add_development_dependency 'simplecov', '~> 0'
18+
spec.add_development_dependency 'minitest'
19+
spec.add_development_dependency 'rake'
20+
spec.add_development_dependency 'rubocop'
21+
spec.add_development_dependency 'simplecov'
2122
end

test/test_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
require 'simplecov'
33
SimpleCov.start
44
end
5-

test/test_ruby_http_client.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def setup
3232
')
3333
@host = 'http://localhost:4010'
3434
@version = 'v3'
35-
@http_options = {open_timeout: 60, read_timeout: 60}
35+
@http_options = { open_timeout: 60, read_timeout: 60 }
3636
@client = MockRequest.new(host: @host,
3737
request_headers: @headers,
3838
version: @version)
3939
@client_with_options = MockRequest.new(host: @host,
40-
request_headers: @headers,
41-
version: @version,
42-
http_options: @http_options)
40+
request_headers: @headers,
41+
version: @version,
42+
http_options: @http_options)
4343
end
4444

4545
def test_init
@@ -67,7 +67,7 @@ def test_add_version
6767

6868
def test_build_query_params
6969
url = ''
70-
query_params = { 'limit' => 100, 'offset' => 0, 'categories' => ['category1', 'category2'] }
70+
query_params = { 'limit' => 100, 'offset' => 0, 'categories' => %w[category1 category2] }
7171
url = @client.build_query_params(url, query_params)
7272
assert_equal('?limit=100&offset=0&categories=category1&categories=category2', url)
7373
end
@@ -97,8 +97,8 @@ def test_build_request
9797
args = nil
9898
response = @client.build_request(name, args)
9999
assert_equal(200, response.status_code)
100-
assert_equal({'message' => 'success'}, response.body)
101-
assert_equal({'headers' => 'test'}, response.headers)
100+
assert_equal({ 'message' => 'success' }, response.body)
101+
assert_equal({ 'headers' => 'test' }, response.headers)
102102
end
103103

104104
def test_build_request_post_empty_content_type
@@ -109,7 +109,7 @@ def test_build_request_post_empty_content_type
109109
request_headers: headers,
110110
version: 'v3'
111111
)
112-
args = [{'request_body' => {"hogekey" => "hogevalue"}}]
112+
args = [{ 'request_body' => { 'hogekey' => 'hogevalue' } }]
113113
client.build_request('post', args)
114114
assert_equal('application/json', client.request['Content-Type'])
115115
assert_equal('{"hogekey":"hogevalue"}', client.request.body)
@@ -149,10 +149,10 @@ def test_build_request_post_multipart
149149
}
150150
client = MockRequest.new(
151151
host: 'https://localhost',
152-
request_headers: headers,
152+
request_headers: headers
153153
)
154154
name = 'post'
155-
args = [{'request_body' => 'hogebody'}]
155+
args = [{ 'request_body' => 'hogebody' }]
156156
client.build_request(name, args)
157157
assert_equal('multipart/form-data; boundary=xYzZY', client.request['Content-Type'])
158158
assert_equal('hogebody', client.request.body)
@@ -174,8 +174,8 @@ def test__
174174
def test_method_missing
175175
response = @client.get
176176
assert_equal(200, response.status_code)
177-
assert_equal({'message' => 'success'}, response.body)
178-
assert_equal({'headers' => 'test'}, response.headers)
177+
assert_equal({ 'message' => 'success' }, response.body)
178+
assert_equal({ 'headers' => 'test' }, response.headers)
179179
end
180180

181181
def test_http_options
@@ -273,14 +273,10 @@ def test_troubleshooting_exists
273273
assert(File.file?('./TROUBLESHOOTING.md'))
274274
end
275275

276-
# def test_usage_exists
277-
# assert(File.file?('./USAGE.md'))
278-
# end
276+
def test_use_cases_exists
277+
assert(File.file?('use_cases/README.md'))
278+
end
279279

280-
# def test_use_cases_exists
281-
# assert(File.file?('./USE_CASES.md'))
282-
# end
283-
284280
def test_license_date_is_updated
285281
license_end_year = IO.read('LICENSE.txt').match(/Copyright \(c\) 2016-(\d{4}) SendGrid/)[1].to_i
286282
current_year = Time.new.year

0 commit comments

Comments
 (0)