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 +4 -4
- data/.travis.yml +3 -3
- data/Gemfile.lock +3 -3
- data/lib/parcel_api/label.rb +19 -12
- data/lib/parcel_api/version.rb +1 -1
- data/parcel_api.gemspec +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b4a64cee7c8d3f2bc58d3a657b75404bd4dfc18
|
4
|
+
data.tar.gz: b901efeb4b0573f25cfd1f7c5418281181976094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5c5b3d71b090caca863daa02e080480ec4d3da7b25eaedf4230bfe078142a31178e30dfc442971330c006a18eceaba30dea6928df6e3474e502902727c88177
|
7
|
+
data.tar.gz: a188ba9475063f663fec6d6fa46a58dc25e3ace41ba7f1243919132b1592053c4d923ef10da7e2249007dd508001a8167927af1eaaa79ec9d2316d04ebd04dfb
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -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.
|
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.
|
94
|
+
yard (~> 0.9)
|
95
95
|
|
96
96
|
BUNDLED WITH
|
97
|
-
1.
|
97
|
+
1.16.0
|
data/lib/parcel_api/label.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
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 =
|
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
|
data/lib/parcel_api/version.rb
CHANGED
data/parcel_api.gemspec
CHANGED
@@ -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.
|
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.
|
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:
|
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.
|
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.
|
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:
|