Class: Peddler::Client
- Inherits:
-
Object
- Object
- Peddler::Client
- Extended by:
- Forwardable
- Includes:
- Jeff
- Defined in:
- lib/peddler/client.rb
Overview
An abstract client
Subclass to implement an MWS API section.
Direct Known Subclasses
MWS::CartInformation::Client, MWS::CustomerInformation::Client, MWS::Feeds::Client, MWS::Finances::Client, MWS::FulfillmentInboundShipment::Client, MWS::FulfillmentInventory::Client, MWS::FulfillmentOutboundShipment::Client, MWS::OffAmazonPayments::Client, MWS::Orders::Client, MWS::Products::Client, MWS::Recommendations::Client, MWS::Reports::Client, MWS::Sellers::Client, MWS::Subscriptions::Client, MWS::Webstore::Client
Class Attribute Summary collapse
- .error_handler ⇒ Object readonly private
- .parser ⇒ Object private
Instance Attribute Summary collapse
-
#auth_token ⇒ String
The MWSAuthToken used to access another seller’s account.
-
#body ⇒ String
The body of the HTTP request.
-
#merchant_id ⇒ String
The merchant’s Seller ID.
-
#path ⇒ String
The HTTP path of the API.
-
#primary_marketplace_id ⇒ String
The merchant’s Marketplace ID.
- #version ⇒ Object private
Class Method Summary collapse
-
.on_error {|request, response| ... } ⇒ Object
Sets an error handler.
- .path(path = nil) ⇒ Object private
- .version(version = nil) ⇒ Object private
Instance Method Summary collapse
- #aws_endpoint ⇒ Object private
- #defaults ⇒ Object private
- #error_handler ⇒ Object private
- #headers ⇒ Object private
-
#initialize(opts = {}) ⇒ Client
constructor
Creates a new client instance.
- #marketplace ⇒ Object private
- #marketplace_id ⇒ Object deprecated Deprecated.
- #marketplace_id=(marketplace_id) ⇒ Object deprecated Deprecated.
-
#on_error {|request, response| ... } ⇒ Object
Sets an error handler.
- #operation(action = nil) ⇒ Object private
- #run ⇒ Object private
Constructor Details
#initialize(opts = {}) ⇒ Client
Creates a new client instance
86 87 88 |
# File 'lib/peddler/client.rb', line 86 def initialize(opts = {}) opts.each { |k, v| send("#{k}=", v) } end |
Class Attribute Details
.error_handler ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/peddler/client.rb', line 40 def error_handler @error_handler end |
.parser ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/peddler/client.rb', line 43 def parser @parser ||= Parser end |
Instance Attribute Details
#auth_token ⇒ String
The MWSAuthToken used to access another seller’s account
17 18 19 |
# File 'lib/peddler/client.rb', line 17 def auth_token @auth_token end |
#body ⇒ String
The body of the HTTP request
26 27 28 |
# File 'lib/peddler/client.rb', line 26 def body @body end |
#merchant_id ⇒ String
The merchant’s Seller ID
115 116 117 |
# File 'lib/peddler/client.rb', line 115 def merchant_id @merchant_id ||= ENV['MWS_MERCHANT_ID'] end |
#path ⇒ String
The HTTP path of the API
127 128 129 |
# File 'lib/peddler/client.rb', line 127 def path @path ||= self.class.path end |
#primary_marketplace_id ⇒ String
The merchant’s Marketplace ID
98 99 100 |
# File 'lib/peddler/client.rb', line 98 def primary_marketplace_id @primary_marketplace_id ||= ENV['MWS_MARKETPLACE_ID'] end |
#version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
132 133 134 |
# File 'lib/peddler/client.rb', line 132 def version @version ||= self.class.version end |
Class Method Details
.on_error {|request, response| ... } ⇒ Object
Sets an error handler
62 63 64 |
# File 'lib/peddler/client.rb', line 62 def on_error(&blk) @error_handler = blk end |
.path(path = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/peddler/client.rb', line 50 def path(path = nil) path ? @path = path : @path ||= '/' end |
.version(version = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 |
# File 'lib/peddler/client.rb', line 55 def version(version = nil) version ? @version = version : @version end |
Instance Method Details
#aws_endpoint ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 |
# File 'lib/peddler/client.rb', line 91 def aws_endpoint "https://#{host}#{path}" end |
#defaults ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
148 149 150 |
# File 'lib/peddler/client.rb', line 148 def defaults @defaults ||= { expects: 200 } end |
#error_handler ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
165 166 167 |
# File 'lib/peddler/client.rb', line 165 def error_handler @error_handler || self.class.error_handler end |
#headers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
153 154 155 |
# File 'lib/peddler/client.rb', line 153 def headers @headers ||= {} end |
#marketplace ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
120 121 122 |
# File 'lib/peddler/client.rb', line 120 def marketplace @marketplace ||= find_marketplace end |
#marketplace_id ⇒ Object
103 104 105 |
# File 'lib/peddler/client.rb', line 103 def marketplace_id @primary_marketplace_id end |
#marketplace_id=(marketplace_id) ⇒ Object
108 109 110 |
# File 'lib/peddler/client.rb', line 108 def marketplace_id=(marketplace_id) @primary_marketplace_id = marketplace_id end |
#on_error {|request, response| ... } ⇒ Object
Sets an error handler
160 161 162 |
# File 'lib/peddler/client.rb', line 160 def on_error(&blk) @error_handler = blk end |
#operation(action = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
170 171 172 |
# File 'lib/peddler/client.rb', line 170 def operation(action = nil) action ? @operation = Operation.new(action) : @operation end |
#run ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
175 176 177 178 179 180 181 182 183 |
# File 'lib/peddler/client.rb', line 175 def run opts = opts.store(:response_block, Proc.new) if block_given? res = post(opts) parser.new(res, encoding) rescue Excon::Errors::Error => e handle_error(e) end |