Class: Peddler::Client

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

Overview

An abstract client

Subclass this to implement an MWS API section.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Creates a new client

Parameters:

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

Options Hash (opts):

  • :aws_access_key_id (String)
  • :aws_secret_access_key (String)
  • :marketplace (String, Peddler::Marketplace)
  • :merchant_id (String)
  • :auth_token (String)


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

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

Class Attribute Details

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



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

def parser
  @parser
end

.pathObject

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.



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

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



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

def version
  @version
end

Instance Attribute Details

#auth_tokenString

Note:

You can omit this if you are accessing your own seller account

The MWS Auth Token for a seller’s account

Returns:

  • (String)


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

def auth_token
  @auth_token
end

#bodyString

The body of the HTTP request

Returns:

  • (String)


76
77
78
# File 'lib/peddler/client.rb', line 76

def body
  @body
end

#marketplacePeddler::Marketplace

Note:

You can pass the two-letter country code of the marketplace as shorthand when setting

The marketplace where you signed up as application developer



62
63
64
# File 'lib/peddler/client.rb', line 62

def marketplace
  @marketplace
end

#merchant_idString

The seller’s Merchant ID

Returns:

  • (String)


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

def merchant_id
  @merchant_id
end

#pathObject

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.



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

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



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

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.



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

def defaults
  @defaults ||= { expects: 200 }
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.



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

def headers
  @headers ||= {}
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.



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

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.



112
113
114
115
116
117
118
119
120
121
# File 'lib/peddler/client.rb', line 112

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::HTTPStatus => error
  handle_http_status_error(error)
end