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):

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


87
88
89
# File 'lib/peddler/client.rb', line 87

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

Class Attribute Details

.error_handlerObject (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

.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.



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

def parser
  @parser ||= Parser
end

Instance Attribute Details

#auth_tokenString

The MWSAuthToken used to access another seller’s account

Returns:

  • (String)


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

def auth_token
  @auth_token
end

#bodyString

The body of the HTTP request

Returns:

  • (String)


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

def body
  @body
end

#marketplace_idString

The merchant’s Marketplace ID

Returns:

  • (String)


99
100
101
# File 'lib/peddler/client.rb', line 99

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

#merchant_idString

The merchant’s Seller ID

Returns:

  • (String)


106
107
108
# File 'lib/peddler/client.rb', line 106

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

#pathString

The HTTP path of the API

Returns:

  • (String)


118
119
120
# File 'lib/peddler/client.rb', line 118

def path
  @path ||= self.class.path
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.



123
124
125
# File 'lib/peddler/client.rb', line 123

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

Class Method Details

.on_error {|request, response| ... } ⇒ Object

 Sets an error handler

Yield Parameters:

  • request (Excon::Request)
  • response (Excon::Response)


67
68
69
# File 'lib/peddler/client.rb', line 67

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.



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

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.



60
61
62
# File 'lib/peddler/client.rb', line 60

def version(version = nil)
  version ? @version = version : @version
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.



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

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.



134
135
136
# File 'lib/peddler/client.rb', line 134

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.



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

def error_handler
  @error_handler || 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.



139
140
141
# File 'lib/peddler/client.rb', line 139

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.



111
112
113
# File 'lib/peddler/client.rb', line 111

def marketplace
  @marketplace ||= find_marketplace
end

#on_error {|request, response| ... } ⇒ Object

 Sets an error handler

Yield Parameters:

  • request (Excon::Request)
  • response (Excon::Response)


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

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.



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

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.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/peddler/client.rb', line 161

def run
  opts = defaults.merge(query: operation, headers: headers)
  opts.store(:body, body) if body
  opts.store(:response_block, Proc.new) if block_given?
  res = post(opts)

  parser.new(res, encoding)
rescue Excon::Errors::Error => e
  handle_error(e) or raise
rescue NoMethodError => e
  if e.message == "undefined method `new' for #{parser}"
    warn "[DEPRECATION] `Parser.parse` is deprecated. Please use `Parser.new` instead."
    parser.parse(res, encoding)
  else
    raise
  end
end