snap-api 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: caeae4ddeae317c237567774b5ecb054142b02d24d24bf4b1218f93d9feb44c7
4
- data.tar.gz: 950b6945052899297045d606dd9911a339576298b404354ee593a59147a162f7
3
+ metadata.gz: d4c7f2ab6265d52e1c9e48ca60783fb125559aa900188864a3c0553a00274977
4
+ data.tar.gz: c6825d01e780dc708f0344175bcf675fb2fb2564fe3517fd59230e559b97d1ae
5
5
  SHA512:
6
- metadata.gz: 73450e8a5dc843617f1289fb98c9f3eebb6cc16b9859fecdd644dc43db13f0c4f58f38df5838efb18cc05eea0ea2b7896c7e250249023aea260932f84664dbd4
7
- data.tar.gz: b32116608cba5ea60cfa3e393d8cdcfd5b2fc675af24bb1b9346aa7e98a80e8980cd49c437a032fff84741d1f1de4efdece180f38e78f8742deedd4eaf52b950
6
+ metadata.gz: 61cc3d73640512a749b649248ceb090d050abe0628fb832c219359d014c4473c057ca4c650c19b909679c4584c6dfeb2e5973e5778bdfc40660b2a2e9b78bac8
7
+ data.tar.gz: 442ab51322849cc78a28d7fec934cd652d79a606e89bd8c1f41d0ce4bb110591dbcb6eb98a70e9b86548501e45f63f0549fe0bb5b4979930184394223f91fb84
data/History.md CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ 0.1.5 / 2018-10-03
3
+ ==================
4
+
5
+ * Use Content-Type application/json
6
+ * Add errors!
7
+
2
8
  0.1.4 / 2018-09-30
3
9
  ==================
4
10
 
@@ -0,0 +1,8 @@
1
+ module Snap
2
+ module Api
3
+ # An order stage error occurs when you attempt to update a shipment that is
4
+ # in a stage that does not allow updates.
5
+ class OrderStageError < StandardError
6
+ end
7
+ end
8
+ end
@@ -7,7 +7,7 @@ module Snap
7
7
 
8
8
  def self.update(options)
9
9
  shipment_status = Snap::ShipmentStatus.new(options)
10
- client.put("/shipmentstatus/#{shipment_status.ShipmentId}", body: shipment_status)
10
+ client.put("/shipmentstatus/#{shipment_status.ShipmentId}", body: shipment_status.to_json)
11
11
  end
12
12
 
13
13
  def self.model
@@ -15,12 +15,15 @@ module Snap
15
15
 
16
16
  def self.create(options)
17
17
  shipment = Snap::Shipment.new(options)
18
- client.post('/shipments', body: shipment)
18
+ client.post('/shipments', body: shipment.to_json)
19
19
  end
20
20
 
21
21
  def self.update(options)
22
22
  shipment = Snap::Shipment.new(options)
23
- client.put("/shipments/#{shipment.ShipmentId}", body: shipment)
23
+ client.put(
24
+ "/shipments/#{shipment.ShipmentId}",
25
+ body: shipment.to_json
26
+ )
24
27
  end
25
28
 
26
29
  def self.model
data/lib/snap/client.rb CHANGED
@@ -6,6 +6,7 @@ module Snap
6
6
  def client
7
7
  base_uri Snap.config.endpoint
8
8
  basic_auth(Snap.config.username, Snap.config.password)
9
+ headers('Content-Type' => 'application/json')
9
10
  self
10
11
  end
11
12
 
@@ -34,7 +35,20 @@ module Snap
34
35
  end
35
36
 
36
37
  def wrap_response
37
- Snap::Response.new(yield, model)
38
+ httparty_response = yield
39
+ snoop_for_errors(httparty_response)
40
+ Snap::Response.new(httparty_response, model)
41
+ end
42
+
43
+ def snoop_for_errors(httparty_response)
44
+ case httparty_response.parsed_response.class
45
+ # Snap can return response bodies in many different formats. How we look
46
+ # for and what errors can occur are dependent on that type. For example
47
+ # 500's mostly return raw html as a string. Pages with lists are an
48
+ # Array. Resource endpoints are typically Hash.
49
+ when Hash
50
+ raise Api::OrderStageError, httparty_response if httparty_response.parsed_response.value? 'ORDER_STAGE'
51
+ end
38
52
  end
39
53
  end
40
54
  end
data/lib/snap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Snap
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
data/lib/snap.rb CHANGED
@@ -6,6 +6,8 @@ require 'snap/version'
6
6
  require 'snap/client'
7
7
  require 'snap/response'
8
8
 
9
+ require 'snap/api/errors/order_stage_error'
10
+
9
11
  require 'snap/api/outbound'
10
12
  require 'snap/api/stock_totals'
11
13
  require 'snap/api/shipment_status'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snap-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-01 00:00:00.000000000 Z
11
+ date: 2018-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -199,6 +199,7 @@ files:
199
199
  - bin/setup
200
200
  - config/initializers/snap.rb
201
201
  - lib/snap.rb
202
+ - lib/snap/api/errors/order_stage_error.rb
202
203
  - lib/snap/api/outbound.rb
203
204
  - lib/snap/api/shipment_status.rb
204
205
  - lib/snap/api/shipments.rb