Class: Peddler::Client
Abstract
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Jeff
- Defined in:
- lib/peddler/client.rb
Overview
This class is abstract.
Subclass to implement an MWS API section.
Direct Known Subclasses
MWS::CartInformation::Client, MWS::CustomerInformation::Client, MWS::Feeds::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
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
42
43
44
|
# File 'lib/peddler/client.rb', line 42
def initialize(opts = {})
opts.each { |k, v| send("#{k}=", v) }
end
|
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
13
14
15
|
# File 'lib/peddler/client.rb', line 13
def auth_token
@auth_token
end
|
#body ⇒ Object
Returns the value of attribute body.
15
16
17
|
# File 'lib/peddler/client.rb', line 15
def body
@body
end
|
#marketplace_id ⇒ Object
50
51
52
|
# File 'lib/peddler/client.rb', line 50
def marketplace_id
@marketplace_id ||= ENV['MWS_MARKETPLACE_ID']
end
|
#merchant_id ⇒ Object
54
55
56
|
# File 'lib/peddler/client.rb', line 54
def merchant_id
@merchant_id ||= ENV['MWS_MERCHANT_ID']
end
|
#path ⇒ Object
70
71
72
|
# File 'lib/peddler/client.rb', line 70
def path
@path ||= self.class.path
end
|
Class Method Details
.inherited(base) ⇒ Object
38
39
40
|
# File 'lib/peddler/client.rb', line 38
def self.inherited(base)
base.params(params)
end
|
.parser ⇒ Object
26
27
28
|
# File 'lib/peddler/client.rb', line 26
def self.parser
@parser ||= Parser
end
|
.parser=(parser) ⇒ Object
30
31
32
|
# File 'lib/peddler/client.rb', line 30
def self.parser=(parser)
@parser = parser
end
|
.path(path = nil) ⇒ Object
34
35
36
|
# File 'lib/peddler/client.rb', line 34
def self.path(path = nil)
path ? @path = path : @path ||= '/'
end
|
Instance Method Details
#aws_endpoint ⇒ Object
46
47
48
|
# File 'lib/peddler/client.rb', line 46
def aws_endpoint
"https://#{host}#{path}"
end
|
#defaults ⇒ Object
62
63
64
|
# File 'lib/peddler/client.rb', line 62
def defaults
@defaults ||= { expects: 200 }
end
|
66
67
68
|
# File 'lib/peddler/client.rb', line 66
def
@headers ||= {}
end
|
#marketplace ⇒ Object
58
59
60
|
# File 'lib/peddler/client.rb', line 58
def marketplace
@marketplace ||= find_marketplace
end
|
#on_error(&blk) ⇒ Object
79
80
81
|
# File 'lib/peddler/client.rb', line 79
def on_error(&blk)
@error_handler = blk
end
|
#operation(action = nil) ⇒ Object
83
84
85
|
# File 'lib/peddler/client.rb', line 83
def operation(action = nil)
action ? @operation = Operation.new(action) : @operation
end
|
#run(&blk) ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/peddler/client.rb', line 87
def run(&blk)
opts = defaults.merge(query: operation, headers: )
opts.store(:body, body) if body
opts.store(:response_block, blk) if block_given?
res = post(opts)
parser.parse(res, encoding)
rescue Excon::Errors::Error => ex
handle_error(ex) or raise
end
|