peddler 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b895fd9d95067954cbd73695cb806cf00ef7d67
4
- data.tar.gz: 4b5b4859c729b127b8c753cce4904f624a0ae912
3
+ metadata.gz: c7ac83135cc31198b41fceb4be3028d9944e702a
4
+ data.tar.gz: 5a48846777e07c4eb00cd068a81ca08586074a25
5
5
  SHA512:
6
- metadata.gz: c04561373d334ad22ff43f3dc8a9fe6ebb69fcd37a5d359d6d46dce1650582094fc698a2af482d29db0447d891da9300f1557b92943da5507d66ce0c72f16583
7
- data.tar.gz: 8a3bd3bfefb7c156858c025375d86c87a7b999e09798083ac6e047b7b1dedc297b3f86b3d73d1da524bf24dd3f4eaedf8796bc7573ff584b7274550028d67de3
6
+ metadata.gz: ff2c5463b8af1784df36c2040f1f149b8c80d9c0dc4f57ec2a1ed3a9550c72d3e9a9725a3c09061458ef33abb0bce0b7be30ad6bbbcddaf7c1c5a11a9a3c58a7
7
+ data.tar.gz: 9148086d4d91c67a83be7a999da65dd492b6db60d08c704ce58286fff11f7a25e73cbddd477b25957a42f329b15b4459c1e3df11590f39239554268d34ff9b0d
data/README.md CHANGED
@@ -11,33 +11,40 @@ To use Amazon MWS, you must have an eligible seller account.
11
11
 
