shipping_easy 0.5.1 → 0.6.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: ca4ac52af392f77a3a537b74210a2d5b29b826d6
4
- data.tar.gz: 0e9faecca79f6496af919b6b52f0c1534ce69ab9
3
+ metadata.gz: 4636298fa843b5ea5aa02f25d8e1ecec4bd092ba
4
+ data.tar.gz: 107c5c0016f39128ab1c2c24d0cf960d3d154202
5
5
  SHA512:
6
- metadata.gz: 8c9b4257ab9e56f41acf6838c43955c05e73ca6494643cc079f8e7959a1c76e779f1e503f6c9af15538ab924484a47b9c01f7438fc86fea8ce2aaaa6eda6fcb4
7
- data.tar.gz: 3a6b3e2248688713060c2423a85e6cf0c09ca488bf5d618712f894dc167aa34b9466cea83730abebe0667ff209d6474e4daf3930d6e10eec82a8366515cf98b0
6
+ metadata.gz: 6099a9900b9ac14d838d59c32ee0fb96efe693a40fbb7cdbe8afba54b1d53523ea1aa8892e009658bf265e018f4a18a855dc0ecc7c488b6ca14f74be181667ea
7
+ data.tar.gz: e29d8f25e9c2c9c269eb6ff34d88e307b1dafd07bbbadbc0d946fd49059f8016cd48ef9b60345133b18f25adebe82d3cbc109785b60cc54b8ef8b07d6d0bcf5a
data/README.md CHANGED
@@ -4,542 +4,9 @@
4
4
 
5
5
  This is the official wrapper for the ShippingEasy API.
6
6
 
