Skip to content

chore: Missing Dev Dependencies + rubocop #79 #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 5, 2018
Merged
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
45 changes: 45 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
AllCops:
Exclude:
- bin/**/*
- script/**/*
- vendor/**/*
- cookbooks/**/*

ClassLength:
Enabled: false
CyclomaticComplexity:
Enabled: false
Documentation:
Enabled: false
Encoding:
Enabled: false
LineLength:
Enabled: false
MethodLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/ModuleLength:
Enabled: false
PerceivedComplexity:
Enabled: false
Style/SpaceBeforeFirstArg:
Enabled: true
Style/ClassAndModuleChildren:
Enabled: false
Style/EmptyLinesAroundBlockBody:
Enabled: true
Style/FileName:
Enabled: true
Style/RescueModifier:
Enabled: true
Style/StringLiterals:
Enabled: true
Metrics/BlockLength:
Enabled: false
Style/NumericLiterals:
Enabled: false
Style/ExtraSpacing:
Enabled: true
AllowForAlignment: false
ForceEqualSignAlignment: false
25 changes: 24 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,28 @@ Rake::TestTask.new do |t|
t.libs << 'test'
end

desc 'run rubocop'
task :rubocop do
sh 'rubocop -c .rubocop.yml --display-only-fail-level-offenses -D'
end

desc 'run rubocop w/autocorrect'
task :rubocorrect do
sh 'rubocop -c .rubocop.yml -a'
end

desc 'run minitest'
task :minitest do
Rake::Task[:test].invoke
end

desc 'Run tests'
task default: :test
task default: 'test:quick'

namespace :test do
desc 'Run all the quick tests'
task :quick do
Rake::Task['rubocop'].invoke
Rake::Task['minitest'].invoke
end
end
9 changes: 7 additions & 2 deletions lib/ruby_http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Client
# - +proxy_options+ -> A hash of proxy settings.
# (e.g. { host: '127.0.0.1', port: 8080 })
#
def initialize(host: nil, request_headers: nil, version: nil, url_path: nil, http_options: {}, proxy_options: {})
def initialize(host: nil, request_headers: nil, version: nil, url_path: nil, http_options: {}, proxy_options: {}) # rubocop:disable Metrics/ParameterLists
@host = host
@request_headers = request_headers || {}
@version = version
Expand Down 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 @@ -227,6 +227,8 @@ def _(name = nil)
# * *Returns* :
# - Client object or Response object
#
# rubocop:disable Style/MethodMissingSuper
# rubocop:disable Style/MissingRespondToMissing
def method_missing(name, *args, &_block)
# Capture the version
if name.to_s == 'version'
Expand All @@ -235,8 +237,11 @@ 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
# rubocop:enable Style/MethodMissingSuper
# rubocop:enable Style/MissingRespondToMissing
end
end
29 changes: 15 additions & 14 deletions ruby_http_client.gemspec
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@

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|
spec.name = 'ruby_http_client'
spec.version = '3.3.0'
spec.authors = ['Elmer Thomas']
spec.email = 'dx@sendgrid.com'
spec.summary = 'A simple REST client'
spec.name = 'ruby_http_client'
spec.version = '3.3.0'
spec.authors = ['Elmer Thomas']
spec.email = 'dx@sendgrid.com'
spec.summary = 'A simple REST client'
spec.description = 'Quickly and easily access any REST or REST-like API.'
spec.homepage = 'http://github.com/sendgrid/ruby-http-client'
spec.license = 'MIT'
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
spec.test_files = spec.files.grep(/^(test|spec|features)/)
spec.homepage = 'http://github.com/sendgrid/ruby-http-client'
spec.license = 'MIT'
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
spec.test_files = spec.files.grep(/^(test|spec|features)/)
spec.require_paths = ['lib']

spec.add_development_dependency 'rake', '~> 0'
spec.add_development_dependency 'simplecov', '~> 0'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'simplecov'
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

34 changes: 15 additions & 19 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 @@ -273,14 +273,10 @@ def test_troubleshooting_exists
assert(File.file?('./TROUBLESHOOTING.md'))
end

# def test_usage_exists
# assert(File.file?('./USAGE.md'))
# end
def test_use_cases_exists
assert(File.file?('use_cases/README.md'))
end

# def test_use_cases_exists
# assert(File.file?('./USE_CASES.md'))
# 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