12
12
  ![Peddler](http://f.cl.ly/items/231z2m0r1Q2o2q1n0w1N/peddler.jpg)
13
13
 
14
- ## Configuration
14
+ ## Scope
15
15
 
16
- Require the library and instantiate a client:
16
+ **Peddler** maps one on one to the MWS APIs and their various operations. It treats required request parameters as ordinary arguments and optional ones as keyword arguments. It parses XML responses with [**MultiXml**](https://github.com/sferik/multi_xml), which helps cast the result nodes into Ruby Hashes. Tab-delimited files are handled with Standard Library's [**CSV**](https://github.com/ruby/ruby/blob/trunk/lib/csv.rb).
17
+
18
+ Further abstraction is not in the scope of this project. See [**MWS Orders**](https://github.com/hakanensari/mws-orders) for a richer interface to the same-named API, built on **Peddler**.
19
+
20
+ ## Quick Start
17
21
 
18
22
  ```ruby
19
23
  require 'peddler'
24
+
20
25
  client = MWS.orders
26
+ parser = client.list_orders(created_after: 1.month.ago)
27
+ parser.parse
21
28
  ```
22
29
 
23
30
  You can set up credentials when instantiating:
24
31
 
25
32
  ```ruby
26
33
  client = MWS.orders(
27
- marketplace_id: 'A1F83G8C2ARO7P',
28
- merchant_id: 'A2A9WNXCU02UZW',
29
- aws_access_key_id: 'AKIVICHZMZ2JRSSLC27W',
30
- aws_secret_access_key: 'rOMa3ydPBTJ3AD0bxERTOX0Fv0fAC6Q0s6/czMZO'
34
+ marketplace_id: "YOUR_MARKETPLACE_ID",
35
+ merchant_id: "YOUR_MERCHANT_ID",
36
+ aws_access_key_id: "YOUR_AWS_ACCESS_KEY_ID",
37
+ aws_secret_access_key: "YOUR_AWS_SECRET_ACCESS_KEY"
31
38
  )
32
39
  ```
33
40
 
34
- Alternatively, use environment variables if you only have a single set of credentials:
41
+ Alternatively, you can use environment variables if you only have a single set of credentials:
35
42
 
36
43
  ```sh
37
- export MWS_MARKETPLACE_ID="A1F83G8C2ARO7P"
38
- export MWS_MERCHANT_ID="A2A9WNXCU02UZW"
39
- export AWS_ACCESS_KEY_ID="AKIVICHZMZ2JRSSLC27W"
40
- export AWS_SECRET_ACCESS_KEY="rOMa3ydPBTJ3AD0bxERTOX0Fv0fAC6Q0s6/czMZO"
44
+ export MWS_MARKETPLACE_ID=YOUR_MARKETPLACE_ID
45
+ export MWS_MERCHANT_ID=YOUR_MERCHANT_ID
46
+ export AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
47
+ export AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY
41
48
  ```
42
49
 
43
50
  ## Usage
@@ -142,7 +142,7 @@ module MWS
142
142
  # Returns delivery tracking information for a package in an outbound
143
143
  # shipment for a Multi-Channel Fulfillment order
144
144
  def get_package_tracking_details
145
- fail NotImplementedError
145
+ raise NotImplementedError
146
146
  end
147
147
 
148
148
  # Requests that Amazon stop attempting to fulfill an existing fulfillment
@@ -186,7 +186,7 @@ module MWS
186
186
  # @see http://docs.developer.amazonservices.com/en_US/reports/Reports_GetReportScheduleListByNextToken.html
187
187
  # @raise [NotImplementedError]
188
188
  def get_report_schedule_list_by_next_token(*)
189
- fail NotImplementedError
189
+ raise NotImplementedError
190
190
  end
191
191
 
192
192
  # Count scheduled reports
@@ -23,13 +23,21 @@ module Peddler
23
23
  }
24
24
 
25
25
  attr_accessor :path
26
- attr_writer :merchant_id, :marketplace_id, :parser
26
+ attr_writer :merchant_id, :marketplace_id
27
27
  attr_reader :body
28
28
 
29
29
  alias_method :configure, :tap
30
30
 
31
31
  params('SellerId' => -> { merchant_id })
32
32
 
33
+ def self.parser
34
+ @parser ||= Parser
35
+ end
36
+
37
+ def self.parser=(parser)
38
+ @parser = parser
39
+ end
40
+
33
41
  def self.path(path = nil)
34
42
  path ? @path = path : @path ||= '/'
35
43
  end
@@ -54,8 +62,8 @@ module Peddler
54
62
  @merchant_id ||= ENV['MWS_MERCHANT_ID']
55
63
  end
56
64
 
57
- def parser
58
- @parser ||= Parser
65
+ def defaults
66
+ @defaults ||= { expects: 200 }
59
67
  end
60
68
 
61
69
  def headers
@@ -72,7 +80,7 @@ module Peddler
72
80
  end
73
81
 
74
82
  def run(&blk)
75
- opts = { query: operation, headers: headers, expects: 200 }
83
+ opts = defaults.merge(query: operation, headers: headers)
76
84
  opts.store(:body, body) if body
77
85
  opts.store(:response_block, blk) if block_given?
78
86
  res = post(opts)
@@ -103,11 +111,15 @@ module Peddler
103
111
  end
104
112
 
105
113
  def host
106
- HOSTS.fetch(marketplace_id) { fail BadMarketplaceId }
114
+ HOSTS.fetch(marketplace_id) { raise BadMarketplaceId }
107
115
  end
108
116
 
109
117
  def extract_options(args)
110
118
  args.last.is_a?(Hash) ? args.pop : {}
111
119
  end
120
+
121
+ def parser
122
+ self.class.parser
123
+ end
112
124
  end
113
125
  end
@@ -1,3 +1,3 @@
1
1
  module Peddler
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
@@ -13,14 +13,12 @@ class TestPeddlerClient < MiniTest::Test
13
13
  Excon.stub({}, body: @body, status: 200)
14
14
 
15
15
  @klass = Class.new(Peddler::Client)
16
+ @klass.parser = Parser
16
17
  @client = @klass.new
17
-
18
18
  @client.aws_access_key_id = 'key'
19
19
  @client.aws_secret_access_key = 'secret'
20
20
  @client.merchant_id = 'seller'
21
21
  @client.marketplace_id = 'ATVPDKIKX0DER' # US
22
- @client.parser = Parser
23
-
24
22
  @client.operation('Foo')
25
23
  end
26
24
 
@@ -116,4 +114,23 @@ class TestPeddlerClient < MiniTest::Test
116
114
 
117
115
  assert_equal @body, chunks
118
116
  end
117
+
118
+ def test_request_preserves_user_agent
119
+ instrumentor = Class.new
120
+ class << instrumentor
121
+ attr_accessor :events
122
+
123
+ def instrument(name, params = {})
124
+ events.update(name => params)
125
+ yield if block_given?
126
+ end
127
+ end
128
+ instrumentor.events = {}
129
+
130
+ @client.defaults.update(instrumentor: instrumentor)
131
+ @client.run
132
+ headers = instrumentor.events['excon.request'][:headers]
133
+
134
+ assert headers.has_key?('User-Agent')
135
+ end
119
136
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peddler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-12 00:00:00.000000000 Z
11
+ date: 2014-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeff