shipping_easy 0.2.2 → 0.3.0

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: 57853b3a7460d70af7dd2867a40dd19d52ef72f3
4
- data.tar.gz: 0c76624c1ad71e13c64653db58470ba3665697ca
3
+ metadata.gz: 5ff1cf485fdfa4f09bf7dbd69c89230897d98bc0
4
+ data.tar.gz: d14eaf59c001dfb06ce92aaefaa7e8c3d247c189
5
5
  SHA512:
6
- metadata.gz: 26160b7461cd4346d0c8e6ca0f40f01ded8aba1d338afce5fc35023cb3b5083d50ea6f318c113ff7635d0b6c8eec4ab95ac6dfa052ede253f611545471d2afc5
7
- data.tar.gz: 74a6bfef1b5168a09d33f186c6b4196832953058088a3b9a38db591269a9aae2f608094abc4bd5bf1d91c266920bab26e434ebfb6069581935107a3cef75640c
6
+ metadata.gz: cbbc3019268e0f8fc9ae38325ed377d4f716be23ee920ffdc200a7b90d42cfde9a92083bfdefc7d3adfbb3390c14f0ab4c21c8ee60a849bce127f2eb28c377fa
7
+ data.tar.gz: 870a7e66a8279a5ba38fc37abc1e7b8073760da54d33233e31c4282100b0911065a9f3771b74739dc22a5b3af5bde99d2a065df14e4dc1964fb9a4b7e43cacb0
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  *.gem
2
+ .idea
3
+ .ruby-*
2
4
  *.rbc
3
5
  .bundle
4
6
  .config
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ v0.3.0
2
+ - Added find and find_all methods to Order.
data/README.md CHANGED
@@ -60,6 +60,81 @@ The arguments for the constructor are as follows:
60
60
 
61
61
  ## API Calls
62
62
 
63
+ ### Finding an order
64
+
65
+ To retrieve a specific order, call the find method on the Order resource class with a ShippingEasy order ID specified.
66
+
67
+ ShippingEasy::Resources::Order.find(id: 876)
68
+
69
+ If successful the call will return a JSON hash with the ShippingEasy order.
70
+
71
+ Example payload may be found here:
72
+
73
+ https://gist.github.com/twmills/491b44fb6e78b20c1266
74
+
75
+ #### Possible Exceptions
76
+
77
+ ##### ShippingEasy::AccessDeniedError
78
+ Your credentials could not be authenticated or the store api_key could not be found.
79
+
80
+ ##### ShippingEasy::ResourceNotFoundError
81
+ The requested resource could not be found.
82
+
83
+ ##### ShippingEasy::InvalidRequestError
84
+ The order could not be created on the server for one or more of the following reasons:
85
+
86
+ * The API timestamp could not be parsed.
87
+
88
+ The exception will contain a message that indicates which of these conditions failed.
89
+
90
+ ### Retrieving multiple orders
91
+
92
+ To retrieve multiple orders, call the find_all method on the Order resource class with a ShippingEasy order ID specified.
93
+
94
+ ShippingEasy::Resources::Order.find_all
95
+
96
+ If successful the call will return a JSON hash included an array of orders and a hash metadata detailing the conditions used in the search as well as pagination details regarding the response.
97
+
98
+ #### Filtering Parameters
99
+
100
+ **page**
101
+ : The page to return in the paginated result set.
102
+
103
+ **per_page**
104
+ : The number of result to include per pagein the paginated result set. Defaults to 50 if not specified and the maximum number of results returned per page is 200.
105
+
106
+ **last_updated_at**
107
+ : Filters the results by the orders' last updated at timestamp and only returns results with a timestamp newer than or equal to the specified value. Defaults to 1 week ago if not specified. The maxiumum time this value can be set to is 3 months ago.
108
+
109
+ **status**
110
+ : Filters the results by the orders' ShippingEasy order status. Defaults to "shipped". Possible values are "shipped" and "ready_for_shipment". It is possible to pass an array of statuses, e.g. ["shipping", "ready_for_shipment"].
111
+
112
+ **page**
113
+ : The page to return in the paginated result set.
114
+
115
+ **store_api_key**
116
+ : By default orders are searched across all the stores on a customer's account. If you would like to filter on a specific API-driven store, include its API key.
117
+
118
+ #### Filtering Example
119
+
120
+ ShippingEasy::Resources::Order.find_all(page: 1, per_page: 1, status: ["ready_for_shipment", "shipped"], last_updated_at: "2014-05-07 14:42:18 UTC")
121
+
122
+ An example JSON response may be found here:
123
+
124
+ https://gist.github.com/twmills/005b3c4ab9c85330a801
125
+
126
+ #### Possible Exceptions
127
+
128
+ ##### ShippingEasy::AccessDeniedError
129
+ Your credentials could not be authenticated or the store api_key could not be found.
130
+
131
+ ##### ShippingEasy::InvalidRequestError
132
+ The order could not be created on the server for one or more of the following reasons:
133
+
134
+ * The API timestamp could not be parsed.
135
+
136
+ The exception will contain a message that indicates which of these conditions failed.
137
+
63
138
  ### Adding an order