7
- The ShippingEasy API supports the following features:
8
-
9
- * Secure, authenticated intake of orders for shipment
10
- * Cancellation of orders that no longer need to be shipped
11
- * A callback facility that provides shipment information (carrier, cost, tracking number, etc.) for an order
12
- * Query capabilities to read order data from ShippingEasy
13
-
14
- We will keep this library up to date as we expand the ShippingEasy API.
15
-
16
- ## Setup
17
-
18
- ### Installation
19
-
20
- Add this line to your application's Gemfile:
21
-
22
- gem 'shipping_easy'
23
-
24
- And then execute:
25
-
26
- $ bundle
27
-
28
- Or install it yourself as:
29
-
30
- $ gem install shipping_easy
31
-
32
- ### Configuration
33
-
34
- You will need a ShippingEasy API key and secret to sign your API requests. These can be found in your account's settings (https://app.shippingeasy.com/settings/api_credentials).
35
-
36
- Once you have the credentials, add them to the libary's configuration. Do this in an intializer if you're running a Rails app:
37
-
38
- ShippingEasy.configure do |config|
39
- config.api_key = 'd8e8fca2dc0f896fd7cb4cb0031ba249'
40
- config.api_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
41
- end
42
-
43
-
44
- If you are a 3rd party plugin developer and have a staging account with ShippingEasy, you can change the base URL like so:
45
-
46
- config.base_url = 'https://staging.shippingeasy.com'
47
-
48
- ## Authentication
49
-
50
- The ShippingEasy API will hit a callback URL when an order, or a part of an order, has been shipped. The request to the callback URL will be also signed with the same shared secret found in the store's API settings.
51
-
52
- This gem provides an Authenticator to handle verifying the signed request from ShippingEasy. Here's an example of how to use it (after you configured the library with your credentials in the step above):
53
-
54
- ShippingEasy::Authenticator.authenticate(method: :post, path: "/callback", body: "{\"shipment\":{\"id\":\"1234\"}}")
55
- # => true
56
-
57
- The arguments for the constructor are as follows:
58
-
59
- * **method** - The method of the http request. E.g. "post" or "get".
60
- * **path** - The path of the request's uri. E.g. "/orders/callback"
61
- * **params** - An associative array of the request's query string parameters. E.g. array("api_signature" => "asdsadsad", "api_timestamp" => "1234567899")
62
- * **body** - The request body as a JSON string.
63
- * **api_secret** - Optional. The ShippingEasy API secret for the customer account. Defaults to the global configuration if set.
64
-
65
- ## API Calls
66
-
67
- ### Finding an order
68
-
69
- To retrieve a specific order, call the find method on the Order resource class.
70
-
71
- ShippingEasy::Resources::Order.find(id: 876)
72
-
73
- If successful the call will return a JSON hash with the ShippingEasy order.
74
-
75
- Example payload may be found here:
76
-
77
- https://gist.github.com/twmills/491b44fb6e78b20c1266
78
-
79
- #### Possible Exceptions
80
-
81
- ##### ShippingEasy::AccessDeniedError
82
- Your credentials could not be authenticated or the store api_key could not be found.
83
-
84
- ##### ShippingEasy::ResourceNotFoundError
85
- The requested resource could not be found.
86
-
87
- ##### ShippingEasy::InvalidRequestError
88
- The order could not be created on the server for one or more of the following reasons:
89
-
90
- * The API timestamp could not be parsed.
91
-
92
- The exception will contain a message that indicates which of these conditions failed.
93
-
94
- ### Retrieving multiple orders
95
-
96
- To retrieve multiple orders, call the find_all method on the Order resource class with a ShippingEasy order ID specified.
97
-
98
- ShippingEasy::Resources::Order.find_all
99
-
100
- 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.
101
-
102
- #### Filtering Parameters
103
-
104
- **page**
105
- : The page to return in the paginated result set.
106
-
107
- **per_page**
108
- : 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.
109
-
110
- **last_updated_at**
111
- : 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.
112
-
113
- **status**
114
- : Filters the results by the orders' ShippingEasy order status. Defaults to "shipped". Possible values are "shipped" , "cleared", and "ready_for_shipment". It is possible to pass an array of statuses, e.g. ["shipping", "ready_for_shipment"].
115
-
116
- **page**
117
- : The page to return in the paginated result set.
118
-
119
- **store_api_key**
120
- : 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.
121
-
122
- #### Filtering Example
123
-
124
- 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")
125
-
126
- An example JSON response may be found here:
127
-
128
- https://gist.github.com/twmills/005b3c4ab9c85330a801
129
-
130
- #### Possible Exceptions
131
-
132
- ##### ShippingEasy::AccessDeniedError
133
- Your credentials could not be authenticated or the store api_key could not be found.
134
-
135
- ##### ShippingEasy::InvalidRequestError
136
- The orders could not retrieved for one or more of the following reasons:
137
-
138
- * The API timestamp could not be parsed.
139
-
140
- The exception will contain a message that indicates which of these conditions failed.
141
-
142
- ### Adding an order
143
-
144
- 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.)
145
-
146
- payload = { order: "external_order_identifier" => "ABC123", "subtotal_including_tax" => "12.38", ... }
147
- ShippingEasy::Resources::Order.create(store_api_key: "d8821dde1d32f408def40b77273d5c11", payload: payload)
148
-
149
- If successful the call will return a JSON hash with the ShippingEasy order ID, as well as the external order identifier originally supplied in your call.
150
-
151
- { "order" => { "id" => "27654", "external_order_identifier" => "ABC123" } }
152
-
153
- #### Possible Exceptions
154
-
155
- ##### ShippingEasy::AccessDeniedError
156
- Your credentials could not be authenticated or the store api_key could not be found.
157
-
158
- ##### ShippingEasy::InvalidRequestError
159
- The order could not be created on the server for one or more of the following reasons:
160
-
161
- * The JSON payload could not be parsed.
162
- * One or more of the supplied data attributes failed validation and is missing or incorrect.
163
- * An order with the supplied external_order_identifier already exists for that store.
164
-
165
- The exception will contain a message that indicates which of these conditions failed.
166
-
167
- #### Order Attributes
168
-
169
- The following is a list of attributes that should be provided to the ShippingEasy_Order object as a associative array.
170
-
171
- An example hash for the create order API call may be found here: https://gist.github.com/twmills/9349053.
172
-
173
- **external_order_identifier**
174
- : *Required.* The e-commerce system's order ID.
175
-
176
- **ordered_at**
177
- : *Required.* Timestamp when the order was created.
178
-
179
- **order_status**
180
- : Possible values are "awaiting_shipment", "awaiting_payment", "awaiting_fulfillment", "awaiting_shipment", "partially_shipped". Default is "awaiting_shipment".
181
-
182
- **total_including_tax**
183
- : Defaults to 0.0 if not specified.
184
-
185
- **total_excluding_tax**
186
- : Defaults to 0.0 if not specified.
187
-
188
- **discount_amount**
189
- : Defaults to 0.0 if not specified.
190
-
191
- **coupon_discount**
192
- : Defaults to 0.0 if not specified.
193
-
194
- **subtotal_including_tax**
195
- : Defaults to 0.0 if not specified.
196
-
197
- **subtotal_excluding_tax**
198
- : Defaults to 0.0 if not specified.
199
-
200
- **subtotal_tax**
201
- : Defaults to 0.0 if not specified.
202
-
203
- **total_tax**
204
- : Defaults to 0.0 if not specified.
205
-
206
- **base_shipping_cost**
207
- : Defaults to 0.0 if not specified.
208
-
209
- **shipping_cost_including_tax**
210
- : Defaults to 0.0 if not specified.
211
-
212
- **shipping_cost_excluding_tax**
213
- : Defaults to 0.0 if not specified.
214
-
215
- **shipping_cost_tax**
216
- : Defaults to 0.0 if not specified.
217
-
218
- **base_handling_cost**
219
- : Defaults to 0.0 if not specified.
220
-
221
- **handling_cost_excluding_tax**
222
- : Defaults to 0.0 if not specified.
223
-
224
- **handling_cost_including_tax**
225
- : Defaults to 0.0 if not specified.
226
-
227
- **handling_cost_tax**
228
- : Defaults to 0.0 if not specified.
229
-
230
- **base_wrapping_cost**
231
- : Defaults to 0.0 if not specified.
232
-
233
- **wrapping_cost_excluding_tax**
234
- : Defaults to 0.0 if not specified.
235
-
236
- **wrapping_cost_including_tax**
237
- : Defaults to 0.0 if not specified.
238
-
239
- **wrapping_cost_tax**
240
- : Defaults to 0.0 if not specified.
241
-
242
- **notes**
243
- : Customer notes on the order.
244
-
245
- **billing_company**
246
- : Company name for billing address
247
-
248
- **billing_first_name**
249
- : Customer first name for billing address
250
-
251
- **billing_last_name**
252
- : Customer last name for billing address
253
-
254
- **billing_address**
255
- : First address line for billing address
256
-
257
- **billing_address2**
258
- : Additional address line for billing address
259
-
260
- **billing_city**
261
- : City name for billing address
262
-
263
- **billing_state**
264
- : State name for billing address
265
-
266
- **billing_country**
267
- : Country name for billing address
268
-
269
- **billing_postal_code**
270
- : Postal code for billing address
271
-
272
- **billing_phone_number**
273
- : Phone number.
274
-
275
- **billing_email**
276
- : Email address
277
-
278
- **recipients**
279
- : A nested associative array of recipient attributes. At least one recipient is required.
280
-
281
- **recipients > company**
282
- : Company name for shipping address
283
-
284
- **recipients > first_name**
285
- : Customer first name for shipping address
286
-
287
- **recipients > last_name**
288
- : Customer last name for shipping address
289
-
290
- **recipients > address**
291
- : *Required.* First address line for shipping address
292
-
293
- **recipients > address2**
294
- : Additional address line for shipping address
295
-
296
- **recipients > city**
297
- : City name for shipping address
298
-
299
- **recipients > state**
300
- : State name for shipping address
301
-
302
- **recipients > country**
303
- : Country name for shipping address
304
-
305
- **recipients > residential**
306
- : Whether or not address is residential or not. Value can be "true" or "false".
307
-
308
- **recipients > postal_code**
309
- : *Required.* Postal code for shipping address
310
-
311
- **recipients > postal_code_plus_4**
312
- : Postal code plus 4 for shipping address
313
-
314
- **recipients > phone_number**
315
- : Customer phone number
316
-
317
- **recipients > email**
318
- : Customer email address
319
-
320
- **recipients > base_cost**
321
- : Cost before tax for all line items sent to this recipient
322
-
323
- **recipients > cost_excluding_tax**
324
- : Cost before tax for all line items sent to this recipient
325
-
326
- **recipients > cost_including_tax**
327
- : Cost including tax for all line items sent to this recipient
328
-
329
- **recipients > cost_tax**
330
- : Cost of the tax for all line items sent to this recipient
331
-
332
- **recipients > base_handling_cost**
333
- : Handling cost before tax for all line items sent to this recipient
334
-
335
- **recipients > handling_cost_excluding_tax**
336
- : Handling cost before tax for all line items sent to this recipient
337
-
338
- **recipients > handling_cost_including_tax**
339
- : Handling cost including tax for all line items sent to this recipient
340
-
341
- **recipients > handling_cost_tax**
342
- : Handling cost of the tax for all line items sent to this recipient
343
-
344
- **recipients > shipping_zone_id**
345
- : ID of the shipping zone.
346
-
347
- **recipients > shipping_zone_name**
348
- : Name of the shipping zone.
349
-
350
- **recipients > shipping_method**
351
- : Method of shipment.
352
-
353
- **recipients > items_total**
354
- : Total number of items.
355
-
356
- **recipients > items_shipped**
357
- : Total number of items shipped.
358
-
359
- **recipients > line_items**
360
- : A nested associative array of line item attributes. At least one line item is required.
361
-
362
- **recipients > line_items > item_name**
363
- : Name of the item/product.
364
-
365
- **recipients > line_items > sku**
366
- : SKU of the item/product.
367
-
368
- **recipients > line_items > bin_picking_number**
369
- : Bin number where the item may be stored in a warehouse.
370
-
371
- **recipients > line_items > weight_in_ounces**
372
- : Weight of the line item in ounces.
373
-
374
- **recipients > line_items > quantity**
375
- : Quantity of the the items for the line item.
376
-
377
- **recipients > line_items > total_excluding_tax**
378
- : Total excluding tax for the line item.
379
-
380
- **recipients > line_items > unit_price**
381
- : Unit price of the item.
382
-
383
- **recipients > line_items > product_options**
384
- : Hash of product variations applicable to this line item. E.g. {"color":"red", "size":"XXL"}
385
-
386
- ### Cancelling an order
387
-
388
- 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.
389
-
390
- Here's an example using your store's API key and the e-commerce order identifier used to create the order in ShippingEasy:
391
-
392
- ShippingEasy::Resources::Cancellation.create(store_api_key: "d8821dde1d32f408def40b77273d5c11", external_order_identifier: "ABC123")
393
-
394
- If successful the call will return a JSON hash with the ShippingEasy order ID, as well as the external order identifier originally supplied in your call.
395
-
396
- { "order" => { "id" => "27654", "external_order_identifier" => "ABC123" } }
397
-
398
- ### Rate Quote API
399
-
400
- ShippingEasy provides an API for our partners to fetch rate quotes from USPS, UPS or FedEx.
401
-
402
- Once you've setup your Partner credentials with a ShippingEasy account manager and have been issued an API key/secret, configure the client with your API credentials in the following block, which should be setup in an initializer:
403
-
404
- ShippingEasy.configure do |config|
405
- config.partner_api_key = REPLACE_WITH_API_KEY # Use your provided Partner API Key
406
- config.partner_api_secret = REPLACE_WITH_API_SECRET # Use your provided Partner API Secret
407
- config.base_url = "https://app.shippingeasy.com"
408
- end
409
-
410
- #### Rate Quote API Attributes
411
-
412
- The following is a list of attributes that should be provided to the `ShippingEasy::Resources::RateQuote` object as an associative array, using the `fetch` method.
413
-
414
- Some example hashes of rate quote request data for each carrier can be found at https://gist.github.com/nkrupa/3a76e592377f12bd96be
415
-
416
- **carrier**
417
- : *Required.* Must be one of the following (case-sensitive): `['usps', 'ups', 'fedex']`.
418
-
419
- **carrier_service**
420
- : *Required.* Must match the carrier-specific service API key (and is case-sensitive). For example, for USPS First Class International, use `FirstClassMailInternational`. See the carrier's documentation for possible service keys.
421
-
422
- **packaging**
423
- : *Required.* Use `custom` for customer-provided, otherwise specify the carrier-specific packaging key. For example, for USPS Small Flat Rate Box, use `SmallFlatRateBox`.
424
-
425
- **packaging_dimensions**
426
- : Valid only for customer-provided packaging. Must be a hash with all three keys of `:length, :width, :height`.
427
-
428
- **from_address_1**
429
- : *Required for UPS and FedEx*
430
-
431
- **from_address_2**
432
-
433
- **from_city**
434
- : *Required for UPS and FedEx*
435
-
436
- **from_state**
437
- : *Required for UPS and FedEx*
438
-
439
- **from_postal_code**
440
- : *Required for all carriers*
441
-
442
- **from_phone_number**
443
- : *Required for FedEx*
444
-
445
- **to_residential**
446
- : boolean (defaults to false) represented if destination address is residential. Used by UPS and FedEx.
447
-
448
- **to_postal_code**
449
- : *Required for USPS domestic rates, and for UPS and FedEx*
450
-
451
- **to_address_1**
452
- : *Required for UPS and FedEx*
453
-
454
- **to_address_2**
455
-
456
- **to_city**
457
- : *Required for UPS and FedEx*
458
-
459
- **to_state**
460
- : *Required for UPS and FedEx*
461
-
462
- **to_country_code**
463
- : *Required for all international quotes* Defaults to 'US', must be a two-digit ISO-3166 country code.
464
-
465
- **to_phone_number**
466
- : *Required for FedEx*
467
-
468
- **weight**
469
- : *Required for most carrier services* - represented in ounces.
470
-
471
- **confirmation_option**
472
- : Available options (not all available for all carriers/services): `["delivery_confirmation", "signature_required", "adult_signature_required", "verbal_confirmation", "DIRECT", "INDIRECT", "ADULT", "included_signature_confirmation", "restricted_delivery", "signature_confirmation", "adult_signature", "delivery_confirmation", "am_delivery"]`
473
-
474
- **requires_additional_handling**
475
- : Available for UPS only
476
-
477
- **saturday_pickup**
478
- : Available for UPS/FedEx only. Cannot be combined with saturday_delivery
479
-
480
- **saturday_delivery**
481
- : Available for UPS/FedEx only. Cannot be combined with saturday_pickup
482
-
483
- **ship_date**
484
- : *Required for FedEx*
485
-
486
-
487
- #### Possible Exceptions
488
-
489
- ##### ShippingEasy::AccessDeniedError
490
- Your credentials could not be authenticated or the store api_key could not be found.
491
-
492
- ##### ShippingEasy::InvalidRequestError
493
- The cancellation could not complete for one or more of the following reasons:
494
-
495
- * The order could not be found.
496
- * The order has already been marked as shipped in the ShippingEasy system and cannot be cancelled.
497
-
498
- The exception will contain a message that indicates which of these conditions failed.
499
-
500
- ## Making requests via curl
501
- First you will need to create an API signature. Concatenate these into a plaintext string using the following order:
502
-
503
- 1. Capitilized method of the request. E.g. "POST"
504
- 2. The URI path
505
- 3. The query parameters sorted alphabetically and concatenated together into a URL friendly format: param1=ABC&param2=XYZ
506
- 4. The request body as a string if one exists. Escape all double quotes with backslashes.
507
-
508
- All parts are then concatenated together with an ampersand. The result resembles something like this:
509
-
510
- "POST&/api/orders&api_key=f9a7c8ebdfd34beaf260d9b0296c7059&api_timestamp=1401803554&{\"orders\":{\"name\":\"Flip flops\",\"cost\":\"10.00\",\"shipping_cost\":\"2.00\"}}"
511
-
512
- Finally, using your API secret encrypt the string using HMAC sha256. In ruby, it looks like this:
513
-
514
- OpenSSL::HMAC::hexdigest("sha256", api_secret, "POST&/api/stores/27aa472e16faa83dd13b7758d31974ed/orders&api_key=f9a7c8ebdfd34beaf260d9b0296c7059&api_timestamp=1401803554&{\"orders\":{\"name\":\"Flip flops\",\"cost\":\"10.00\",\"shipping_cost\":\"2.00\"}}")
515
-
516
- ### API timestamp
517
- You must include an API timestamp in your requests. The timestamp should be a Unix epoch timestamp (integer) of the current time.
518
-
519
- ### Example curl requests
520
-
521
- #### Creating an order
522
-
523
- ````shell
524
- curl -H "Content-Type: application/json" --data @body.json "https://app.shippingeasy.com/api/stores/27aa472e16faa83dd13b7758d31974ed/orders?api_key=f9a7c8ebdfd34beaf260d9b0296c7059&api_timestamp=1401803554&api_signature=c65f43beed46e581939898a78acd10064cfa146845e97885ec02124d7ad648e4"
525
- ````
526
-
527
- An example body.json can be found here:
528
-
529
- https://gist.github.com/twmills/3f4636b835c611ab3f7f
530
-
531
- #### Cancelling an order
532
-
533
- ````shell
534
- curl -X POST "https://app.shippingeasy.com/api/stores/86eac265e87ea9a74a86fe248f2e79d2/orders/ABC123/cancellations?api_key=XXX&api_signature=c24c5118a2b2af27557af721145991594d00a0d914f0d9bc2b9a2fa26efb30cc&api_timestamp=1409173624"
535
- ````
536
-
537
- #### Searching orders
538
-
539
- ````shell
540
- curl "https://app.shippingeasy.com/api/orders?api_key=XXX&api_signature=a6ab10918d435ad2abfbbe6004dc2fc7faac62a291f4d66e4a36e5a654d15a54&api_timestamp=1409174329&page=3&per_page=10&status%5B%5D=ready_for_shipment&status%5B%5D=shipped"
541
- ````
7
+ Documentation is hosted here:
542
8
 
