Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inherit_from: .rubocop_todo.yml
50 changes: 50 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-10-04 23:17:28 +0530 using RuboCop version 0.59.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
Metrics/AbcSize:
Max: 31

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 212

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 10
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 19

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 6

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 1
Style/MethodMissingSuper:
Exclude:
- 'lib/ruby_http_client.rb'

# Offense count: 1
Style/MissingRespondToMissing:
Exclude:
- 'lib/ruby_http_client.rb'

# Offense count: 10
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 117
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ env:

language: ruby
rvm:
- 2.2
- 2.2

before_install:
- gem install minitest
- gem install simplecov
- bundle install

notifications:
hipchat:
Expand All @@ -28,6 +27,7 @@ before_script:

script:
- rake
- rubocop

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
3 changes: 2 additions & 1 deletion lib/ruby_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def make_request(http, request)
# - Request object
def build_http(host, port)
params = [host, port]
params = params + @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
params += @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
add_ssl(Net::HTTP.new(*params))
end

Expand Down Expand Up @@ -235,6 +235,7 @@ def method_missing(name, *args, &_block)
end
# We have reached the end of the method chain, make the API call
return build_request(name, args) if @methods.include?(name.to_s)

# Add a segment to the URL
_(name)
end
Expand Down
5 changes: 3 additions & 2 deletions ruby_http_client.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
Expand All @@ -16,6 +15,8 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(/^(test|spec|features)/)
spec.require_paths = ['lib']

spec.add_development_dependency 'minitest'
spec.add_development_dependency 'rake', '~> 0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'simplecov', '~> 0'
end
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
require 'simplecov'
SimpleCov.start
end

28 changes: 14 additions & 14 deletions test/test_ruby_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def setup
')
@host = 'http://localhost:4010'
@version = 'v3'
@http_options = {open_timeout: 60, read_timeout: 60}
@http_options = { open_timeout: 60, read_timeout: 60 }
@client = MockRequest.new(host: @host,
request_headers: @headers,
version: @version)
@client_with_options = MockRequest.new(host: @host,
request_headers: @headers,
version: @version,
http_options: @http_options)
request_headers: @headers,
version: @version,
http_options: @http_options)
end

def test_init
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_add_version

def test_build_query_params
url = ''
query_params = { 'limit' => 100, 'offset' => 0, 'categories' => ['category1', 'category2'] }
query_params = { 'limit' => 100, 'offset' => 0, 'categories' => %w[category1 category2] }
url = @client.build_query_params(url, query_params)
assert_equal('?limit=100&offset=0&categories=category1&categories=category2', url)
end
Expand Down Expand Up @@ -97,8 +97,8 @@ def test_build_request
args = nil
response = @client.build_request(name, args)
assert_equal(200, response.status_code)
assert_equal({'message' => 'success'}, response.body)
assert_equal({'headers' => 'test'}, response.headers)
assert_equal({ 'message' => 'success' }, response.body)
assert_equal({ 'headers' => 'test' }, response.headers)
end

def test_build_request_post_empty_content_type
Expand All @@ -109,7 +109,7 @@ def test_build_request_post_empty_content_type
request_headers: headers,
version: 'v3'
)
args = [{'request_body' => {"hogekey" => "hogevalue"}}]
args = [{ 'request_body' => { 'hogekey' => 'hogevalue' } }]
client.build_request('post', args)
assert_equal('application/json', client.request['Content-Type'])
assert_equal('{"hogekey":"hogevalue"}', client.request.body)
Expand Down Expand Up @@ -149,10 +149,10 @@ def test_build_request_post_multipart
}
client = MockRequest.new(
host: 'https://localhost',
request_headers: headers,
request_headers: headers
)
name = 'post'
args = [{'request_body' => 'hogebody'}]
args = [{ 'request_body' => 'hogebody' }]
client.build_request(name, args)
assert_equal('multipart/form-data; boundary=xYzZY', client.request['Content-Type'])
assert_equal('hogebody', client.request.body)
Expand All @@ -174,8 +174,8 @@ def test__
def test_method_missing
response = @client.get
assert_equal(200, response.status_code)
assert_equal({'message' => 'success'}, response.body)
assert_equal({'headers' => 'test'}, response.headers)
assert_equal({ 'message' => 'success' }, response.body)
assert_equal({ 'headers' => 'test' }, response.headers)
end

def test_http_options
Expand Down Expand Up @@ -279,8 +279,8 @@ def test_troubleshooting_exists

# def test_use_cases_exists
# assert(File.file?('./USE_CASES.md'))
# end
# end

def test_license_date_is_updated
license_end_year = IO.read('LICENSE.txt').match(/Copyright \(c\) 2016-(\d{4}) SendGrid/)[1].to_i
current_year = Time.new.year
Expand Down