64
139
 
65
140
  To add an order to a store, simply call the create method on the Order resource class. (A comprehensive list of the data attributes and their definitions can be found below.)
@@ -91,7 +166,7 @@ The following is a list of attributes that should be provided to the ShippingEas
91
166
 
92
167
  An example hash for the create order API call may be found here: https://gist.github.com/twmills/9349053.
93
168
 
94
- **ext_order_identifier**
169
+ **external_order_identifier**
95
170
  : *Required.* The e-commerce system's order ID.
96
171
 
97
172
  **ordered_at**
@@ -301,6 +376,9 @@ An example hash for the create order API call may be found here: https://gist.gi
301
376
  **recipients > line_items > unit_price**
302
377
  : Unit price of the item.
303
378
 
379
+ **recipients > line_items > product_options**
380
+ : Hash of product variations applicable to this line item. E.g. {"color":"red", "size":"XXL"}
381
+
304
382
  ### Cancelling an order
305
383
 
306
384
  Sometimes an e-commerce system will mark an order as shipped outside of the ShippingEasy system. Therefore an API call is required to remove this order from ShippingEasy so that it is not double-shipped.
@@ -21,6 +21,13 @@ class ShippingEasy::Http::FaradayAdapter
21
21
  end
22
22
  end
23
23
 
24
+ def get
25
+ connection.get do |req|
26
+ req.url uri, params
27
+ req.body = request.body
28
+ end
29
+ end
30
+
24
31
  def connection
25
32
  @connection ||= Faraday.new(url: base_url) do |faraday|
26
33
  faraday.adapter Faraday.default_adapter
@@ -1,10 +1,13 @@
1
1
  class ShippingEasy::Resources::Base
2
2
 
3
- def self.command(name, command_options, &block)
3
+ def self.command(name, command_options = {}, &block)
4
4
  define_singleton_method name do |options = {}|
5
- options[:relative_path] = command_options.fetch(:relative_path, block.call(options))
6
- options[:http_method] = command_options.fetch(:http_method, :get)
7
- execute_request!(options)
5
+ request_options = {}
6
+ request_options[:relative_path] = command_options.delete(:relative_path) || block.call(options)
7
+ request_options[:http_method] = command_options.delete(:http_method) || :get
8
+ request_options[:payload] = options.delete(:payload) if options.has_key?(:payload)
9
+ request_options[:params] = options unless options.nil? || options.empty?
10
+ execute_request!(request_options)
8
11
  end
9
12
  end
10
13
 
@@ -4,4 +4,16 @@ class ShippingEasy::Resources::Order < ShippingEasy::Resources::Base
4
4
  "/stores/#{args.delete(:store_api_key)}/orders"
5
5
  end
6
6
 
7
+ command :find do |args|
8
+ "/orders/#{args.delete(:id)}"
9
+ end
10
+
11
+ command :find_all do |args|
12
+ if args.has_key?(:store_api_key)
13
+ "/stores/#{args.delete(:store_api_key)}/orders"
14
+ else
15
+ "/orders"
16
+ end
17
+ end
18
+
7
19
  end
@@ -1,3 +1,3 @@
1
1
  module ShippingEasy
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -12,24 +12,33 @@ describe ShippingEasy::Resources::Base do
12
12
  end