9
+ http://shippingeasy.readme.io/v1.0/docs/ruby-client-getting-started
543
10
 
544
11
  ## Contributing
545
12
 
@@ -1,11 +1,14 @@
1
1
  class ShippingEasy::Resources::Order < ShippingEasy::Resources::Base
2
-
3
2
  command :create, http_method: :post do |args|
4
3
  "/stores/#{args.delete(:store_api_key)}/orders"
5
4
  end
6
5
 
7
6
  command :find do |args|
8
- "/orders/#{args.delete(:id)}"
7
+ if args.has_key?(:store_api_key)
8
+ "/stores/#{args.delete(:store_api_key)}/orders/#{args.delete(:id)}"
9
+ else
10
+ "/orders/#{args.delete(:id)}"
11
+ end
9
12
  end
10
13
 
11
14
  command :find_all do |args|
@@ -15,5 +18,4 @@ class ShippingEasy::Resources::Order < ShippingEasy::Resources::Base
15
18
  "/orders"
16
19
  end
17
20
  end
18
-
19
21
  end
@@ -19,11 +19,12 @@ module ShippingEasy
19
19
  # :body - The body of the request which should normally be a JSON payload.
20
20
  #
21
21
  def initialize(options = {})
22
+ options = options.dup
22
23
  @api_secret = options.delete(:api_secret) || ""
