smartsend-ruby 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/smartsend/client.rb +15 -9
- data/lib/smartsend/label.rb +1 -1
- data/lib/smartsend/shipment.rb +1 -1
- data/lib/smartsend/version.rb +1 -1
- data/test/test_shipment.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c45ce36e82559cb441b9b08910b5d8013a74a9ba7ac286394f71bb989ee75dea
|
4
|
+
data.tar.gz: 5167540923efdbcc3278b8c79d09d21be7a097f8c37dd4e85884f9a437d7a5c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abe6b8111118a639fcc3fa42442e15e9542c9b2d004536552dfa5d94655dd501eae30ef90f5364d0cb41c5e073c6f8e667ab8379811d330d97637130fb8d14b1
|
7
|
+
data.tar.gz: 81eadfc5a5fd8d1762b04ed533ac73e61da3d37b36661cf7f1e092b5a8e3c2f77eca8bf40cdd8d1c7f1f51a344ec2974cbb274be0238cf1eeba724d636e858a9
|
data/README.md
CHANGED
data/lib/smartsend/client.rb
CHANGED
@@ -2,15 +2,21 @@ require 'http'
|
|
2
2
|
require 'logger'
|
3
3
|
|
4
4
|
class Smartsend::Client
|
5
|
+
@@logging = false
|
5
6
|
|
6
|
-
def
|
7
|
+
def self.with_logs
|
8
|
+
@@logging = true
|
9
|
+
yield
|
10
|
+
@@logging = false
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(account=nil)
|
7
14
|
@account = account || Smartsend.account
|
8
|
-
@debug = debug
|
9
15
|
end
|
10
16
|
|
11
17
|
def post(path, params)
|
12
|
-
|
13
|
-
|
18
|
+
log("POST #{path}")
|
19
|
+
log(params)
|
14
20
|
|
15
21
|
request do
|
16
22
|
http.post(url(path), json: params)
|
@@ -18,7 +24,7 @@ class Smartsend::Client
|
|
18
24
|
end
|
19
25
|
|
20
26
|
def get(path)
|
21
|
-
|
27
|
+
log("GET #{path}")
|
22
28
|
|
23
29
|
request do
|
24
30
|
http.get(url(path))
|
@@ -32,8 +38,8 @@ class Smartsend::Client
|
|
32
38
|
def request
|
33
39
|
response = yield
|
34
40
|
|
35
|
-
|
36
|
-
|
41
|
+
log(response)
|
42
|
+
log(response.body.to_s)
|
37
43
|
|
38
44
|
case response.code
|
39
45
|
when (200..299)
|
@@ -74,8 +80,8 @@ class Smartsend::Client
|
|
74
80
|
|
75
81
|
private
|
76
82
|
|
77
|
-
def
|
78
|
-
Logger.new($stdout).
|
83
|
+
def log(value)
|
84
|
+
Logger.new($stdout).log(value) if @@logging
|
79
85
|
end
|
80
86
|
|
81
87
|
BASE_URL = 'http://smartsend-prod.apigee.net/api/v1'.freeze
|
data/lib/smartsend/label.rb
CHANGED
@@ -2,7 +2,7 @@ class Smartsend::Label
|
|
2
2
|
attr_accessor :tracking_code, :url, :pdf
|
3
3
|
|
4
4
|
def self.find_by_tracking_code(tracking_code, account: nil)
|
5
|
-
response = Smartsend::Client.new(account
|
5
|
+
response = Smartsend::Client.new(account).get("shipments/tracking/#{tracking_code}/labels")
|
6
6
|
|
7
7
|
if response.success?
|
8
8
|
label = new
|
data/lib/smartsend/shipment.rb
CHANGED
@@ -28,7 +28,7 @@ class Smartsend::Shipment
|
|
28
28
|
|
29
29
|
response['data']['parcels'].each do |parcel_response|
|
30
30
|
parcel = parcels.find do |item|
|
31
|
-
item.internal_id == parcel_response['parcel_internal_id']
|
31
|
+
item.internal_id.to_s == parcel_response['parcel_internal_id'].to_s
|
32
32
|
end
|
33
33
|
|
34
34
|
parcel&.label_url = parcel_response.dig('pdf', 'link')
|
data/lib/smartsend/version.rb
CHANGED
data/test/test_shipment.rb
CHANGED
@@ -71,7 +71,7 @@ class ShipmentTest < Minitest::Test
|
|
71
71
|
|
72
72
|
# add one or more parcels/fulfillments to the shipment
|
73
73
|
parcel = Smartsend::Parcel.new(
|
74
|
-
internal_id:
|
74
|
+
internal_id: 123456789, # your internal parcel id
|
75
75
|
internal_reference: "123456789",
|
76
76
|
weight: 1.25,
|
77
77
|
height: 21,
|