13
13
 
14
14
  it "extracts options to send to a request" do
15
+ GenericResource.command(:find_all, http_method: :get) do |args|
16
+ "/orders"
17
+ end
18
+ GenericResource.should_receive(:execute_request!).with({:relative_path=>"/orders",
19
+ :http_method=>:get,
20
+ :params => {:page => 2,
21
+ :per_page => 3,
22
+ :status => [:shipped]}})
15
23
 
24
+ GenericResource.find_all(:page => 2, :per_page => 3, :status => [:shipped] )
16
25
  end
17
26
 
18
27
  context "when a block is provided" do
19
28
  it "uses it as the value for the path" do
20
- GenericResource.command(:create, method: :post) do |args|
29
+ GenericResource.command(:create, http_method: :post) do |args|
21
30
  "/this/is/the/path"
22
31
  end
23
- GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/path", :http_method=>:get})
32
+ GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/path", :http_method=>:post})
24
33
  GenericResource.create
25
34
  end
26
35
 
27
36
  context "and an argument is passed in" do
28
37
  it "interpolates it" do
29
- GenericResource.command(:create, method: :post) do |args|
38
+ GenericResource.command(:create, http_method: :post) do |args|
30
39
  "/this/is/the/#{args.delete(:name)}"
31
40
  end
32
- GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/ABC123", :http_method=>:get})
41
+ GenericResource.should_receive(:execute_request!).with({:relative_path=>"/this/is/the/ABC123", :http_method=>:post})
33
42
  GenericResource.create(name: "ABC123")
34
43
  end
35
44
  end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe ShippingEasy::Resources::Order do
4
+
5
+ describe ".find_all" do
6
+ it "sends a request with the expected options" do
7
+
8
+ ShippingEasy::Resources::Order.should_receive(:execute_request!).with({:relative_path=>"/orders",
9
+ :http_method=>:get,
10
+ :params => {:page => 2,
11
+ :per_page => 3,
12
+ :status => [:shipped]}})
13
+
14
+ ShippingEasy::Resources::Order.find_all(:page => 2, :per_page => 3, :status => [:shipped])
15
+ end
16
+ end
17
+
18
+ describe ".find" do
19
+ it "sends a request with the expected options" do
20
+ ShippingEasy::Resources::Order.should_receive(:execute_request!).with({:relative_path=>"/orders/2", :http_method=>:get})
21
+ ShippingEasy::Resources::Order.find(:id => 2)
22
+ end
23
+ end
24
+
25
+ describe ".create" do
26
+ it "sends a request with the expected options" do
27
+ ShippingEasy::Resources::Order.should_receive(:execute_request!).with({:relative_path=>"/stores/123456/orders", :http_method=>:post, payload: { name: "Jack" }})
28
+ ShippingEasy::Resources::Order.create(:store_api_key => "123456", payload: { name: "Jack" })
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipping_easy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShippingEasy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -104,6 +104,7 @@ files:
104
104
  - .gitignore
105
105
  - .rspec
106
106
  - .travis.yml
107
+ - CHANGELOG
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md
@@ -128,6 +129,7 @@ files:
128
129
  - spec/http/request_spec.rb
129
130
  - spec/http/response_handler_spec.rb
130
131
  - spec/resources/base_spec.rb
132
+ - spec/resources/order_spec.rb
131
133
  - spec/signature_spec.rb
132
134
  - spec/spec_helper.rb
133
135
  homepage: https://github.com/ShippingEasy/shipping_easy-ruby
@@ -150,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
152
  version: '0'
151
153
  requirements: []
152
154
  rubyforge_project:
153
- rubygems_version: 2.0.0
155
+ rubygems_version: 2.2.0
154
156
  signing_key:
155
157
  specification_version: 4
156
158
  summary: The official ShippingEasy API client for Ruby.
@@ -161,5 +163,6 @@ test_files:
161
163
  - spec/http/request_spec.rb
162
164
  - spec/http/response_handler_spec.rb
163
165
  - spec/resources/base_spec.rb
166
+ - spec/resources/order_spec.rb
164
167
  - spec/signature_spec.rb
165
168
  - spec/spec_helper.rb