23
24
  @method = options.fetch(:method, :get).to_s.upcase
24
25
  @path = options.delete(:path) || ""
25
26
  @body = options.delete(:body) || ""
26
- @params = options.delete(:params) || {}
27
+ @params = options[:params].nil? ? {} : options.delete(:params).dup
27
28
  @params.delete(:api_signature) # remove for convenience
28
29
  end
29
30
 
@@ -1,3 +1,3 @@
1
1
  module ShippingEasy
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -3,28 +3,50 @@ require "spec_helper"
3
3
  describe ShippingEasy::Resources::Order do
4
4
 
5
5
  describe ".find_all" do
6
- it "sends a request with the expected options" do
6
+ context "when store ID is not included" do
7
+ it "sends a request with the expected options" do
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] } }, :public)
13
+
14
+ ShippingEasy::Resources::Order.find_all(:page => 2, :per_page => 3, :status => [:shipped])
15
+ end
16
+ end
7
17
 
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]}}, :public)
18
+ context "when store ID is included" do
19
+ it "sends a request with the expected options" do
20
+ ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/stores/123456/orders",
21
+ :http_method => :get,
22
+ :params => { :page => 2,
23
+ :per_page => 3,
24
+ :status => [:shipped] } }, :public)
13
25
 
14
- ShippingEasy::Resources::Order.find_all(:page => 2, :per_page => 3, :status => [:shipped])
26
+ ShippingEasy::Resources::Order.find_all(:store_api_key => "123456", :page => 2, :per_page => 3, :status => [:shipped])
27
+ end
15
28
  end
