Skip to content

Commit

Permalink
Address ruby 2.7 deprecation warnings (#53)
Browse files Browse the repository at this point in the history
* Address ruby 2.7 keyword argument warnings

1. Must explicitly pass a hash when a function accepts both keyword
   args and a hash parameter.

2. Must explicitly convert hash to keyword args with ** when passing
   a hash as keyword arguments.

* Update faraday

Currently the Gemfile is locked 0.15.4, while the gemspec allows
0.13.x - 0.17.x, excluding some bad 0.16 releases.  This 0.15.4
version contains various deprecation warnings under ruby 2.7:

> warning: Capturing the given block using Proc.new is deprecated;
> use `&block` instead

Update the Gemfile to point to the latest 0.x version, which is
0.17.3.

Disallow 0.17.1 in the gemspec, which has some error class
hierarchy changes (which were reverted in 0.17.3) that break tests.

For more details, see
https://github.com/lostisland/faraday/blob/master/CHANGELOG.md
  • Loading branch information
ledbettj authored Mar 10, 2021
1 parent 82865bd commit 0a35f81
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gemspec

group :development do
gem "coveralls", require: false
gem "faraday", "0.15.4"
gem "faraday", "0.17.3"
gem "mocha", "~> 0.13.2"
gem "rake"
gem "shoulda-context"
Expand Down
2 changes: 1 addition & 1 deletion lib/telnyx/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def refresh

def self.retrieve(id, opts = {})
opts = Util.normalize_opts(opts)
instance = new(id, opts)
instance = new(id, **opts)
instance.refresh
instance
end
Expand Down
39 changes: 15 additions & 24 deletions lib/telnyx/telnyx_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,30 +310,21 @@ def specific_api_error(resp, error_list, context)
json_body: resp.data,
}

case resp.http_status
when 400
InvalidRequestError.new(error_list, opts)
when 401
AuthenticationError.new(error_list, opts)
when 403
PermissionError.new(error_list, opts)
when 404
ResourceNotFoundError.new(error_list, opts)
when 405
MethodNotSupportedError.new(error_list, opts)
when 408
TimeoutError.new(error_list, opts)
when 422
InvalidParametersError.new(error_list, opts)
when 429
RateLimitError.new(error_list, opts)
when 500
APIError.new(error_list, opts)
when 503
ServiceUnavailableError.new(error_list, opts)
else
APIError.new(error_list, opts)
end
err_class = case resp.http_status
when 400 then InvalidRequestError
when 401 then AuthenticationError
when 403 then PermissionError
when 404 then ResourceNotFoundError
when 405 then MethodNotSupportedError
when 408 then TimeoutError
when 422 then InvalidParametersError
when 429 then RateLimitError
when 500 then APIError
when 503 then ServiceUnavailableError
else APIError
end

err_class.new(error_list, **opts)
end

def handle_network_error(e, context, num_retries, api_base = nil)
Expand Down
2 changes: 1 addition & 1 deletion telnyx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |s|
"source_code_uri" => "https://github.com/team-telnyx/telnyx-ruby",
}

s.add_dependency("faraday", "~> 0.13", "!= 0.16.0", "!= 0.16.1", "!= 0.16.2")
s.add_dependency("faraday", "~> 0.13", "!= 0.16.0", "!= 0.16.1", "!= 0.16.2", "!= 0.17.1")
s.add_dependency("net-http-persistent", "~> 3.0")
s.add_dependency("ed25519", "~> 1")

Expand Down
10 changes: 5 additions & 5 deletions test/telnyx/telnyx_object_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,26 @@ def to_hash

should "mass assign values with #update_attributes" do
obj = Telnyx::TelnyxObject.construct_from(id: 1, name: "Telnyx")
obj.update_attributes(name: "telnyx")
obj.update_attributes({ name: "telnyx" })
assert_equal "telnyx", obj.name

# unfortunately, we even assign unknown properties to duplicate the
# behavior that we currently have via magic accessors with
# method_missing
obj.update_attributes(unknown: "foo")
obj.update_attributes({ unknown: "foo" })
assert_equal "foo", obj.unknown
end

should "#update_attributes with a hash" do
obj = Telnyx::TelnyxObject.construct_from({})
obj.update_attributes(metadata: { foo: "bar" })
obj.update_attributes({ metadata: { foo: "bar" } })
assert_equal Telnyx::TelnyxObject, obj.metadata.class
end

should "create accessors when #update_attributes is called" do
obj = Telnyx::TelnyxObject.construct_from({})
assert_equal false, obj.send(:metaclass).method_defined?(:foo)
obj.update_attributes(foo: "bar")
obj.update_attributes({ foo: "bar" })
assert_equal true, obj.send(:metaclass).method_defined?(:foo)
end

Expand Down Expand Up @@ -268,7 +268,7 @@ def to_hash

should "#serialize_params on a basic object" do
obj = Telnyx::TelnyxObject.construct_from(foo: nil)
obj.update_attributes(foo: "bar")
obj.update_attributes({ foo: "bar" })
assert_equal({ foo: "bar" }, obj.serialize_params)
end

Expand Down

0 comments on commit 0a35f81

Please sign in to comment.