Class: Peddler::Client Abstract

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

Overview

This class is abstract.

Subclass to implement an MWS API section.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



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

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

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



13
14
15
# File 'lib/peddler/client.rb', line 13

def auth_token
  @auth_token
end

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#marketplace_idObject



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

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

#merchant_idObject



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

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

#pathObject



70
71
72
# File 'lib/peddler/client.rb', line 70

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

Class Method Details

.inherited(base) ⇒ Object



38
39
40
# File 'lib/peddler/client.rb', line 38

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

.parserObject



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

def self.parser
  @parser ||= Parser
end

.parser=(parser) ⇒ Object



30
31
32
# File 'lib/peddler/client.rb', line 30

def self.parser=(parser)
  @parser = parser
end

.path(path = nil) ⇒ Object



34
35
36
# File 'lib/peddler/client.rb', line 34

def self.path(path = nil)
  path ? @path = path : @path ||= '/'
end

Instance Method Details

#aws_endpointObject



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

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

#defaultsObject



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

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

#headersObject



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

def headers
  @headers ||= {}
end

#marketplaceObject



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

def marketplace
  @marketplace ||= find_marketplace
end

#on_error(&blk) ⇒ Object



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

def on_error(&blk)
  @error_handler = blk
end

#operation(action = nil) ⇒ Object



83
84
85
# File 'lib/peddler/client.rb', line 83

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

#run(&blk) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/peddler/client.rb', line 87

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

  parser.parse(res, encoding)
rescue Excon::Errors::Error => ex
  handle_error(ex) or raise
end