Skip to content

Commit 43566d0

Browse files
committed
Housekeeping 🧹
1 parent f96d0eb commit 43566d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2073
-1894
lines changed

.github/workflows/CI.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
with:
2424
bundler-cache: true
2525

26-
# - name: Lint
27-
# run: bundle exec rake lint
26+
- name: Lint
27+
run: bundle exec rake lint
2828

2929
- name: Test
3030
run: bundle exec rake test

.pryrc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# rubocop:disable
22

33
# frozen_string_literal: true
4+
45
# === EDITOR ===
5-
Pry.editor = "vi"
6+
Pry.editor = 'vi'
67

78
# === COLORS ===
8-
unless ENV["PRY_BW"]
9+
unless ENV['PRY_BW']
910
Pry.color = true
10-
Pry.config.theme = "railscasts"
11+
Pry.config.theme = 'railscasts'
1112
end
1213

1314
# === Listing config ===
@@ -25,7 +26,7 @@ Pry.config.ls.private_method_color = :bright_black
2526
# awesome_print gem: great syntax colorized printing
2627
# look at ~/.aprc for more settings for awesome_print
2728
begin
28-
require "awesome_print"
29+
require 'awesome_print'
2930
# The following line enables awesome_print for all pry output,
3031
# and it also enables paging
3132
Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
@@ -35,7 +36,7 @@ begin
3536
Formatter.prepend(Module.new do
3637
def awesome_self(object, type)
3738
if type == :string && @options[:string_limit] && object.inspect.to_s.length > @options[:string_limit]
38-
colorize(object.inspect.to_s[0..@options[:string_limit]] + "...", type)
39+
colorize("#{object.inspect.to_s[0..@options[:string_limit]]}...", type)
3940
else
4041
super(object, type)
4142
end
@@ -46,11 +47,11 @@ begin
4647
AwesomePrint.defaults = {
4748
string_limit: 80,
4849
indent: 2,
49-
multiline: true,
50+
multiline: true
5051
}
5152
AwesomePrint.pry!
5253
rescue err
53-
puts "gem install awesome_print # <-- highly recommended"
54+
puts 'gem install awesome_print # <-- highly recommended'
5455
end
5556

5657
# rubocop:enable

.rubocop.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
AllCops:
22
NewCops: enable # https://docs.rubocop.org/rubocop/1.11/versioning.html#pending-cops
33
SuggestExtensions: false
4-
TargetRubyVersion: 2.6
4+
TargetRubyVersion: 3.2.2
55
Exclude:
66
- bin/**/*
77
- tmp/**/*
88
- vendor/**/*
9+
- test/**/*
910
- lib/shipengine/utils/base58.rb
1011
- !ruby/regexp /(foo|bar|baz)\.rb/
1112

Gemfile

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
# frozen_string_literal: true
22

3-
source "https://rubygems.org"
3+
source 'https://rubygems.org'
44

55
group :development do
6-
gem "guard"
7-
gem "guard-minitest"
8-
gem "pry"
9-
gem "solargraph", require: false
10-
gem "yard"
11-
gem "ruby-debug-ide", require: false
12-
gem "rubocop-shopify", require: false
13-
gem "awesome_print"
14-
gem "overcommit"
6+
gem 'awesome_print'
7+
gem 'guard'
8+
gem 'guard-minitest'
9+
gem 'overcommit'
10+
gem 'pry'
11+
gem 'rubocop-shopify', require: false
12+
gem 'ruby-debug-ide', require: false
13+
gem 'solargraph', require: false
14+
gem 'yard'
1515
end
1616

1717
group :test do
18-
gem "minitest"
19-
gem "minitest-fail-fast"
20-
gem "minitest-focus"
21-
gem "minitest-hooks"
22-
gem "minitest-line"
23-
gem "minitest-tagz"
24-
gem "minitest-reporters"
25-
gem "simplecov", require: false
26-
gem "webmock"
27-
gem "spy"
18+
gem 'minitest'
19+
gem 'minitest-fail-fast'
20+
gem 'minitest-focus'
21+
gem 'minitest-hooks'
22+
gem 'minitest-line'
23+
gem 'minitest-reporters'
24+
gem 'minitest-tagz'
25+
gem 'simplecov', require: false
26+
gem 'spy'
27+
gem 'webmock'
2828
end
2929

3030
group :test, :development do
31-
gem "rake"
32-
gem "rubocop", require: false
31+
gem 'rake'
32+
gem 'rubocop', require: false
3333
end
3434

3535
gemspec

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ GEM
132132
unicode-display_width (>= 2.4.0, < 3.0)
133133
rubocop-ast (1.29.0)
134134
parser (>= 3.2.1.0)
135-
rubocop-shopify (2.2.0)
136-
rubocop (~> 1.18)
135+
rubocop-shopify (2.14.0)
136+
rubocop (~> 1.51)
137137
ruby-debug-ide (0.7.2)
138138
rake (>= 0.8.1)
139139
ruby-progressbar (1.13.0)

Guardfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
# More info at https://github.com/guard/guard#readme
44
guard :minitest do
5-
watch(%r{^lib/(.*)\.rb$}) { "test" } # run all tests if code is modified
5+
watch(%r{^lib/(.*)\.rb$}) { 'test' } # run all tests if code is modified
66
watch(%r{^test/(.*)_test\.rb$}) # only run specific test file if test is modified
77

88
# configuration
9-
watch(%r{^test/test_helper\.rb$}) { "test" }
10-
watch(%r{^test/test_utility/(.*)\.rb$}) { "test" }
9+
watch(%r{^test/test_helper\.rb$}) { 'test' }
10+
watch(%r{^test/test_utility/(.*)\.rb$}) { 'test' }
1111
end
1212

1313
# https://stackoverflow.com/questions/23571163/clear-previous-tests-in-rspec-while-running-new-tests-using-guard

Rakefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
# frozen_string_literal: true
22

33
begin
4-
require "bundler/setup"
4+
require 'bundler/setup'
55
rescue LoadError
6-
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
6+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
77
end
88

9-
require "rubocop/rake_task"
10-
require "bundler/gem_tasks"
11-
require "rake/testtask"
9+
require 'rubocop/rake_task'
10+
require 'bundler/gem_tasks'
11+
require 'rake/testtask'
1212

1313
Rake::TestTask.new(:test) do |t|
14-
t.libs << "test"
15-
t.libs << "lib"
14+
t.libs << 'test'
15+
t.libs << 'lib'
1616
t.verbose = true
1717
t.warning = false
18-
t.pattern = "test/**/*_test.rb"
18+
t.pattern = 'test/**/*_test.rb'
1919
end
2020

2121
RuboCop::RakeTask.new(:lint) do |t|
22-
t.options = ["--display-cop-names"]
22+
t.options = ['--display-cop-names']
2323
end
2424

2525
RuboCop::RakeTask.new(:fix) do |t|
26-
t.options = ["--auto-correct-all"]
26+
t.options = ['--auto-correct-all']
2727
end
2828

2929
task :default do
30-
Rake::Task["test"].execute
31-
Rake::Task["lint"].execute
30+
Rake::Task['test'].execute
31+
Rake::Task['lint'].execute
3232
end

lib/faraday/raise_http_exception.rb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
2-
require "faraday"
2+
3+
require 'faraday'
34
# @private
45
module FaradayMiddleware
56
# @private
@@ -8,10 +9,16 @@ def call(env)
89
@app.call(env).on_complete do |response|
910
case response[:status].to_i
1011
when 400, 401, 404, 500, 502, 503, 504
11-
raise ShipEngine::Exceptions::ShipEngineError.new(message: error_body(response[:body]), source: error_source(response[:body]),
12-
type: error_type(response[:body]), code: error_code(response[:body]), request_id: response[:body]["request_id"], url: response[:url].to_s)
12+
raise ShipEngine::Exceptions::ShipEngineError.new(
13+
message: error_body(response[:body]),
14+
source: error_source(response[:body]),
15+
type: error_type(response[:body]),
16+
code: error_code(response[:body]),
17+
request_id: response[:body]['request_id'],
18+
url: response[:url].to_s
19+
)
1320
when 429
14-
raise ShipEngine::Exceptions::RateLimitError.new(retries: env.request_headers["Retries"].to_i, source: error_source(response[:body]), request_id: response[:body]["request_id"])
21+
raise ShipEngine::Exceptions::RateLimitError.new(retries: env.request_headers['Retries'].to_i, source: error_source(response[:body]), request_id: response[:body]['request_id'])
1522
end
1623
end
1724
end
@@ -23,55 +30,47 @@ def initialize(app)
2330

2431
private
2532

26-
def error_message_400(response)
33+
def error_message_400(response) # rubocop:todo Naming/VariableNumber
2734
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]}#{error_body(response[:body])}"
2835
end
2936

