smartsend-ruby 0.4.3 → 0.5.0

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: 05d95b8459e5449f3e3f8705cc764ee69c8641f37356ce10e1942d4d23d6231d
4
- data.tar.gz: 1dab6250bc9920d7724d4fc8e607a9a4c6589d57bb5b1b5f280370f6588c46f8
3
+ metadata.gz: d36b8c30a86a4866accdd796d49fde62d5e2fe8454460d1a28d21620f52d57db
4
+ data.tar.gz: 00c0cf8b2b5f219f03b4ccdc06aecdf3353c183909dd417721a19a927e784c2e
5
5
  SHA512:
6
- metadata.gz: 748ae771f8941ae465ff88d603341a18f625871b51192c2adae90214353ba700bd1f31d2207c89a04364807adac30ad7735de8afa82f2d3de302f1818f8e92ed
7
- data.tar.gz: d2807ed9dedc4341a50c30785532f530ad4ce5165baee33ee027ac58f47e0522b72f81a93dbae07886fafe278dc163bbb10fee362587729a693c382524424815
6
+ metadata.gz: 6462b9a13139bf477a86c27aa5a5bdbdd5b53c56923b94f4fece41108bbc6373f2522a056ed7c7b5220dc07eeedabccd9daa57f487b7bf66591fd7be49af3e26
7
+ data.tar.gz: 89df2896fa3dac223e5333cd43f7c2cbca5b2fcef7a5f3a33d82d5f3bb66b1be33500153a3d361c9e5db8a14f2a8fc5e0fa7f520fa29bd084da54528cd83c6aa
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5
data/README.md CHANGED
@@ -153,6 +153,9 @@ account.valid?
153
153
 
154
154
  ## Changelog
155
155
 
156
+ ### [0.5.0] - 2018-05-15
157
+ * Find label by tracking_code
158
+
156
159
  ### [0.4.3] - 2018-05-03
157
160
  * Using prod url
158
161
 
@@ -3,17 +3,23 @@ require 'logger'
3
3
 
4
4
  class Smartsend::Client
5
5
 
6
- def initialize(account=nil)
6
+ def initialize(account=nil, debug: false)
7
7
  @account = account || Smartsend.account
8
+ @debug = debug
8
9
  end
9
10
 
10
11
  def post(path, params)
12
+ debug("POST #{path}")
13
+ debug(params)
14
+
11
15
  request do
12
16
  http.post(url(path), json: params)
13
17
  end
14
18
  end
15
19
 
16
20
  def get(path)
21
+ debug("GET #{path}")
22
+
17
23
  request do
18
24
  http.get(url(path))
19
25
  end
@@ -26,8 +32,8 @@ class Smartsend::Client
26
32
  def request
27
33
  response = yield
28
34
 
29
- logger.debug(response)
30
- logger.debug(response.body.to_s)
35
+ debug(response)
36
+ debug(response.body.to_s)
31
37
 
32
38
  case response.code
33
39
  when (200..299)
@@ -68,16 +74,16 @@ class Smartsend::Client
68
74
 
69
75
  private
70
76
 
77
+ def debug(value)
78
+ Logger.new($stdout).debug(value) if @debug
79
+ end
80
+
71
81
  BASE_URL = 'http://smartsend-prod.apigee.net/api/v1'.freeze
72
82
 
73
83
  def url(path)
74
84
  "#{BASE_URL}/#{path}?api_token=#{@account.api_token}"
75
85
  end
76
86
 
77
- def logger
78
- Logger.new($stdout)
79
- end
80
-
81
87
  def user_agent_string
82
88
  (["Ruby/#{Smartsend::VERSION}"] + @account.user_agents.to_a).join(' ')
83
89
  end
@@ -0,0 +1,16 @@
1
+ class Smartsend::Label
2
+ attr_accessor :tracking_code, :url, :pdf
3
+
4
+ def self.find_by_tracking_code(tracking_code, account: nil)
5
+ response = Smartsend::Client.new(account, debug: true).get("shipments/tracking/#{tracking_code}/labels")
6
+
7
+ if response.success?
8
+ label = new
9
+ label.tracking_code = tracking_code
10
+ label.url = response.dig('data', 'pdf', 'link')
11
+ label.pdf = response.dig('data', 'pdf', 'base_64_encoded')
12
+ label
13
+ end
14
+ end
15
+
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Smartsend
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/smartsend.rb CHANGED
@@ -39,6 +39,7 @@ require_relative 'smartsend/services'
39
39
  require_relative 'smartsend/parcel'
40
40
  require_relative 'smartsend/parcel_item'
41
41
  require_relative 'smartsend/client'
42
+ require_relative 'smartsend/label'
42
43
  require_relative 'smartsend/account'
43
44
  require_relative 'smartsend/version'
44
45
  require_relative 'smartsend/request_error'
@@ -0,0 +1,16 @@
1
+ require 'minitest/autorun'
2
+ require 'smartsend'
3
+
4
+ class ShipmentTest < Minitest::Test
5
+
6
+ def test_find_label
7
+ Smartsend.configure(
8
+ api_token: ENV['SMARTSEND_TOKEN'],
9
+ )
10
+
11
+ assert_raises Smartsend::NotFoundError do
12
+ Smartsend::Label.find_by_tracking_code('123')
13
+ end
14
+ end
15
+
16
+ end
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.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aske Hansen
@@ -31,6 +31,7 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - ".gitignore"
34
+ - ".ruby-version"
34
35
  - Gemfile
35
36
  - Gemfile.lock
36
37
  - MIT-LICENSE
@@ -42,6 +43,7 @@ files:
42
43
  - lib/smartsend/address.rb
43
44
  - lib/smartsend/agent.rb
44
45
  - lib/smartsend/client.rb
46
+ - lib/smartsend/label.rb
45
47
  - lib/smartsend/parcel.rb
46
48
  - lib/smartsend/parcel_item.rb
47
49
  - lib/smartsend/receiver.rb
@@ -52,6 +54,7 @@ files:
52
54
  - lib/smartsend/version.rb
53
55
  - smartsend-ruby.gemspec
54
56
  - test/test_account.rb
57
+ - test/test_label.rb
55
58
  - test/test_shipment.rb
56
59
  - test/test_smartsend.rb
57
60
  homepage: https://github.com/smartsendio/smartsend-ruby
@@ -80,5 +83,6 @@ specification_version: 4
80
83
  summary: Smartsend.io api client
81
84
  test_files:
82
85
  - test/test_account.rb
86
+ - test/test_label.rb
83
87
  - test/test_shipment.rb
84
88
  - test/test_smartsend.rb