parcel_api 1.2.0 → 1.2.1

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
  SHA1:
3
- metadata.gz: 8a13b9916fa74c4f67fecb998d3e1dea4f2e1a80
4
- data.tar.gz: 77a34e2f09f3652004658cb8d3d46481711a0804
3
+ metadata.gz: 7b4a64cee7c8d3f2bc58d3a657b75404bd4dfc18
4
+ data.tar.gz: b901efeb4b0573f25cfd1f7c5418281181976094
5
5
  SHA512:
6
- metadata.gz: 80523cc33e155600914746946f7f07750785405a9e227d8c5fc47b099b79b7d9b8f7ec955980b4b8587b7c1b0df4fb4aaae02f3d651c507bda748eeb4c9aad60
7
- data.tar.gz: d67c9e91c76821fcc008876348ab5424affc0e9040c0f37e650a79428836e2277a23f56082c3497cc3696d1c755b57b990e8ec5a186ad05cfd3b05e985247e5c
6
+ metadata.gz: b5c5b3d71b090caca863daa02e080480ec4d3da7b25eaedf4230bfe078142a31178e30dfc442971330c006a18eceaba30dea6928df6e3474e502902727c88177
7
+ data.tar.gz: a188ba9475063f663fec6d6fa46a58dc25e3ace41ba7f1243919132b1592053c4d923ef10da7e2249007dd508001a8167927af1eaaa79ec9d2316d04ebd04dfb
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- - 2.1.0
5
- - 2.0.0
3
+ - 2.4.3
4
+ - 2.3.7
5
+ - 2.2.10
6
6
  addons:
7
7
  code_climate:
8
8
  repo_token: 71a1f8fa6b8f4bd0e13542f237fd8f060d4dab088c71e5f980ed6247197d1820
@@ -77,7 +77,7 @@ GEM
77
77
  webmock (1.21.0)
78
78
  addressable (>= 2.3.6)
79
79
  crack (>= 0.3.2)
80
- yard (0.8.7.6)
80
+ yard (0.9.12)
81
81
 
82
82
  PLATFORMS
83
83
  ruby
@@ -91,7 +91,7 @@ DEPENDENCIES
91
91
  rspec (~> 3.2)
92
92
  vcr (~> 2.9)
93
93
  webmock (~> 1.21)
94
- yard (~> 0.8)
94
+ yard (~> 0.9)
95
95
 
96
96
  BUNDLED WITH
97
- 1.14.6
97
+ 1.16.0
@@ -6,10 +6,12 @@ module ParcelApi
6
6
  class Label
7
7
  LABEL_URL = '/ParcelLabel/2.0/labels'
8
8
 
9
+ attr_accessor :connection, :labels, :label_request, :label_response
10
+
9
11
  # Creates a new ParcelApi::Label instance.
10
12
 
11
- def initialize(connection=nil)
12
- @connection ||= connection || ParcelApi::Client.connection
13
+ def initialize(connection = nil)
14
+ self.connection ||= connection || ParcelApi::Client.connection
13
15
  end
14
16
 
15
17
  # Create a label with the specified options
@@ -17,10 +19,7 @@ module ParcelApi
17
19
  # @return Single or array of label objects
18
20
 
19
21
  def create(label_options)
20
- domestic_url = File.join(LABEL_URL, 'domestic')
21
- response = @connection.post domestic_url, body: label_options.to_json.to_ascii, headers: { 'Content-Type' => 'application/json' }
22
- labels = response.parsed['labels'].map {|label| OpenStruct.new(label)}
23
- labels.first if labels.count == 1
22
+ create_label File.join(LABEL_URL, 'domestic'), label_options
24
23
  end
25
24
 
26
25
  # Create an international label with the specified options
@@ -28,10 +27,7 @@ module ParcelApi
28
27
  # @return Single or array of label objects
29
28
 
30
29
  def international_create(label_options)
31
- international_url = File.join(LABEL_URL, 'international')
32
- response = @connection.post international_url, body: label_options.to_json.to_ascii, headers: { 'Content-Type' => 'application/json' }
33
- labels = response.parsed['labels'].map {|label| OpenStruct.new(label)}
34
- labels.first if labels.count == 1
30
+ create_label File.join(LABEL_URL, 'international', label_options)
35
31
  end
36
32
 
37
33
  # Get label details
@@ -40,7 +36,7 @@ module ParcelApi
40
36
 
41
37
  def details(label_id)
42
38
  details_url = File.join(LABEL_URL, "#{label_id}.json")
43
- response = @connection.get details_url
39
+ response = connection.get details_url
44
40
  details = response.parsed.tap {|d| d.delete('success')}
45
41
  OpenStruct.new(details)
46
42
  end
@@ -51,10 +47,21 @@ module ParcelApi
51
47
 
52
48
  def download(label_id)
53
49
  download_url = File.join(LABEL_URL, "#{label_id}.pdf")
54
- response = @connection.get download_url
50
+ response = connection.get download_url
55
51
  StringIO.new(response.body)
56
52
  end
57
53
 
54
+ private
55
+
56
+ def create_label(url, label_options)
57
+ self.label_request = {
58
+ body: label_options.to_json.to_ascii,
59
+ headers: { 'Content-Type' => 'application/json' }
60
+ }
61
+ self.label_response = connection.post(url, label_request)
62
+ self.label_response.parsed['labels'].map {|label| OpenStruct.new(label)}.first
63
+ end
64
+
58
65
  end
59
66
 
60
67
  end
@@ -1,3 +1,3 @@
1
1
  module ParcelApi
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'pry', '~> 0.10'
32
32
  spec.add_development_dependency 'webmock', '~> 1.21'
33
33
  spec.add_development_dependency 'vcr', '~> 2.9'
34
- spec.add_development_dependency 'yard', '~> 0.8'
34
+ spec.add_development_dependency 'yard', '~> 0.9'
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parcel_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Coleman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2018-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -190,14 +190,14 @@ dependencies:
190
190
  requirements:
191
191
  - - "~>"
192
192
  - !ruby/object:Gem::Version
193
- version: '0.8'
193
+ version: '0.9'
194
194
  type: :development
195
195
  prerelease: false
196
196
  version_requirements: !ruby/object:Gem::Requirement
197
197
  requirements:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
- version: '0.8'
200
+ version: '0.9'
201
201
  description:
202
202
  email:
203
203
  - github@robert.net.nz
@@ -254,4 +254,3 @@ signing_key:
254
254
  specification_version: 4
255
255
  summary: Ruby client for NZ Post's Parcel APIs
256
256
  test_files: []
257
- has_rdoc: