shipppit-canada-post 0.5.1 → 0.5.2

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: fd38859443dc7b05a54e7aa1a261da790092a3ee
4
- data.tar.gz: bd72c15948dcfed708388ebc41c29da061bc8004
3
+ metadata.gz: e71df1fc73d258b2507a86f1acaea2febf74667c
4
+ data.tar.gz: 5df51cc9a3174de2a3faaddbd873f5eb80ce3990
5
5
  SHA512:
6
- metadata.gz: 652e4fece5355352bedcd17f1190c4ca23ae5626c805da4e998e3476665f452f6a5cbd0d4d65d8a79d1074b44c67ca37bd8445e922ffd1488968ffad58199e1e
7
- data.tar.gz: 3403823d0b6b9c1d6f8a81ec2725c9384c3d8ed44b0a2cef6edc3179393d4746a1f46abfb986b54893968f3aaeee1ab43df7434e49e5f535452ca6a92696629f
6
+ metadata.gz: c56d09c4bc84a56f2e311d16c66d792254e5e5edd365dda58995eaeba6bdf82a1982f54478f8fae25e9662fe76c1813884002d8090a9eede5de1f90ac4137f71
7
+ data.tar.gz: 82b8070994af506e4ed57bba35543f9f23482ae1a5746fb18dcef3e23054969fc244c7e5dc5cb22e2a4557c0ff800d2a96eaea78a4e8661cca66325bc111c103
data/README.md CHANGED
@@ -214,7 +214,7 @@ canada_post_service.create(
214
214
  Use this call to get a unique registration token (token-id) required to launch a merchant into the Canada Post sign-up process.
215
215
 
216
216
  ```ruby
217
- @token = canada_post_service.registration
217
+ @token = canada_post_service.registration_token
218
218
  {'token-id' => '11111111111111111111111'}
219
219
  ```
220
220
 
data/lib/canada_post.rb CHANGED
@@ -6,7 +6,6 @@ require "canada_post/request/registration"
6
6
  require "canada_post/client"
7
7
  require "canada_post/credentials"
8
8
  require "canada_post/rate"
9
- require "canada_post/shipment"
10
9
 
11
10
  module CanadaPost
12
11
  # Exceptions: CandaPost::RateError
@@ -33,19 +33,23 @@ module CanadaPost
33
33
  Request::Registration.new(@credentials).get_token
34
34
  end
35
35
 
36
+ def get_merchant_info(token)
37
+ Request::Registration.new(@credentials).merchant_info(token)
38
+ end
39
+
36
40
  def get_artifact(url)
37
41
  manifest = Request::Manifest.new(@credentials).get_manifest(url)
38
42
  if manifest[:errors].present?
39
43
  return {
40
- status: false,
41
- error: manifest[:errors]
44
+ status: false,
45
+ error: manifest[:errors]
42
46
  }
43
47
  else
44
48
  artifact_link = get_artifact_link(manifest[:manifest])
45
49
  artifact = Request::Manifest.new(@credentials).get_artifact(artifact_link)
46
50
  return {
47
- status: true,
48
- artifact: artifact
51
+ status: true,
52
+ artifact: artifact
49
53
  }
50
54
  end
51
55
  end
@@ -9,7 +9,7 @@ module CanadaPost
9
9
  @username = options[:username]
10
10
  @password = options[:password]
11
11
  @customer_number = options[:customer_number]
12
- @mode = options[:mode] || "development"
12
+ @mode = options[:mode] || 'development'
13
13
  end
14
14
 
15
15
  end
@@ -3,7 +3,6 @@ require 'nokogiri'
3
3
  require 'active_support/core_ext/hash'
4
4
  require 'canada_post/helpers'
5
5
  require 'canada_post/rate'
6
- require 'canada_post/shipment'
7
6
 
8
7
  module CanadaPost
9
8
  module Request
@@ -91,7 +91,6 @@ module CanadaPost
91
91
  headers: shipping_header,
92
92
  basic_auth: @authorization
93
93
  )
94
- puts api_response
95
94
  process_response(api_response)
96
95
  end
97
96
 
@@ -1,3 +1,3 @@
1
1
  module CanadaPost
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'canada_post'
3
- require 'canada_post/shipment'
4
3
  require 'canada_post/client'
5
4
 
6
5
  describe CanadaPost::Request::Manifest do
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
  require 'canada_post'
3
- require 'canada_post/shipment'
4
3
  require 'canada_post/client'
5
4
 
6
5
  describe CanadaPost::Request::Registration do
@@ -1,9 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'canada_post'
3
- require 'canada_post/shipment'
4
3
  require 'canada_post/client'
5
4
 
6
- describe CanadaPost::Shipment do
5
+ describe CanadaPost::Request::Shipping do
7
6
  context 'missing required parameters' do
8
7
  it 'does raise Rate exception' do
9
8
  expect { CanadaPost::Client.new }.to raise_error(CanadaPost::RateError)
@@ -100,16 +99,16 @@ describe CanadaPost::Shipment do
100
99
  context "Create MOBO shipping (on behalf of)", :vcr do
101
100
  let(:shipping) {
102
101
  canada_post_service.create(
103
- sender: sender,
104
- destination: destination,
105
- package: package,
106
- mobo: mobo,
107
- notification: notification,
108
- preferences: preferences,
109
- group_id: group_id[:value],
110
- mailing_date: mailing_date[:value],
111
- service_code: service_code[:value],
112
- contract_number: contract_number[:value]
102
+ sender: sender,
103
+ destination: destination,
104
+ package: package,
105
+ mobo: mobo,
106
+ notification: notification,
107
+ preferences: preferences,
108
+ group_id: group_id[:value],
109
+ mailing_date: mailing_date[:value],
110
+ service_code: service_code[:value],
111
+ contract_number: contract_number[:value]
113
112
  )
114
113
  }