3037
def error_body(body)
31-
if !body.nil? && !body.empty? && body.is_a?(String)
32-
body = ::JSON.parse(body)
33-
end
38+
body = ::JSON.parse(body) if !body.nil? && !body.empty? && body.is_a?(String)
3439

3540
if body.nil?
3641
nil
37-
elsif body["errors"] && !body["errors"].empty?
38-
body["errors"][0]["message"]
42+
elsif body['errors'] && !body['errors'].empty?
43+
body['errors'][0]['message']
3944
end
4045
end
4146

4247
def error_source(body)
43-
if !body.nil? && !body.empty? && body.is_a?(String)
44-
body = ::JSON.parse(body)
45-
end
48+
body = ::JSON.parse(body) if !body.nil? && !body.empty? && body.is_a?(String)
4649

4750
if body.nil?
4851
nil
49-
elsif body["errors"] && !body["errors"].empty?
50-
body["errors"][0]["error_source"]
52+
elsif body['errors'] && !body['errors'].empty?
53+
body['errors'][0]['error_source']
5154
end
5255
end
5356

5457
def error_type(body)
55-
if !body.nil? && !body.empty? && body.is_a?(String)
56-
body = ::JSON.parse(body)
57-
end
58+
body = ::JSON.parse(body) if !body.nil? && !body.empty? && body.is_a?(String)
5859

