smartsend-ruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +7 -0
- data/README.md +38 -16
- data/lib/smartsend/account.rb +9 -0
- data/lib/smartsend/client.rb +12 -5
- data/lib/smartsend/order.rb +7 -5
- data/lib/smartsend/orders.rb +11 -4
- data/lib/smartsend/parcel.rb +3 -1
- data/lib/smartsend/receiver.rb +1 -1
- data/lib/smartsend/sender.rb +1 -1
- data/lib/smartsend/service.rb +1 -7
- data/lib/smartsend/version.rb +1 -1
- data/lib/smartsend.rb +18 -10
- data/smartsend-ruby.gemspec +2 -2
- data/test/test_addresses.rb +2 -2
- data/test/test_orders.rb +3 -1
- data/test/test_service.rb +1 -7
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1daea641d267754bf37d492b13ece1a513f6225e
|
4
|
+
data.tar.gz: 201cf9674744dbd1eb80118e310485814dbcc308
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97a78073a953cee9b2b2719dbaaa91dff9dbc42a6c5a0c19a4dec070bc22f58cca68766ba8ec39414849fe207b4a6854e67223b84a156fe7aba5aac856c2637c
|
7
|
+
data.tar.gz: a075eb79b103e433468a56d7db5bd6040ea5f47b0f1f023c1086367c2c5568e053d70957fb9e096bcdbef5587c86ae2dcd011aa51b4911867e1905c3705d95bf
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2017 Aske Behrsin Hansen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -10,9 +10,8 @@ Before beginning you need a Smartsend account.
|
|
10
10
|
gem install 'smartsend-ruby'
|
11
11
|
```
|
12
12
|
|
13
|
-
## Usage
|
14
13
|
|
15
|
-
|
14
|
+
## Configuration
|
16
15
|
|
17
16
|
```ruby
|
18
17
|
Smartsend.configure(
|
@@ -24,16 +23,18 @@ Smartsend.configure(
|
|
24
23
|
)
|
25
24
|
```
|
26
25
|
|
26
|
+
## Usage
|
27
|
+
|
27
28
|
### Creating an order
|
28
29
|
|
29
30
|
This creates a label.
|
30
31
|
|
31
32
|
```ruby
|
32
|
-
|
33
33
|
# initalize a new order
|
34
34
|
order = Smartsend::Order.new(
|
35
|
+
id: "123123123", # your internal order id
|
35
36
|
order_number: "AC12345789",
|
36
|
-
carrier: "
|
37
|
+
carrier: "postnord", # postnord/gls/bring
|
37
38
|
method: "private",
|
38
39
|
return: false,
|
39
40
|
total_price: 199.75,
|
@@ -58,8 +59,9 @@ order.receiver = Smartsend::Receiver.new(
|
|
58
59
|
mail: "contact@smartsend.io"
|
59
60
|
)
|
60
61
|
|
61
|
-
# set the
|
62
|
+
# optionally set the sender of the order
|
62
63
|
order.sender = Smartsend::Sender.new(
|
64
|
+
id: "123456",
|
63
65
|
company: "Smart Send",
|
64
66
|
name1: "Henrik Hansen",
|
65
67
|
name2: "C/O Vivian Hansen",
|
@@ -72,9 +74,9 @@ order.sender = Smartsend::Sender.new(
|
|
72
74
|
mail: "contact@smartsend.io"
|
73
75
|
)
|
74
76
|
|
75
|
-
#
|
77
|
+
# optionally ship to a droppoint by setting an agent
|
76
78
|
order.agent = Smartsend::Agent.new(
|
77
|
-
id: "
|
79
|
+
id: "2103", # droppoint id
|
78
80
|
type: "PDK", # droppoint provider
|
79
81
|
company: "Smart Send",
|
80
82
|
name1: "Henrik Hansen",
|
@@ -114,39 +116,59 @@ parcel_item = Smartsend::ParcelItem.new(
|
|
114
116
|
currency: "DKK"
|
115
117
|
)
|
116
118
|
|
117
|
-
parcel.items
|
118
|
-
order.parcels
|
119
|
+
parcel.items << parcel_item
|
120
|
+
order.parcels << parcel
|
119
121
|
|
120
122
|
# send the order to Smartsend.io
|
121
123
|
order.save!
|
122
124
|
```
|
123
125
|
|
124
|
-
After saving
|
126
|
+
After saving, the order it is updated with a url for the label pdf and tracking codes for each parcel.
|
125
127
|
|
126
128
|
```ruby
|
127
129
|
order.label_url
|
128
|
-
=> '
|
130
|
+
=> 'http://v70.api.smartsend.dk/...'
|
129
131
|
|
130
132
|
order.parcels.first.tracking_code
|
131
133
|
=> '1234...'
|
132
134
|
|
133
135
|
order.parcels.first.tracking_url
|
134
|
-
=> 'https
|
136
|
+
=> 'https://tracking.postnord.com/...'
|
135
137
|
```
|
136
138
|
|
137
139
|
### Creating orders in batch
|
138
140
|
|
139
141
|
You can create up to 10 orders in batch.
|
140
142
|
|
143
|
+
This updates all orders with a label_url and also gives you a labels_url with the combined labels
|
144
|
+
|
141
145
|
```ruby
|
142
|
-
order1 = Smartsend::Order.new(...)
|
143
|
-
order2 = Smartsend::Order.new(...)
|
144
146
|
|
145
|
-
orders = Smartsend::Orders.new
|
147
|
+
orders = Smartsend::Orders.new
|
148
|
+
orders << Smartsend::Order.new(...)
|
149
|
+
orders << Smartsend::Order.new(...)
|
146
150
|
|
147
151
|
# send the orders to Smartsend.io
|
148
152
|
orders.save_all!
|
149
153
|
|
154
|
+
orders.labels_url
|
155
|
+
=> 'http://v70.api.smartsend.dk/...'
|
156
|
+
|
150
157
|
orders.first.label_url
|
151
|
-
=> '
|
158
|
+
=> 'http://v70.api.smartsend.dk/...'
|
159
|
+
```
|
160
|
+
|
161
|
+
### Using multiple accounts
|
162
|
+
|
163
|
+
If your system requires multiple accounts you can pass an account instance when saving orders.
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
order = Smartsend::Order.new(...)
|
167
|
+
|
168
|
+
account = Smartsend::Account.new(
|
169
|
+
email: 'smartsend-username',
|
170
|
+
license: 'smartsend-license-key'
|
171
|
+
)
|
172
|
+
|
173
|
+
order.save!(account: account)
|
152
174
|
```
|
data/lib/smartsend/client.rb
CHANGED
@@ -4,6 +4,10 @@ class Smartsend::Client
|
|
4
4
|
|
5
5
|
BASE_URL = 'http://smartsend-prod.apigee.net/v7/booking'.freeze
|
6
6
|
|
7
|
+
def initialize(account=nil)
|
8
|
+
@account = account || Smartsend.account
|
9
|
+
end
|
10
|
+
|
7
11
|
def post(path, params)
|
8
12
|
request do
|
9
13
|
http.post("#{BASE_URL}/#{path}", json: params)
|
@@ -15,8 +19,11 @@ class Smartsend::Client
|
|
15
19
|
|
16
20
|
Rails.logger.debug(response.to_s) if defined?(Rails)
|
17
21
|
|
18
|
-
|
22
|
+
case response.code.to_s
|
23
|
+
when '200'
|
19
24
|
Response.new(JSON.parse(response)).successful!
|
25
|
+
when '401'
|
26
|
+
raise Smartsend::AuthorizationError, 'Unable to authorize'
|
20
27
|
else
|
21
28
|
Response.new(response).failed!
|
22
29
|
end
|
@@ -48,13 +55,13 @@ class Smartsend::Client
|
|
48
55
|
|
49
56
|
def http
|
50
57
|
raise Smartsend::MissingConfigError, 'Missing api_key' if Smartsend.api_key.nil?
|
51
|
-
raise Smartsend::MissingConfigError, 'Missing email'
|
52
|
-
raise Smartsend::MissingConfigError, 'Missing license' if
|
58
|
+
raise Smartsend::MissingConfigError, 'Missing email' if @account.email.nil?
|
59
|
+
raise Smartsend::MissingConfigError, 'Missing license' if @account.license.nil?
|
53
60
|
|
54
61
|
HTTP.headers(
|
55
62
|
apikey: Smartsend.api_key,
|
56
|
-
smartsendmail:
|
57
|
-
smartsendlicence:
|
63
|
+
smartsendmail: @account.email,
|
64
|
+
smartsendlicence: @account.license,
|
58
65
|
cmssystem: Smartsend.cms_system,
|
59
66
|
cmsversion: Smartsend.cms_version,
|
60
67
|
appversion: Smartsend.app_version,
|
data/lib/smartsend/order.rb
CHANGED
@@ -6,10 +6,12 @@ class Smartsend::Order
|
|
6
6
|
args.each do |k, v|
|
7
7
|
instance_variable_set "@#{k}", v
|
8
8
|
end
|
9
|
+
|
10
|
+
@parcels ||= []
|
9
11
|
end
|
10
12
|
|
11
|
-
def save!
|
12
|
-
response = Smartsend::Client.new.post('order', self.serialize)
|
13
|
+
def save!(account: nil)
|
14
|
+
response = Smartsend::Client.new(account).post('order', self.serialize)
|
13
15
|
|
14
16
|
if response.success?
|
15
17
|
update_label_url_tracking_codes(response)
|
@@ -20,8 +22,7 @@ class Smartsend::Order
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def update_label_url_tracking_codes(response)
|
23
|
-
@
|
24
|
-
@label_url = response['link']
|
25
|
+
@label_url = response['pdflink']
|
25
26
|
|
26
27
|
response['parcels'].each do |parcel_response|
|
27
28
|
if parcel = @parcels.select { |x| x.reference.to_s == parcel_response['reference'].to_s }.first
|
@@ -35,6 +36,7 @@ class Smartsend::Order
|
|
35
36
|
def serialize
|
36
37
|
{
|
37
38
|
orderno: @order_number,
|
39
|
+
reference: @id,
|
38
40
|
carrier: @carrier,
|
39
41
|
method: @method,
|
40
42
|
return: @return,
|
@@ -46,7 +48,7 @@ class Smartsend::Order
|
|
46
48
|
sender: @sender&.serialize,
|
47
49
|
receiver: @receiver&.serialize,
|
48
50
|
agent: @agent&.serialize,
|
49
|
-
parcels: @parcels.
|
51
|
+
parcels: @parcels.map(&:serialize),
|
50
52
|
service: service.serialize
|
51
53
|
}
|
52
54
|
end
|
data/lib/smartsend/orders.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
class Smartsend::Orders
|
2
2
|
include Enumerable
|
3
|
+
attr_accessor :labels_url
|
3
4
|
|
4
5
|
def initialize(*orders)
|
5
6
|
@orders = orders
|
6
7
|
end
|
7
8
|
|
8
|
-
def save_all!
|
9
|
+
def save_all!(account: nil)
|
9
10
|
raise Smartsend::TooManyOrdersError, "You can save a maximum of 10 orders in batch" if count > 10
|
10
11
|
|
11
|
-
response = Smartsend::Client.new.post('orders', self.serialize)
|
12
|
+
response = Smartsend::Client.new(account).post('orders', self.serialize)
|
12
13
|
|
13
14
|
update_label_url_tracking_codes(response)
|
14
15
|
|
@@ -16,13 +17,19 @@ class Smartsend::Orders
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def update_label_url_tracking_codes(response)
|
20
|
+
@labels_url = response['combine_pdf']
|
21
|
+
|
19
22
|
response['orders'].each do |response_order|
|
20
|
-
if order = @orders.select { |x| x.
|
21
|
-
order.update_label_url_tracking_codes(
|
23
|
+
if order = @orders.select { |x| x.id.to_s == response_order['reference'].to_s }.first
|
24
|
+
order.update_label_url_tracking_codes(response_order)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
29
|
+
def <<(order)
|
30
|
+
@orders << order
|
31
|
+
end
|
32
|
+
|
26
33
|
def serialize
|
27
34
|
@orders.map(&:serialize)
|
28
35
|
end
|
data/lib/smartsend/parcel.rb
CHANGED
@@ -5,6 +5,8 @@ class Smartsend::Parcel
|
|
5
5
|
args.each do |k, v|
|
6
6
|
instance_variable_set "@#{k}", v
|
7
7
|
end
|
8
|
+
|
9
|
+
@items ||= []
|
8
10
|
end
|
9
11
|
|
10
12
|
def serialize
|
@@ -16,7 +18,7 @@ class Smartsend::Parcel
|
|
16
18
|
:width => @width,
|
17
19
|
:length => @length,
|
18
20
|
:size => @size,
|
19
|
-
:items => @items.
|
21
|
+
:items => @items.map(&:serialize)
|
20
22
|
}
|
21
23
|
|
22
24
|
freetext_lines.to_a.each_with_index do |line, i|
|
data/lib/smartsend/receiver.rb
CHANGED
data/lib/smartsend/sender.rb
CHANGED
data/lib/smartsend/service.rb
CHANGED
@@ -10,13 +10,7 @@ class Smartsend::Service
|
|
10
10
|
def serialize
|
11
11
|
{
|
12
12
|
"notemail": @email,
|
13
|
-
"notesms": @phone
|
14
|
-
"prenote": true,
|
15
|
-
"prenote_from": "contact@smartsend.io",
|
16
|
-
"prenote_to": "contact@smartsend.io",
|
17
|
-
"prenote_message": "Your order is now on the way.",
|
18
|
-
"flex": "string",
|
19
|
-
"waybillid": "string"
|
13
|
+
"notesms": @phone
|
20
14
|
}
|
21
15
|
end
|
22
16
|
|
data/lib/smartsend/version.rb
CHANGED
data/lib/smartsend.rb
CHANGED
@@ -13,6 +13,10 @@ module Smartsend
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.account
|
17
|
+
Smartsend::Account.new(email: @@email, license: @@license)
|
18
|
+
end
|
19
|
+
|
16
20
|
def self.api_key
|
17
21
|
@@api_key
|
18
22
|
end
|
@@ -52,16 +56,20 @@ module Smartsend
|
|
52
56
|
class MissingConfigError < StandardError
|
53
57
|
end
|
54
58
|
|
59
|
+
class AuthorizationError < StandardError
|
60
|
+
end
|
55
61
|
|
56
62
|
end
|
57
63
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
require_relative 'smartsend/order'
|
65
|
+
require_relative 'smartsend/orders'
|
66
|
+
require_relative 'smartsend/address'
|
67
|
+
require_relative 'smartsend/receiver'
|
68
|
+
require_relative 'smartsend/sender'
|
69
|
+
require_relative 'smartsend/agent'
|
70
|
+
require_relative 'smartsend/service'
|
71
|
+
require_relative 'smartsend/parcel'
|
72
|
+
require_relative 'smartsend/parcel_item'
|
73
|
+
require_relative 'smartsend/client'
|
74
|
+
require_relative 'smartsend/account'
|
75
|
+
require_relative 'smartsend/version'
|
data/smartsend-ruby.gemspec
CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Smartsend::VERSION
|
8
8
|
s.date = '2017-11-13'
|
9
9
|
s.summary = "Smartsend.io api client"
|
10
|
-
s.description = "Create orders in smartsend
|
10
|
+
s.description = "Create orders in smartsend"
|
11
11
|
s.authors = ["Aske Hansen"]
|
12
12
|
s.email = 'aske@deeco.dk'
|
13
|
-
s.homepage = 'https://github.com/
|
13
|
+
s.homepage = 'https://github.com/smartsendio/smartsend-ruby'
|
14
14
|
s.license = 'MIT'
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
data/test/test_addresses.rb
CHANGED
@@ -7,7 +7,7 @@ class AddressesTest < Minitest::Test
|
|
7
7
|
sender = Smartsend::Sender.new(address)
|
8
8
|
|
9
9
|
assert_equal({
|
10
|
-
"senderid":
|
10
|
+
"senderid": 1,
|
11
11
|
"company": "Smart Send",
|
12
12
|
"name1": "Henrik Hansen",
|
13
13
|
"name2": "C/O Vivian Hansen",
|
@@ -25,7 +25,7 @@ class AddressesTest < Minitest::Test
|
|
25
25
|
receiver = Smartsend::Receiver.new(address)
|
26
26
|
|
27
27
|
assert_equal({
|
28
|
-
"
|
28
|
+
"receiverid": 1,
|
29
29
|
"company": "Smart Send",
|
30
30
|
"name1": "Henrik Hansen",
|
31
31
|
"name2": "C/O Vivian Hansen",
|
data/test/test_orders.rb
CHANGED
@@ -25,6 +25,7 @@ class OrdersTest < Minitest::Test
|
|
25
25
|
def params
|
26
26
|
{
|
27
27
|
orderno: 'AC12345789',
|
28
|
+
reference: '1234567',
|
28
29
|
carrier: 'postdanmark',
|
29
30
|
method: 'private',
|
30
31
|
return: false,
|
@@ -37,12 +38,13 @@ class OrdersTest < Minitest::Test
|
|
37
38
|
receiver: nil,
|
38
39
|
agent: nil,
|
39
40
|
parcels: [],
|
40
|
-
service: {:notemail=>"contact@smartsend.io", :notesms=>"12345678"
|
41
|
+
service: { :notemail=>"contact@smartsend.io", :notesms=>"12345678" }
|
41
42
|
}
|
42
43
|
end
|
43
44
|
|
44
45
|
def order
|
45
46
|
Smartsend::Order.new(
|
47
|
+
:id => "1234567",
|
46
48
|
:order_number => "AC12345789",
|
47
49
|
:carrier => "postdanmark",
|
48
50
|
:method => "private",
|
data/test/test_service.rb
CHANGED
@@ -8,13 +8,7 @@ class SerivceTest < Minitest::Test
|
|
8
8
|
|
9
9
|
assert_equal({
|
10
10
|
"notemail": "contact@smartsend.io",
|
11
|
-
"notesms": "12345678"
|
12
|
-
"prenote": true,
|
13
|
-
"prenote_from": "contact@smartsend.io",
|
14
|
-
"prenote_to": "contact@smartsend.io",
|
15
|
-
"prenote_message": "Your order is now on the way.",
|
16
|
-
"flex": "string",
|
17
|
-
"waybillid": "string"
|
11
|
+
"notesms": "12345678"
|
18
12
|
}, service.serialize)
|
19
13
|
end
|
20
14
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aske Hansen
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.2'
|
27
|
-
description: Create orders in smartsend
|
27
|
+
description: Create orders in smartsend
|
28
28
|
email: aske@deeco.dk
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
@@ -33,10 +33,12 @@ files:
|
|
33
33
|
- ".gitignore"
|
34
34
|
- Gemfile
|
35
35
|
- Gemfile.lock
|
36
|
+
- MIT-LICENSE
|
36
37
|
- README.md
|
37
38
|
- Rakefile
|
38
39
|
- lib/smartsend-ruby.rb
|
39
40
|
- lib/smartsend.rb
|
41
|
+
- lib/smartsend/account.rb
|
40
42
|
- lib/smartsend/address.rb
|
41
43
|
- lib/smartsend/agent.rb
|
42
44
|
- lib/smartsend/client.rb
|
@@ -56,7 +58,7 @@ files:
|
|
56
58
|
- test/test_parcels.rb
|
57
59
|
- test/test_service.rb
|
58
60
|
- test/test_smartsend.rb
|
59
|
-
homepage: https://github.com/
|
61
|
+
homepage: https://github.com/smartsendio/smartsend-ruby
|
60
62
|
licenses:
|
61
63
|
- MIT
|
62
64
|
metadata: {}
|