smartsend-ruby 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e21904f9f72b5f2539f62b745eae8ebd0e796ac
4
- data.tar.gz: b8fc28840c4ace20f5e760f05f47008fc950cbfd
3
+ metadata.gz: 31f5d50cd758e048368ed4208cb76d4bf015b24d
4
+ data.tar.gz: 521b79b970af201b0def8cadc432b50ca4d592b4
5
5
  SHA512:
6
- metadata.gz: 1dce17d09126216ec231abefee7a2e4ee8b7840e0e529d8cf12d8a18dab39d2b8fc4de84dbc6ddd88adeeee0cdf6b0c1a259506fdaa0320b6caac65a698af34d
7
- data.tar.gz: 8bc153718756d6ddd37b6a15cf43362ae4511f16261f5dbd5aa194a37de1ec52af912ed413d4ac05f20ed7d732e342342ddab64ac3d8538838180af06f49cc7f
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
- This is a ruby wrapper for the Smartsend.io api.
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
- sms: "12345678",
71
+ phone: "12345678",
68
72
  mail: "contact@smartsend.io"
69
73
  )
70
74
 
71
- # you can ship to a droppoint by defining an agent
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
- unitweight: 1.25,
107
- unitprice: 144.5,
112
+ unit_weight: 1.25,
113
+ unit_price: 144.5,
108
114
  currency: "DKK"
109
115
  )
110
116
 
@@ -1,11 +1,11 @@
1
1
  class Smartsend::Agent < Smartsend::Address
2
- attr_accessor :carrier
2
+ attr_accessor :type
3
3
 
4
4
  def serialize
5
5
  super.merge(
6
6
  id: @id,
7
7
  agentno: @id,
8
- agenttype: @carrier
8
+ agenttype: @type
9
9
  )
10
10
  end
11
11
 
@@ -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
- response = http.post("#{BASE_URL}/#{path}", json: params)
9
- response = JSON.parse(response)
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
- Rails.logger.debug(response) if defined?(Rails)
41
+ def failed?
42
+ !@success
43
+ end
12
44
 
13
- response
14
45
  end
15
46
 
16
47
  private
@@ -11,9 +11,12 @@ class Smartsend::Order
11
11
  def save!
12
12
  response = Smartsend::Client.new.post('order', self.serialize)
13
13
 
14
- update_label_url_tracking_codes(response)
15
-
16
- self
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)
@@ -1,3 +1,3 @@
1
1
  module Smartsend
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -40,7 +40,7 @@ class AddressesTest < Minitest::Test
40
40
  end
41
41
 
42
42
  def test_agent_serializing
43
- receiver = Smartsend::Agent.new(address.merge(carrier: 'PDK'))
43
+ receiver = Smartsend::Agent.new(address.merge(type: 'PDK'))
44
44
 
45
45
  assert_equal({
46
46
  "id": 1,
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.1
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