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.

rubocop:disable ClassLength

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)


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



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

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.



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

def parser
  @parser ||= Parser
end

Instance Attribute Details

#auth_tokenString

The MWSAuthToken used to access another seller’s account

Returns:

  • (String)


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

def auth_token
  @auth_token
end

#bodyString

The body of the HTTP request

Returns:

  • (String)


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

def body
  @body
end

#merchant_idString

The merchant’s Seller ID

Returns:

  • (String)


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

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

#pathString

The HTTP path of the API

Returns:

  • (String)


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

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

#primary_marketplace_idString

The merchant’s Marketplace ID

Returns:

  • (String)


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

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.



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

Yield Parameters:

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


64
65
66
# File 'lib/peddler/client.rb', line 64

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.



52
53
54
# File 'lib/peddler/client.rb', line 52

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.



57
58
59
# File 'lib/peddler/client.rb', line 57

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.



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

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.



143
144
145
# File 'lib/peddler/client.rb', line 143

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.



160
161
162
# File 'lib/peddler/client.rb', line 160

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.



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

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.



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

def marketplace
  @marketplace ||= find_marketplace
end

#marketplace_idObject

Deprecated.


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

def marketplace_id
  @primary_marketplace_id
end

#marketplace_id=(marketplace_id) ⇒ Object

Deprecated.


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

Yield Parameters:

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


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

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.



165
166
167
# File 'lib/peddler/client.rb', line 165

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.



170
171
172
173
174
175
176
177
178
# File 'lib/peddler/client.rb', line 170

def run
  opts = build_options
  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