mirror of
https://github.com/dkam/paapi.git
synced 2025-12-28 07:04:53 +00:00
Add net-http-persistent as a dependency. Remove code to determine which HTTP client to use. Cleanup spacing
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
## 0.1.7 ( Unreleased )
|
||||||
|
- Add gem 'net-http-persistent' for connection persistance
|
||||||
|
- Remove the code which would use other http clients if available
|
||||||
## 0.1.3
|
## 0.1.3
|
||||||
- Dropped the HTTP gem and moved to Ruby's Net::HTTP
|
- Dropped the HTTP gem and moved to Ruby's Net::HTTP
|
||||||
- Merged a branch which adds the Condtion parameter.
|
- Merged a branch which adds the Condtion parameter.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'net/http'
|
require 'net/http/persistent'
|
||||||
require 'aws-sigv4'
|
require 'aws-sigv4'
|
||||||
|
|
||||||
module Paapi
|
module Paapi
|
||||||
@@ -10,9 +10,9 @@ module Paapi
|
|||||||
def initialize(access_key: Paapi.access_key,
|
def initialize(access_key: Paapi.access_key,
|
||||||
secret_key: Paapi.secret_key,
|
secret_key: Paapi.secret_key,
|
||||||
partner_tag: Paapi.partner_tag,
|
partner_tag: Paapi.partner_tag,
|
||||||
market: Paapi.market || DEFAULT_MARKET,
|
market: Paapi.market || DEFAULT_MARKET,
|
||||||
condition: Paapi.condition || DEFAULT_CONDITION,
|
condition: Paapi.condition || DEFAULT_CONDITION,
|
||||||
resources: Paapi.resources || DEFAULT_RESOURCES,
|
resources: Paapi.resources || DEFAULT_RESOURCES,
|
||||||
partner_type: DEFAULT_PARTNER_TYPE
|
partner_type: DEFAULT_PARTNER_TYPE
|
||||||
)
|
)
|
||||||
raise ArgumentError unless MARKETPLACES.keys.include?(market.to_sym)
|
raise ArgumentError unless MARKETPLACES.keys.include?(market.to_sym)
|
||||||
@@ -25,13 +25,7 @@ module Paapi
|
|||||||
self.market = market
|
self.market = market
|
||||||
@partner_tag = partner_tag if !partner_tag.nil?
|
@partner_tag = partner_tag if !partner_tag.nil?
|
||||||
|
|
||||||
if defined?(HTTPX)
|
@http = Net::HTTP::Persistent.new name: 'paapi'
|
||||||
@http = HTTPX.plugin(:persistent)
|
|
||||||
elsif defined?(HTTP)
|
|
||||||
@http = HTTP::Client.new
|
|
||||||
else
|
|
||||||
@http = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def market=(a_market)
|
def market=(a_market)
|
||||||
@@ -108,17 +102,28 @@ module Paapi
|
|||||||
headers['Authorization'] = signature.headers['authorization']
|
headers['Authorization'] = signature.headers['authorization']
|
||||||
headers['Content-Type'] = 'application/json; charset=utf-8'
|
headers['Content-Type'] = 'application/json; charset=utf-8'
|
||||||
|
|
||||||
unless @http.nil?
|
Response.new( post(url: endpoint, body: payload, headers: headers))
|
||||||
Response.new( @http.with_headers(headers).post(endpoint, json: payload ) )
|
end
|
||||||
else
|
|
||||||
Response.new( Client.post(url: endpoint, body: payload, headers: headers))
|
def post(url:, body:, headers:)
|
||||||
end
|
puts "Not Deprecated"
|
||||||
|
uri = URI.parse(url)
|
||||||
|
|
||||||
|
post_request = Net::HTTP::Post.new(uri.path)
|
||||||
|
post_request.content_type = 'application/json; charset=UTF-8'
|
||||||
|
|
||||||
|
headers.each { |k, v| post_request[k] = v }
|
||||||
|
post_request.body = body.to_json
|
||||||
|
|
||||||
|
#Client.post(client: @http, url: url, body: body, headers: headers)
|
||||||
|
http.request uri, post_request
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.post(url:, body:, headers:)
|
def self.post(url:, body:, headers:, client: nil)
|
||||||
|
puts "Deprecated"
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
request = Net::HTTP::Post.new(uri)
|
request = client || Net::HTTP::Post.new(uri)
|
||||||
request.content_type = 'application/json; charset=UTF-8'
|
request.content_type = 'application/json; charset=UTF-8'
|
||||||
headers.each { |k, v| request[k] = v }
|
headers.each { |k, v| request[k] = v }
|
||||||
request.body = body.to_json
|
request.body = body.to_json
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Paapi
|
module Paapi
|
||||||
VERSION = '0.1.6'
|
VERSION = '0.1.7'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|||||||
|
|
||||||
spec.metadata['homepage_uri'] = spec.homepage
|
spec.metadata['homepage_uri'] = spec.homepage
|
||||||
spec.metadata['source_code_uri'] = spec.homepage
|
spec.metadata['source_code_uri'] = spec.homepage
|
||||||
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
spec.metadata["changelog_uri"] = "https://github.com/dkam/paapi/blob/master/CHANGELOG.md"
|
||||||
|
|
||||||
# Specify which files should be added to the gem when it is released.
|
# Specify which files should be added to the gem when it is released.
|
||||||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
||||||
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
|
|||||||
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
||||||
|
|
||||||
spec.add_dependency 'aws-sigv4', '~> 1'
|
spec.add_dependency 'aws-sigv4', '~> 1'
|
||||||
|
spec.add_dependency 'net-http-persistent', '~> 4.0', '>= 4.0.1'
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user