Class: Peddler::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Jeff
Defined in:
lib/peddler/client.rb

Overview

An abstract client

Subclass to implement an MWS API section.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Creates a new client instance

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :primary_marketplace_id (String)
  • :merchant_id (String)
  • :aws_access_key_id (String)
  • :aws_secret_access_key (String)
  • :auth_token (String)


80
81
82
# File 'lib/peddler/client.rb', line 80

def initialize(opts = {})
  opts.each { |k, v| send("#{k}=", v) }
end

Class Attribute Details

.error_handlerObject

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.



41
42
43
# File 'lib/peddler/client.rb', line 41

def error_handler
  @error_handler
end

.parserObject

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.



41
42
43
# File 'lib/peddler/client.rb', line 41

def parser
  @parser
end

Instance Attribute Details

#auth_tokenString

The MWSAuthToken used to access another seller’s account

Returns:

  • (String)


18
19
20
# File 'lib/peddler/client.rb', line 18

def auth_token
  @auth_token
end

#bodyString

The body of the HTTP request

Returns:

  • (String)


27
28
29
# File 'lib/peddler/client.rb', line 27

def body
  @body
end

#merchant_idString

The merchant’s Seller ID

Returns:

  • (String)


109
110
111
# File 'lib/peddler/client.rb', line 109

def merchant_id
  @merchant_id ||= ENV['MWS_MERCHANT_ID']
end

#pathString

The HTTP path of the API

Returns:

  • (String)


121
122
123
# File 'lib/peddler/client.rb', line 121

def path
  @path ||= self.class.path
end

#primary_marketplace_idString

The merchant’s Marketplace ID

Returns:

  • (String)


92
93
94
# File 'lib/peddler/client.rb', line 92

def primary_marketplace_id
  @primary_marketplace_id ||= ENV['MWS_MARKETPLACE_ID']
end

#versionObject

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.



126
127
128
# File 'lib/peddler/client.rb', line 126

def version
  @version ||= self.class.version
end

Class Method Details

.on_error {|error| ... } ⇒ Object

Sets an error handler

Yield Parameters:

  • error (Excon::Error)


55
56
57
# File 'lib/peddler/client.rb', line 55

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.



44
45
46
# File 'lib/peddler/client.rb', line 44

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.



49
50
51
# File 'lib/peddler/client.rb', line 49

def version(version = nil)
  version ? @version = version : @version ||= nil
end

Instance Method Details

#aws_endpointObject

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.



85
86
87
# File 'lib/peddler/client.rb', line 85

def aws_endpoint
  "https://#{host}#{path}"
end

#defaultsObject

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.



136
137
138
# File 'lib/peddler/client.rb', line 136

def defaults
  @defaults ||= { expects: 200 }
end

#error_handlerObject

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.



152
153
154
# File 'lib/peddler/client.rb', line 152

def error_handler
  (@error_handler ||= nil) || self.class.error_handler
end

#headersObject

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.



141
142
143
# File 'lib/peddler/client.rb', line 141

def headers
  @headers ||= {}
end

#marketplaceObject

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.



114
115
116
# File 'lib/peddler/client.rb', line 114

def marketplace
  @marketplace ||= find_marketplace
end

#marketplace_idObject

Deprecated.


97
98
99
# File 'lib/peddler/client.rb', line 97

def marketplace_id
  @primary_marketplace_id
end

#marketplace_id=(marketplace_id) ⇒ Object

Deprecated.


102
103
104
# File 'lib/peddler/client.rb', line 102

def marketplace_id=(marketplace_id)
  @primary_marketplace_id = marketplace_id
end

#on_error {|error| ... } ⇒ Object

Sets an error handler

Yield Parameters:

  • error (Excon::Error)


147
148
149
# File 'lib/peddler/client.rb', line 147

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.



157
158
159
# File 'lib/peddler/client.rb', line 157

def operation(action = nil)
  action ? @operation = Operation.new(action) : @operation
end

#runObject

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.



162
163
164
165
166
167
168
169
170
171
# File 'lib/peddler/client.rb', line 162

def run
  opts = build_options
  opts.store(:response_block, Proc.new) if block_given?
  res = post(opts)
  self.body = nil if res.status == 200

  parser.new(res, encoding)
rescue Excon::Error => e
  handle_error(e)
end