16
29
  end
17
30
 
18
31
  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}, :public)
21
- ShippingEasy::Resources::Order.find(:id => 2)
32
+ context "when store ID is not included" do
33
+ it "sends a request with the expected options" do
34
+ ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/orders/2", :http_method => :get }, :public)
35
+ ShippingEasy::Resources::Order.find(:id => 2)
36
+ end
37
+ end
38
+
39
+ context "when store ID is included" do
40
+ it "sends a request with the expected options" do
41
+ ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/stores/123456/orders/2", :http_method => :get }, :public)
42
+ ShippingEasy::Resources::Order.find(:store_api_key => "123456", :id => 2)
43
+ end
22
44
  end
23
45
  end
24
46
 
25
47
  describe ".create" do
26
48
  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" }}, :public)
49
+ ShippingEasy::Resources::Order.should_receive(:execute_request!).with({ :relative_path => "/stores/123456/orders", :http_method => :post, payload: { name: "Jack" } }, :public)
28
50
  ShippingEasy::Resources::Order.create(:store_api_key => "123456", payload: { name: "Jack" })
29
51
  end
30
52
  end
@@ -8,15 +8,35 @@ describe ShippingEasy::Signature do
8
8
  let(:request_body) { { orders: { name: "Flip flops", cost: "10.00", shipping_cost: "2.00" } }.to_json.to_s }
