smartsend-ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +35 -0
- data/README.md +15 -9
- data/lib/smartsend/agent.rb +2 -2
- data/lib/smartsend/client.rb +35 -4
- data/lib/smartsend/order.rb +6 -3
- data/lib/smartsend/version.rb +1 -1
- data/test/test_addresses.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31f5d50cd758e048368ed4208cb76d4bf015b24d
|
4
|
+
data.tar.gz: 521b79b970af201b0def8cadc432b50ca4d592b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 304eeeca29e60ff755246261364455fbeb90fe15f8b8943a6cbb9125fff69d2fd908df91f80a68c84f786f8fedcec9e34dfb8ed504a07071918782afa9e14360
|
7
|
+
data.tar.gz: 65a5658a830cb9fd620baa76513a9d7994fd41abe9361665d537175db877d9872263972ffb6f61a11d716613e3ba7ec3bbe025393fc0c3f2b32d4991ca196148
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
smartsend-ruby (0.0.1)
|
5
|
+
http (~> 2.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
domain_name (0.5.20170404)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
http (2.2.2)
|
15
|
+
addressable (~> 2.3)
|
16
|
+
http-cookie (~> 1.0)
|
17
|
+
http-form_data (~> 1.0.1)
|
18
|
+
http_parser.rb (~> 0.6.0)
|
19
|
+
http-cookie (1.0.3)
|
20
|
+
domain_name (~> 0.5)
|
21
|
+
http-form_data (1.0.3)
|
22
|
+
http_parser.rb (0.6.0)
|
23
|
+
public_suffix (3.0.1)
|
24
|
+
unf (0.1.4)
|
25
|
+
unf_ext
|
26
|
+
unf_ext (0.0.7.4)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
smartsend-ruby!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.14.6
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# README
|
2
2
|
|
3
|
-
|
3
|
+
A ruby wrapper for the Smartsend.io api.
|
4
4
|
|
5
5
|
Before beginning you need a Smartsend account.
|
6
6
|
|
@@ -29,6 +29,8 @@ Smartsend.configure(
|
|
29
29
|
This creates a label.
|
30
30
|
|
31
31
|
```ruby
|
32
|
+
|
33
|
+
# initalize a new order
|
32
34
|
order = Smartsend::Order.new(
|
33
35
|
order_number: "AC12345789",
|
34
36
|
carrier: "postdanmark", # postdanmark/gls/bring
|
@@ -36,9 +38,12 @@ order = Smartsend::Order.new(
|
|
36
38
|
return: false,
|
37
39
|
total_price: 199.75,
|
38
40
|
shipping_price: 49,
|
39
|
-
currency: "DKK"
|
41
|
+
currency: "DKK",
|
42
|
+
sms_notification: "12345678",
|
43
|
+
email_notification: "contact@smartsend.io"
|
40
44
|
)
|
41
45
|
|
46
|
+
# set the receiver of the order
|
42
47
|
order.receiver = Smartsend::Receiver.new(
|
43
48
|
id: "123456", # your internal customer id
|
44
49
|
company: "Smart Send",
|
@@ -50,11 +55,10 @@ order.receiver = Smartsend::Receiver.new(
|
|
50
55
|
city: "Copenhagen",
|
51
56
|
country: "DK",
|
52
57
|
phone: "12345678",
|
53
|
-
mail: "contact@smartsend.io"
|
54
|
-
sms_notification: "12345678",
|
55
|
-
email_notification: "contact@smartsend.io"
|
58
|
+
mail: "contact@smartsend.io"
|
56
59
|
)
|
57
60
|
|
61
|
+
# set the receiver of the order
|
58
62
|
order.sender = Smartsend::Sender.new(
|
59
63
|
company: "Smart Send",
|
60
64
|
name1: "Henrik Hansen",
|
@@ -64,11 +68,11 @@ order.sender = Smartsend::Sender.new(
|
|
64
68
|
zip: "2100",
|
65
69
|
city: "Copenhagen",
|
66
70
|
country: "DK",
|
67
|
-
|
71
|
+
phone: "12345678",
|
68
72
|
mail: "contact@smartsend.io"
|
69
73
|
)
|
70
74
|
|
71
|
-
# you can ship to a droppoint by
|
75
|
+
# you can ship to a droppoint by seting an agent
|
72
76
|
order.agent = Smartsend::Agent.new(
|
73
77
|
id: "7224", # droppoint id
|
74
78
|
type: "PDK", # droppoint provider
|
@@ -84,6 +88,7 @@ order.agent = Smartsend::Agent.new(
|
|
84
88
|
mail: "contact@smartsend.io"
|
85
89
|
)
|
86
90
|
|
91
|
+
# add one or more parcels/fulfillments to the order
|
87
92
|
parcel = Smartsend::Parcel.new(
|
88
93
|
shipped_at: DateTime.now,
|
89
94
|
reference: "123456789", # your internal parcel id
|
@@ -99,12 +104,13 @@ parcel = Smartsend::Parcel.new(
|
|
99
104
|
]
|
100
105
|
)
|
101
106
|
|
107
|
+
# add items to the parcel
|
102
108
|
parcel_item = Smartsend::ParcelItem.new(
|
103
109
|
sku: "ABC123",
|
104
110
|
title: "ABC123",
|
105
111
|
quantity: 2,
|
106
|
-
|
107
|
-
|
112
|
+
unit_weight: 1.25,
|
113
|
+
unit_price: 144.5,
|
108
114
|
currency: "DKK"
|
109
115
|
)
|
110
116
|
|
data/lib/smartsend/agent.rb
CHANGED
data/lib/smartsend/client.rb
CHANGED
@@ -5,12 +5,43 @@ class Smartsend::Client
|
|
5
5
|
BASE_URL = 'http://smartsend-prod.apigee.net/v7/booking'.freeze
|
6
6
|
|
7
7
|
def post(path, params)
|
8
|
-
|
9
|
-
|
8
|
+
request do
|
9
|
+
http.post("#{BASE_URL}/#{path}", json: params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def request
|
14
|
+
response = yield
|
15
|
+
|
16
|
+
Rails.logger.debug(response.to_s) if defined?(Rails)
|
17
|
+
|
18
|
+
if /^2/ === response.code.to_s
|
19
|
+
Response.new(JSON.parse(response)).successful!
|
20
|
+
else
|
21
|
+
Response.new(response).failed!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Response < SimpleDelegator
|
26
|
+
|
27
|
+
def successful!
|
28
|
+
@success = true
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def failed!
|
33
|
+
@success = false
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def success?
|
38
|
+
@success
|
39
|
+
end
|
10
40
|
|
11
|
-
|
41
|
+
def failed?
|
42
|
+
!@success
|
43
|
+
end
|
12
44
|
|
13
|
-
response
|
14
45
|
end
|
15
46
|
|
16
47
|
private
|
data/lib/smartsend/order.rb
CHANGED
@@ -11,9 +11,12 @@ class Smartsend::Order
|
|
11
11
|
def save!
|
12
12
|
response = Smartsend::Client.new.post('order', self.serialize)
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if response.success?
|
15
|
+
update_label_url_tracking_codes(response)
|
16
|
+
self
|
17
|
+
else
|
18
|
+
response
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
def update_label_url_tracking_codes(response)
|
data/lib/smartsend/version.rb
CHANGED
data/test/test_addresses.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartsend-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aske Hansen
|
@@ -32,6 +32,7 @@ extra_rdoc_files: []
|
|
32
32
|
files:
|
33
33
|
- ".gitignore"
|
34
34
|
- Gemfile
|
35
|
+
- Gemfile.lock
|
35
36
|
- README.md
|
36
37
|
- Rakefile
|
37
38
|
- lib/smartsend-ruby.rb
|