115
114
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipppit-canada-post
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -150,9 +150,7 @@ files:
150
150
  - lib/canada_post/request/manifest.rb
151
151
  - lib/canada_post/request/rate.rb
152
152
  - lib/canada_post/request/registration.rb
153
- - lib/canada_post/request/shipment.rb
154
153
  - lib/canada_post/request/shipping.rb
155
- - lib/canada_post/shipment.rb
156
154
  - lib/canada_post/version.rb
157
155
  - spec/config/canada_post_credentials.example.yml
158
156
  - spec/manifest_spec.rb
@@ -1,96 +0,0 @@
1
- module CanadaPost
2
- module Request
3
- class Shipment < Base
4
-
5
- def process_request
6
- api_response = client(shipment_url, build_xml, shipment_headers)
7
- response = parse_response(api_response)
8
-
9
- if success?(response)
10
- rate_reply_details = response[:price_quotes][:price_quote] || []
11
- rate_reply_details = [rate_reply_details] if rate_reply_details.is_a? Hash
12
- rate_reply_details.map do |rate_reply|
13
- CanadaPost::Shipment.new(rate_reply)
14
- end
15
- else
16
- error_message = if response[:messages]
17
- response[:messages][:message][:description]
18
- else
19
- 'api_response.response'
20
- end
21
- raise ShipmentError, error_message
22
- end
23
- end
24
-
25
- private
26
-
27
- def shipment_headers
28
- api_url += "rs/{mailed by customer}/{mobo}/shipment"
29
- end
30
-
31
- def shipment_headers
32
- {
33
- 'Content-type' => 'application/vnd.cpc.shipment-v7+xml',
34
- 'Accept' => 'application/vnd.cpc.shipment-v7+xml'
35
- }
36
- end
37
-
38
- def build_xml
39
- ns = "http://www.canadapost.ca/ws/shipment-v7"
40
- builder = Nokogiri::XML::Builder.new do |xml|
41
- xml.send(:"mailing-scenario", xmlns: ns) {
42
- add_requested_shipment(xml)
43
- }
44
- end
45
- builder.doc.root.to_xml
46
- end
47
-
48
- def add_requested_shipment(xml)
49
- xml.send(:"customer-number", @customer_number)
50
- add_package(xml)
51
- add_services(xml)
52
- add_shipper(xml)
53
- add_recipient(xml)
54
- end
55
-
56
- def add_shipper(xml)
57
- xml.send(:"origin-postal-code", @shipper[:postal_code])
58
- end
59
-
60
- def add_recipient(xml)
61
- xml.destination {
62
- add_destination(xml)
63
- }
64
- end
65
-
66
- def add_destination(xml)
67
- if @recipient[:country_code] == "CA"
68
- xml.domestic {
69
- xml.send(:"postal-code", @recipient[:postal_code])
70
- }
71
- elsif @recipient[:country_code] == "US"
72
- xml.send(:"united-states") {
73
- xml.send(:"zip-code", @recipient[:postal_code])
74
- }
75
- else
76
- xml.international {
77
- xml.send(:"country-code", @recipient[:country_code])
78
- }
79
- end
80
- end
81
-
82
- def add_services(xml)
83
- if @service_type
84
- xml.services {
85
- xml.send(:"service-code", @service_type)
86
- }
87
- end
88
- end
89
-
90
- def success?(response)
91
- response[:price_quotes]
92
- end
93
-
94
- end
95
- end
96
- end
@@ -1,68 +0,0 @@
1
- module CanadaPost
2
- class Shipment
3
-
4
- def initialize(options={})
5
- @credentials = Credentials.new(options)
6
- end
7
-
8
- def create(options = {})
9
- Request::Shipping.new(@credentials, options).process_request
10
- end
11
-
12
- def get_price(shipping_id)
13
- Request::Shipping.new(@credentials).get_price(shipping_id)
14
- end
15
-
16
- def get_label(label_url)
17
- Request::Shipping.new(@credentials).get_label(label_url)
18
- end
19
-
20
- def get_manifest(url)
21
- Request::Manifest.new(@credentials).get_manifest(url)
22
- end
23
-
24
- def registration_token
25
- Request::Registration.new(@credentials).get_token
26
- end
27
-
28
- def get_merchant_info(token)
29
- Request::Registration.new(@credentials).merchant_info(token)
30
- end
31
-
32
- def get_artifact(url)
33
- manifest = Request::Manifest.new(@credentials).get_manifest(url)
34
- if manifest[:errors].present?
35
- return {
36
- status: false,
37
- error: manifest[:errors]
38
- }
39
- else
40
- artifact_link = get_artifact_link(manifest[:manifest])
41
- artifact = Request::Manifest.new(@credentials).get_artifact(artifact_link)
42
- return {
43
- status: true,
44
- artifact: artifact
45
- }
46
- end
47
- end
48
-
49
- def get_artifact_link(manifest)
50
- links = manifest[:links]
51
- if links.present?
52
- links[:link].each do |link|
53
- if link[:rel] == 'artifact'
54
- return link[:href]
55
- end
56
- end
57
- end
58
- end
59
-
60
- def details(shipping_id)
61
- Request::Shipping.new(@credentials).details(shipping_id)
62
- end
63
-
64
- def rate(options={})
65
- Request::Rate.new(@credentials, options).process_request
66
- end
67
- end
68
- end