9
9
  let(:method) { :post }
10
10
 
11
- subject { ShippingEasy::Signature.new(api_secret: api_secret, method: method, path: path, params: params, body: request_body) }
11
+ let(:options) { {api_secret: api_secret, method: method, path: path, params: params, body: request_body} }
12
+ subject { ShippingEasy::Signature.new(options) }
12
13
 
13
14
  describe "#initialize" do
14
15
  specify { subject.api_secret.should == api_secret }
15
16
  specify { subject.method.should == "POST" }
16
17
  specify { subject.path.should == path }
17
18
  specify { subject.body.should == request_body }
18
- specify { subject.params.should == params }
19
19
  specify { subject.params[:api_signature].should be_nil }
20
+
21
+ it "does not modify the input hash" do
22
+ expect(subject).to_not be_nil
23
+ expect(options).to have_key(:api_secret)
24
+ expect(options).to have_key(:method)
25
+ expect(options).to have_key(:path)
26
+ expect(options).to have_key(:params)
27
+ end
28
+
29
+ it "does not modify the passed in params hash" do
30
+ expect(subject).to_not be_nil
31
+ expect(params).to have_key :test_param
32
+ expect(params).to have_key :api_key
33
+ expect(params).to have_key :api_signature
34
+ end
35
+
36
+ it "the exposed params hash does not contain the api_signature" do
37
+ params_without_signature = params.reject{|k,v| k == :api_signature}
38
+ expect(subject.params).to eq params_without_signature
39
+ end
20
40
  end
21
41
 
22
42
  describe "#plaintext" do
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipping_easy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.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-12-05 00:00:00.000000000 Z
11
+ date: 2015-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.8.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.8.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.4.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.4.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.8.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.8.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: The official ShippingEasy API client for Ruby.
@@ -101,9 +101,9 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - .gitignore
105
- - .rspec
106
- - .travis.yml
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
107
  - CHANGELOG
108
108
  - Gemfile
109
109
  - LICENSE.txt
@@ -148,17 +148,17 @@ require_paths:
148
148
  - lib
149
149
  required_ruby_version: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - '>='
151
+ - - ">="
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - '>='
156
+ - - ">="
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.2.2
161
+ rubygems_version: 2.4.8
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: The official ShippingEasy API client for Ruby.