From 7b30c38ad2ca00e4df2ff40bee120963d8c09d35 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 22 Oct 2024 12:34:55 +0100 Subject: [PATCH 1/4] Updating HTTP Options implementation and tests --- lib/vonage/http.rb | 6 +++--- test/vonage/http_options_test.rb | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/vonage/http.rb b/lib/vonage/http.rb index 88e88c5e..7e4b26be 100644 --- a/lib/vonage/http.rb +++ b/lib/vonage/http.rb @@ -1,6 +1,6 @@ # typed: strict # frozen_string_literal: true -require 'net/http' +require 'net/http/persistent' module Vonage module HTTP @@ -21,7 +21,7 @@ def initialize(hash) end end - sig { params(http: Net::HTTP).returns(T::Hash[Symbol, T.untyped]) } + sig { params(http: Net::HTTP::Persistent).returns(T::Hash[Symbol, T.untyped]) } def set(http) @hash.each do |name, value| http.public_send(defined_options.fetch(name), value) @@ -34,7 +34,7 @@ def set(http) def defined_options @defined_options = T.let(@defined_options, T.nilable(T::Hash[Symbol, T.untyped])) - @defined_options ||= Net::HTTP.instance_methods.grep(/\w=\z/).each_with_object({}) do |name, hash| + @defined_options ||= Net::HTTP::Persistent.instance_methods.grep(/\w=\z/).each_with_object({}) do |name, hash| hash[name.to_s.chomp('=').to_sym] = name end end diff --git a/test/vonage/http_options_test.rb b/test/vonage/http_options_test.rb index c4060c3e..5398af46 100644 --- a/test/vonage/http_options_test.rb +++ b/test/vonage/http_options_test.rb @@ -8,8 +8,12 @@ def read_timeout 5 end - def proxy_address - 'localhost' + def proxy_host + 'example.com' + end + + def proxy_port + 4567 end def ca_file @@ -23,13 +27,16 @@ def test_invalid_option_raises_argument_error end def test_set_method - http = Net::HTTP.new('example.com', Net::HTTP.https_default_port, p_addr = nil) + http = Net::HTTP::Persistent.new + + proxy = URI::HTTP.build(host: proxy_host, port: proxy_port) - options = Options.new(read_timeout: read_timeout, proxy_address: proxy_address, ca_file: ca_file) + options = Options.new(read_timeout: read_timeout, proxy: proxy, ca_file: ca_file) options.set(http) assert_equal read_timeout, http.read_timeout - assert_equal proxy_address, http.proxy_address + assert_equal proxy_host, http.proxy_uri.hostname + assert_equal proxy_port, http.proxy_uri.port assert_equal ca_file, http.ca_file end end From d4e4dcdb11d972b63026e5074832cffcc4bdad10 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 22 Oct 2024 14:36:22 +0100 Subject: [PATCH 2/4] Bumping patch version --- lib/vonage/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vonage/version.rb b/lib/vonage/version.rb index c65edb93..ff1363bf 100644 --- a/lib/vonage/version.rb +++ b/lib/vonage/version.rb @@ -1,5 +1,5 @@ # typed: strong module Vonage - VERSION = '7.27.0' + VERSION = '7.27.1' end From 0dc1a4f9b52115d2635bbf0303f7ad89ebb82e41 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 22 Oct 2024 14:36:39 +0100 Subject: [PATCH 3/4] Updating changelog --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 77001cdb..95625f0f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 7.27.1 + +* Fixes a bug with setting options on the HTTP client. [#319](https://github.com/Vonage/vonage-ruby-sdk/pull/319) + # 7.27.0 * Updates Messages API implementation to add RCS channel as well as a new `PATCH` endpoint for RCS message revocation and WhatsApp Mark as Read features. [#316](https://github.com/Vonage/vonage-ruby-sdk/pull/316) From 6811c2b648dd44507a52638de501da360b8a781e Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 22 Oct 2024 14:36:50 +0100 Subject: [PATCH 4/4] Updating README --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 77b89e84..2657ff01 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ need a Vonage account. Sign up [for free at vonage.com][signup]. * [Logging](#logging) * [Exceptions](#exceptions) * [Overriding the default hosts](#overriding-the-default-hosts) + * [HTTP Client Configuration](#http-client-configuration) * [JWT authentication](#jwt-authentication) * [Webhook signatures](#webhook-signatures) * [Pagination](#pagination) @@ -179,6 +180,33 @@ client = Vonage::Client.new( By default the hosts are set to `api.nexmo.com` and `rest.nexmo.com`, respectively. +### HTTP Client Configuration + +It is possible to set configuration options on the HTTP client. This can be don in a couple of ways. + +1. Using an `:http` key during `Vonage::Client` instantiation, for example: + ```ruby + client = Vonage::Client.new( + api_key: 'YOUR-API-KEY', + api_secret: 'YOUR-API-SECRET', + http: { + max_retries: 1 + } + ) + ``` + +2. By using the `http=` setter on the `Vonage::Config` object, for example: + ```ruby + client = Vonage::Client.new( + api_key: 'YOUR-API-KEY', + api_secret: 'YOUR-API-SECRET' + ) + + client.config.http = { max_retries: 1 } + ``` + +The Vonage Ruby SDK uses the [`Net::HTTP::Persistent` library](https://github.com/drbrain/net-http-persistent) as an HTTP client. For available configuration options see [the documentation for that library](https://www.rubydoc.info/gems/net-http-persistent/3.0.0/Net/HTTP/Persistent). + ### Webhook signatures Certain Vonage APIs provide signed [webhooks](https://developer.vonage.com/en/getting-started/concepts/webhooks) as a means of verifying the origin of the webhooks. The exact signing mechanism varies depending on the API.