5960
if body.nil?
6061
nil
61-
elsif body["errors"] && !body["errors"].empty?
62-
body["errors"][0]["error_type"]
62+
elsif body['errors'] && !body['errors'].empty?
63+
body['errors'][0]['error_type']
6364
end
6465
end
6566

6667
def error_code(body)
67-
if !body.nil? && !body.empty? && body.is_a?(String)
68-
body = ::JSON.parse(body)
69-
end
68+
body = ::JSON.parse(body) if !body.nil? && !body.empty? && body.is_a?(String)
7069

7170
if body.nil?
7271
nil
73-
elsif body["errors"] && !body["errors"].empty?
74-
body["errors"][0]["error_code"]
72+
elsif body['errors'] && !body['errors'].empty?
73+
body['errors'][0]['error_code']
7574
end
7675
end
7776
end

lib/shipengine.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# frozen_string_literal: true
22

33
# for client class
4-
require "shipengine/internal_client"
5-
require "shipengine/domain"
6-
require "shipengine/configuration"
4+
require 'shipengine/internal_client'
5+
require 'shipengine/domain'
6+
require 'shipengine/configuration'
77

88
# just for exporting
9-
require "shipengine/utils/validate"
10-
require "shipengine/version"
11-
require "shipengine/constants"
12-
require "observer"
9+
require 'shipengine/utils/validate'
10+
require 'shipengine/version'
11+
require 'shipengine/constants'
12+
require 'observer'
1313

1414
module ShipEngine
1515
class Client
1616
attr_accessor :configuration
1717

1818
def initialize(api_key, retries: nil, timeout: nil, page_size: nil, base_url: nil)
1919
@configuration = Configuration.new(
20-
api_key: api_key,
21-
retries: retries,
22-
base_url: base_url,
23-
timeout: timeout,
24-
page_size: page_size
20+
api_key:,
21+
retries:,
22+
base_url:,
23+
timeout:,
24+
page_size:
2525
)
2626

2727
@internal_client = ShipEngine::InternalClient.new(@configuration)
@@ -64,7 +64,7 @@ def validate_addresses(address, config = {})
6464
#
6565
# @see https://shipengine.github.io/shipengine-openapi/#operation/list_carriers
6666
def list_carriers(config: {})
67-
@carriers.list_carriers(config: config)
67+
@carriers.list_carriers(config:)
6868
end
6969

7070
# Create label from Rate Id

lib/shipengine/configuration.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
module ShipEngine
34
class Configuration
45
attr_accessor :api_key, :retries, :base_url, :timeout, :page_size
@@ -32,11 +33,11 @@ def merge(config)
3233
protected
3334

3435
def validate
35-
Utils::Validate.str("A ShipEngine API key", @api_key)
36-
Utils::Validate.str("Base URL", @base_url)
37-
Utils::Validate.non_neg_int("Retries", @retries)
38-
Utils::Validate.positive_int("Timeout", @timeout)
39-
Utils::Validate.positive_int("Page size", @page_size)
36+
Utils::Validate.str('A ShipEngine API key', @api_key)
37+
Utils::Validate.str('Base URL', @base_url)
38+
Utils::Validate.non_neg_int('Retries', @retries)
39+
Utils::Validate.positive_int('Timeout', @timeout)
40+
Utils::Validate.positive_int('Page size', @page_size)
4041
end
4142
end
4243
end

lib/shipengine/constants.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# frozen_string_literal: true
22

3-
require_relative "constants/countries"
4-
require_relative "constants/base"
3+
require_relative 'constants/countries'
4+
require_relative 'constants/base'

lib/shipengine/constants/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
module ShipEngine
44
module Constants
55
# A stub API Key to use in the test suite.
6-
API_KEY = "TEST_ycvJAgX6tLB1Awm9WGJmD8mpZ8wXiQ20WhqFowCk32s"
6+
API_KEY = 'TEST_ycvJAgX6tLB1Awm9WGJmD8mpZ8wXiQ20WhqFowCk32s'
77

88
# The base_url for the ShipEngine SDK - for use in production environment.
9-
PROD_URL = "https://api.shipengine.com"
9+
PROD_URL = 'https://api.shipengine.com'
1010

1111
# Regex pattern to match a valid *ISO-8601* string with timezone.
1212
VALID_ISO_STRING = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/

0 commit comments

Comments
 (0)