Skip to content

Commit

Permalink
Switching HTTP adapter (#304)
Browse files Browse the repository at this point in the history
* Switching HTTP adapter
  • Loading branch information
superchilled authored Feb 21, 2024
1 parent 16e948f commit 7bfc223
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/vonage/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require 'net/http'
require 'net/http/persistent'
require 'net/http/post/multipart'
require 'json'

Expand All @@ -12,8 +13,7 @@ def initialize(config)

@host = set_host

@http = Net::HTTP.new(@host, Net::HTTP.https_default_port, p_addr = nil)
@http.use_ssl = true
@http = Net::HTTP::Persistent.new

@config.http.set(@http) unless @config.http.nil?
end
Expand Down Expand Up @@ -94,7 +94,8 @@ def build_request(path:, type: Get, params: {})
def make_request!(request, &block)
logger.log_request_info(request)

response = @http.request(request, &block)
uri = URI("https://" + @host + request.path)
response = @http.request(uri, request, &block)

logger.log_response_info(response, @host)

Expand Down Expand Up @@ -143,7 +144,7 @@ def multipart_post_request(path, filepath:, file_name:, mime_type:, params: {},

uri = override_uri ? URI(override_uri) : URI('https://' + @host + path)

http = override_uri ? Net::HTTP.new(uri.host, Net::HTTP.https_default_port, p_addr = nil) : @http
http = Net::HTTP.new(uri.host, Net::HTTP.https_default_port, p_addr = nil)
http.use_ssl = true
http.set_debug_output($stdout)

Expand Down
2 changes: 1 addition & 1 deletion lib/vonage/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def check(params, signature_secret: @config.signature_secret, signature_method:

signature = params.delete('sig')

::JWT::Algos::Hmac::SecurityUtils.secure_compare(signature, digest(params, signature_secret, signature_method))
::JWT::JWA::Hmac::SecurityUtils.secure_compare(signature, digest(params, signature_secret, signature_method))
end

private
Expand Down
1 change: 1 addition & 0 deletions vonage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Gem::Specification.new do |s|
s.add_dependency('zeitwerk', '~> 2', '>= 2.2')
s.add_dependency('sorbet-runtime', '~> 0.5')
s.add_dependency('multipart-post', '~> 2.0')
s.add_dependency('net-http-persistent', '~> 4.0', '>= 4.0.2')
s.add_runtime_dependency('rexml')
s.add_runtime_dependency('phonelib')
s.require_path = 'lib'
Expand Down

0 comments on commit 7bfc223

Please sign in to comment.