Class: Peddler::Service

Inherits:
Object
  • Object
show all
Includes:
Jeff
Defined in:
lib/peddler/service.rb

Overview

A wrapper around a Marketplace Web Services (MWS) endpoint.

Constant Summary collapse

HOSTS =

A list of MWS hosts.

{
  'CA' => 'mws.amazonservices.ca',
  'CN' => 'mws.amazonservices.com.cn',
  'DE' => 'mws-eu.amazonservices.com',
  'ES' => 'mws-eu.amazonservices.com',
  'FR' => 'mws-eu.amazonservices.com',
  'IN' => 'mws.amazonservices.in',
  'IT' => 'mws-eu.amazonservices.com',
  'JP' => 'mws.amazonservices.jp',
  'UK' => 'mws-eu.amazonservices.com',
  'US' => 'mws.amazonservices.com'
}
MARKETPLACES =

A list of MWS marketplace ids.

{
  'CA' => 'A2EUQ1WTGCTBG2',
  'CN' => nil,
  'DE' => 'A1PA6795UKMFR9',
  'ES' => 'A1RKKUPIHCS9HS',
  'FR' => 'A13V1IB3VIYZZH',
  'IN' => nil,
  'IT' => 'APJ6JRA9NG5V4',
  'JP' => 'A1VC38T7YXB528',
  'UK' => 'A1F83G8C2ARO7P',
  'US' => 'ATVPDKIKX0DER'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale) ⇒ Service

Create a new service endpoint for given locale.

locale - The String MWS API locale.

Raises a Bad Locale error if locale is not valid.



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

def initialize(locale)
  @host = HOSTS[@locale = locale] or raise BadLocale
end

Instance Attribute Details

#sellerObject

Gets the String MWS seller id.

Raises a Missing Seller error if seller id is missing.



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

def seller
  @seller or raise MissingSeller
end

Class Method Details

.inherited(base) ⇒ Object



51
52
53
# File 'lib/peddler/service.rb', line 51

def self.inherited(base)
  base.params(params)
end

.path(path = nil) ⇒ Object

Gets/Sets the path of the MWS endpoint.

path - A String path (optional).



15
16
17
18
# File 'lib/peddler/service.rb', line 15

def path(path = nil)
  @path = path if path
  @path
end

Instance Method Details

#configure(credentials) ⇒ Object

Configure the MWS endpoint.

credentials - The Hash credentials.

:key    - The String Amazon Web Services (AWS) key.
:secret - The String AWS secret.
:seller - The String MWS Seller Id.

Returns nothing.



72
73
74
# File 'lib/peddler/service.rb', line 72

def configure(credentials)
  credentials.each { |key, val| self.send("#{key}=", val) }
end

#endpointObject

 Returns the String MWS endpoint.



77
78
79
# File 'lib/peddler/service.rb', line 77

def endpoint
  "https://#{@host}/#{self.class.path}"
end

#marketplace(locale = nil) ⇒ Object

Returns a String Marketplace id.

locale - The String MWS API locale (default: the locale of the service

endpoint).


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

def marketplace(locale = nil)
  MARKETPLACES[locale || @locale] or raise BadLocale
end

#statusObject

Gets the String service status.



100
101
102
103
104
# File 'lib/peddler/service.rb', line 100

def status
  get(query: { 'Action' => 'GetServiceStatus' })
    .body
    .match(/GREEN_?I?|YELLOW|RED/)[0]
end