canada-post-api 0.0.1a
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 +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/canada-post-api.gemspec +31 -0
- data/lib/canada_post/credentials.rb +17 -0
- data/lib/canada_post/helpers.rb +15 -0
- data/lib/canada_post/rate.rb +20 -0
- data/lib/canada_post/request/base.rb +109 -0
- data/lib/canada_post/request/rate.rb +101 -0
- data/lib/canada_post/shipment.rb +11 -0
- data/lib/canada_post/version.rb +3 -0
- data/lib/canada_post.rb +11 -0
- data/spec/config/canada_post_credentials.example.yml +11 -0
- data/spec/rate_spec.rb +75 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/credentials.rb +16 -0
- data/spec/support/vcr.rb +15 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44c879e058f9e59d7f547cba649787eabae910a2
|
4
|
+
data.tar.gz: 5539d45d2c97d58d11034b14ecf4bab51b1a94cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd8687d20939433e4321273a47e7595d165c5756ccefe58cd44ec685c5d57bd18ca0e6e49545c70e7b1b31d8bd7ede6007c01cb1723c8a2c0b3c7746ed79d2e0
|
7
|
+
data.tar.gz: 01c1fb9bbcb963c4b4a17aa9cc41c9ffe9f7eabc6795306c9a4c7bdafce125133d16c995d90b330754487cf92accbef018aaeecbb2bd9a17fcf87a999a2ca39c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 JONBRWN
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# CanadaPost REST API V3 Wrapper
|
2
|
+
|
3
|
+
A Ruby wrapper for the CanadaPost REST API. Based extensively off the [fedex](https://github.com/jazminschroeder/fedex) gem
|
4
|
+
Current implementation for the rates endpoint
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'canada-post-api'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install canada-post-api
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/[my-github-username]/canada-post-api/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'canada_post/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "canada-post-api"
|
8
|
+
spec.version = CanadaPost::VERSION
|
9
|
+
spec.authors = ["JONBRWN"]
|
10
|
+
spec.email = ["jonathanbrown.a@gmail.com"]
|
11
|
+
spec.summary = %q{Canada Post API}
|
12
|
+
spec.description = %q{Ruby wrapper for the Canada Post API V3}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty"
|
22
|
+
spec.add_dependency "nokogiri"
|
23
|
+
spec.add_dependency "activesupport"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
# TESTING
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "webmock"
|
30
|
+
spec.add_development_dependency "vcr"
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CanadaPost
|
2
|
+
class Credentials
|
3
|
+
include Helpers
|
4
|
+
|
5
|
+
attr_reader :username, :password, :customer_number, :mode
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
requires!(options, :username, :password, :customer_number, :mode)
|
9
|
+
@username = options[:username]
|
10
|
+
@password = options[:password]
|
11
|
+
@customer_number = options[:customer_number]
|
12
|
+
@mode = options[:mode]
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CanadaPost
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
private
|
5
|
+
# Helper method to validate required fields
|
6
|
+
def requires!(hash, *params)
|
7
|
+
params.each { |param| raise RateError, "Missing Required Parameter #{param}" if hash[param].nil? }
|
8
|
+
end
|
9
|
+
|
10
|
+
def underscorize(key) #:nodoc:
|
11
|
+
key.to_s.sub(/^(v[0-9]+|ns):/, "").gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module CanadaPost
|
2
|
+
class Rate
|
3
|
+
|
4
|
+
attr_accessor :service_type, :service_code, :transit_time, :total_net_charge, :rate_type, :total_base_charge
|
5
|
+
def initialize(options={})
|
6
|
+
@service_type = options[:service_name]
|
7
|
+
@service_code = options[:service_code]
|
8
|
+
@total_net_charge = options[:price_details][:due]
|
9
|
+
@total_base_charge = options[:price_details][:base]
|
10
|
+
@gst_taxes = options[:price_details][:taxes][:gst]
|
11
|
+
@pst_taxes = options[:price_details][:taxes][:pst]
|
12
|
+
@hst_taxes = options[:price_details][:taxes][:hst]
|
13
|
+
@transit_time = options[:service_standard][:expected_transit_time]
|
14
|
+
end
|
15
|
+
|
16
|
+
def total_taxes
|
17
|
+
(@gst_taxes.to_f + @pst_taxes.to_f + @hst_taxes.to_f).to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'active_support/core_ext/hash'
|
4
|
+
require 'canada_post/helpers'
|
5
|
+
require 'canada_post/rate'
|
6
|
+
|
7
|
+
module CanadaPost
|
8
|
+
module Request
|
9
|
+
class Base
|
10
|
+
include Helpers
|
11
|
+
include HTTParty
|
12
|
+
|
13
|
+
# CanadaPost API Test URL
|
14
|
+
TEST_URL = "https://ct.soa-gw.canadapost.ca"
|
15
|
+
|
16
|
+
# CanadaPost API Production URL
|
17
|
+
PRODUCTION_URL = "https://https://soa-gw.canadapost.ca"
|
18
|
+
|
19
|
+
# List of available Option Codes
|
20
|
+
# SO - Signature
|
21
|
+
# COV - Coverage (requires qualifier)
|
22
|
+
# COD - COD (requires qualifier)
|
23
|
+
# PA18 - Proof of Age Required - 18
|
24
|
+
# PA19 - Proof of Age Required - 19
|
25
|
+
# HFP - Card for pickup
|
26
|
+
# DNS - Do not safe drop
|
27
|
+
# LAD - Leave at door - do not card
|
28
|
+
OPTION_CODES = ["SO", "COV", "COD", "PA18", "PA19", "HFP", "DNS", "LAD"]
|
29
|
+
|
30
|
+
#List of available Service Codes
|
31
|
+
# DOM.RP - Regular Parcel
|
32
|
+
# DOM.EP - Expedited Parcel
|
33
|
+
# DOM.XP - Xpresspost
|
34
|
+
# DOM.XP.CERT - Xpresspost Certified
|
35
|
+
# DOM.PC - Priority
|
36
|
+
# DOM.DT - Delivered Tonight
|
37
|
+
# DOM.LIB - Library Books
|
38
|
+
# USA.EP - Expedited Parcel USA
|
39
|
+
# USA.PW.ENV - Priority Worldwide Envelope USA
|
40
|
+
# USA.PW.PAK - Priority Worldwide pak USA
|
41
|
+
# USA.PW.Parcel - Priority Worldwide Parcel USA
|
42
|
+
# USA.SP.AIR - Small Packet USA Air
|
43
|
+
# USA.TP - Tracked Package - USA
|
44
|
+
# USA.TP.LVM - Tracked Package - USA (LVM) (large volume mailers)
|
45
|
+
# USA.XP - Xpresspost USA
|
46
|
+
# INT.XP - Xpresspost international
|
47
|
+
# INT.IP.AIR - International Parcel Air
|
48
|
+
# INT.IP.SURF - International Parcel Surface
|
49
|
+
# INT.PW.ENV - Priority Worldwide Envelope Int'l
|
50
|
+
# INT.PW.PAK - Priority Worldwide pak Int'l
|
51
|
+
# INT.PW.PARCEL - Priority Worldwide Parcel Int'l
|
52
|
+
# INT.SP.AIR - Small Packet International Air
|
53
|
+
# INT.SP.SURF - Small Packet International Surface
|
54
|
+
# INT.TP - Tracked Package - International
|
55
|
+
SERVICE_CODES = ["DOM.RP", "DOM.EP", "DOM.XP", "DOM.XP.CERT", "DOM.PC.CERT", "DOM.PC", "DOM.DT", "DOM.LIB", "USA.EP", "USA.PW.ENV", "USA.PW.PAK", "USA.PW.PARCEL", "USA.SP.AIR", "USA.TP", "USA.TP.LVM", "USA.XP", "INT.XP", "INT.IP.AIR", "INT.IP.SURF", "INT.PW.ENV", "INT.PW.PAK", "INT.PW.PARCEL", "INT.SP.AIR", "INT.SP.SURF", "INT.TP"]
|
56
|
+
|
57
|
+
def initialize(credentials, options={})
|
58
|
+
requires!(options, :shipper, :recipient, :package)
|
59
|
+
@credentials = credentials
|
60
|
+
@shipper, @recipient, @package, @service_type = options[:shipper], options[:recipient], options[:package], options[:service_type]
|
61
|
+
@authorization = { username: @credentials.username, password: @credentials.password }
|
62
|
+
@customer_number = @credentials.customer_number
|
63
|
+
end
|
64
|
+
|
65
|
+
def process_request
|
66
|
+
raise NotImplementedError, "Override #process_request in subclass"
|
67
|
+
end
|
68
|
+
|
69
|
+
def api_url
|
70
|
+
@credentials.mode == "production" ? PRODUCTION_URL : TEST_URL
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_xml
|
74
|
+
raise NotImplementedError, "Override #build_xml in subclass"
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_package(xml)
|
78
|
+
xml.send(:"parcel-characteristics") {
|
79
|
+
xml.weight @package[:weight][:value]
|
80
|
+
if @package[:dimensions]
|
81
|
+
xml.dimensions {
|
82
|
+
xml.height @package[:dimensions][:height].round(1)
|
83
|
+
xml.width @package[:dimensions][:width].round(1)
|
84
|
+
xml.length @package[:dimensions][:length].round(1)
|
85
|
+
}
|
86
|
+
end
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
# Parse response, convert keys to underscore symbols
|
91
|
+
def parse_response(response)
|
92
|
+
response = Hash.from_xml( response.parsed_response.gsub("\n", "") ) if response.parsed_response.is_a? String
|
93
|
+
response = sanitize_response_keys(response)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Recursively sanitizes the response object by cleaning up any hash keys.
|
97
|
+
def sanitize_response_keys(response)
|
98
|
+
if response.is_a?(Hash)
|
99
|
+
response.inject({}) { |result, (key, value)| result[underscorize(key).to_sym] = sanitize_response_keys(value); result }
|
100
|
+
elsif response.is_a?(Array)
|
101
|
+
response.collect { |result| sanitize_response_keys(result) }
|
102
|
+
else
|
103
|
+
response
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module CanadaPost
|
2
|
+
module Request
|
3
|
+
class Rate < Base
|
4
|
+
# Sends post request to CanadaPost API and parse the response, a Rate object is created if the response is successful
|
5
|
+
def process_request
|
6
|
+
api_response = self.class.post(api_url,
|
7
|
+
body: build_xml,
|
8
|
+
headers: rate_headers,
|
9
|
+
basic_auth: @authorization
|
10
|
+
)
|
11
|
+
response = parse_response(api_response)
|
12
|
+
if success?(response)
|
13
|
+
rate_reply_details = response[:price_quotes][:price_quote] || []
|
14
|
+
rate_reply_details = [rate_reply_details] if rate_reply_details.is_a? Hash
|
15
|
+
rate_reply_details.map do |rate_reply|
|
16
|
+
CanadaPost::Rate.new(rate_reply)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
error_message = if response[:messages]
|
20
|
+
response[:messages][:message][:description]
|
21
|
+
else
|
22
|
+
'api_response.response'
|
23
|
+
end
|
24
|
+
raise RateError, error_message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def api_url
|
31
|
+
api_url = @credentials.mode == "production" ? PRODUCTION_URL : TEST_URL
|
32
|
+
api_url += "/rs/ship/price"
|
33
|
+
end
|
34
|
+
|
35
|
+
def rate_headers
|
36
|
+
{
|
37
|
+
'Content-type' => 'application/vnd.cpc.ship.rate-v3+xml',
|
38
|
+
'Accept' => 'application/vnd.cpc.ship.rate-v3+xml'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_xml
|
43
|
+
ns = "http://www.canadapost.ca/ws/ship/rate-v3"
|
44
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
45
|
+
xml.send(:"mailing-scenario", xmlns: ns) {
|
46
|
+
add_requested_shipment(xml)
|
47
|
+
|
48
|
+
}
|
49
|
+
end
|
50
|
+
builder.doc.root.to_xml
|
51
|
+
end
|
52
|
+
|
53
|
+
def add_requested_shipment(xml)
|
54
|
+
xml.send(:"customer-number", @customer_number)
|
55
|
+
add_package(xml)
|
56
|
+
add_services(xml)
|
57
|
+
add_shipper(xml)
|
58
|
+
add_recipient(xml)
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_shipper(xml)
|
62
|
+
xml.send(:"origin-postal-code", @shipper[:postal_code])
|
63
|
+
end
|
64
|
+
|
65
|
+
def add_recipient(xml)
|
66
|
+
xml.destination {
|
67
|
+
add_destination(xml)
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_destination(xml)
|
72
|
+
if @recipient[:country_code] == "CA"
|
73
|
+
xml.domestic {
|
74
|
+
xml.send(:"postal-code", @recipient[:postal_code])
|
75
|
+
}
|
76
|
+
elsif @recipient[:country_code] == "US"
|
77
|
+
xml.send(:"united-states") {
|
78
|
+
xml.send(:"zip-code", @recipient[:postal_code])
|
79
|
+
}
|
80
|
+
else
|
81
|
+
xml.international {
|
82
|
+
xml.send(:"country-code", @recipient[:country_code])
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_services(xml)
|
88
|
+
if @service_type
|
89
|
+
xml.services {
|
90
|
+
xml.send(:"service-code", @service_type)
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def success?(response)
|
96
|
+
response[:price_quotes]
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/canada_post.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "canada_post/version"
|
2
|
+
require "canada_post/request/base"
|
3
|
+
require "canada_post/request/rate"
|
4
|
+
require "canada_post/shipment"
|
5
|
+
require "canada_post/rate"
|
6
|
+
require "canada_post/credentials"
|
7
|
+
|
8
|
+
module CanadaPost
|
9
|
+
#Exceptions: CandaPost::RateError
|
10
|
+
class RateError < StandardError; end
|
11
|
+
end
|
data/spec/rate_spec.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'canada_post'
|
3
|
+
require 'canada_post/shipment'
|
4
|
+
|
5
|
+
describe CanadaPost::Shipment do
|
6
|
+
|
7
|
+
context 'missing required parameters' do
|
8
|
+
it 'does raise Rate exception' do
|
9
|
+
expect{ CanadaPost::Shipment.new }.to raise_error(CanadaPost::RateError)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'required parameters present' do
|
14
|
+
it 'does create a valid instance' do
|
15
|
+
expect( CanadaPost::Shipment.new(canada_post_credentials) ).to be_an_instance_of(CanadaPost::Shipment)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'rate service' do
|
20
|
+
let(:canada_post) { CanadaPost::Shipment.new(canada_post_credentials) }
|
21
|
+
let(:simple_package) { { weight: {value: 2, units: "KG"} } }
|
22
|
+
let(:complex_package) { { weight: {value: 2, units: "KG"}, dimension: {length: 25, width: 15,height: 10, units: "CM"} } }
|
23
|
+
let(:shipper) { { postal_code: "M5X1B8", country_code: "CA" } }
|
24
|
+
let(:domestic_recipient) { { postal_code: "M5R1C6", country_code: "CA" } }
|
25
|
+
let(:us_recipient) { { postal_code: "10012", country_code: "US", residential: true } }
|
26
|
+
let(:intl_recipient) { { country_code: "GB" } }
|
27
|
+
|
28
|
+
context 'domestic shipment', :vcr do
|
29
|
+
let(:rates) { canada_post.rate(shipper: shipper, recipient: domestic_recipient, package: simple_package) }
|
30
|
+
it 'does return a rate' do
|
31
|
+
expect(rates.first).to be_an_instance_of(CanadaPost::Rate)
|
32
|
+
end
|
33
|
+
it 'does return a transit time' do
|
34
|
+
expect(rates.first.transit_time).not_to be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with service type specified', :vcr do
|
39
|
+
let(:rates) { canada_post.rate(shipper: shipper, recipient: domestic_recipient, package: simple_package, service_type: "DOM.RP") }
|
40
|
+
|
41
|
+
it 'returns a single rate' do
|
42
|
+
expect(rates.count).to eq 1
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'has a service_type attribute' do
|
46
|
+
expect(rates.first.service_type).to eq("Regular Parcel")
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with no service type specified', :vcr do
|
52
|
+
let(:rates) { canada_post.rate(shipper: shipper, recipient: domestic_recipient, package: simple_package) }
|
53
|
+
it 'returns multiple rates' do
|
54
|
+
expect(rates.count).to be >= 1
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'each rate' do
|
58
|
+
it 'has service type attribute' do
|
59
|
+
expect(rates.first).to respond_to(:service_type)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when there are no valid services available', :vcr do
|
65
|
+
let(:bad_shipper) { shipper.merge(postal_code: '0') }
|
66
|
+
let(:rates) { canada_post.rate(shipper: bad_shipper, recipient: domestic_recipient, package: simple_package) }
|
67
|
+
|
68
|
+
it 'does raise Rate exception' do
|
69
|
+
expect{ rates }.to raise_error(CanadaPost::RateError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'canada_post'
|
3
|
+
require 'support/vcr'
|
4
|
+
require 'support/credentials'
|
5
|
+
|
6
|
+
RSpec.configure do |c|
|
7
|
+
c.filter_run_excluding :production unless canada_post_production_credentials
|
8
|
+
c.expect_with :rspec do |expect_config|
|
9
|
+
expect_config.syntax = :expect
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
def canada_post_credentials
|
2
|
+
@canada_post_credentials ||= credentials["development"]
|
3
|
+
end
|
4
|
+
|
5
|
+
def canada_post_production_credentials
|
6
|
+
@canada_post_production_credentials ||= credentials["production"]
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def credentials
|
12
|
+
@credentials ||= begin
|
13
|
+
YAML.load_file("#{File.dirname(__FILE__)}/../config/canada_post_credentials.yml")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
|
3
|
+
VCR.configure do |c|
|
4
|
+
c.cassette_library_dir = File.expand_path('../../vcr', __FILE__)
|
5
|
+
c.hook_into :webmock
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
RSpec.configure do |c|
|
10
|
+
c.include CanadaPost::Helpers
|
11
|
+
c.around(:each, :vcr) do |example|
|
12
|
+
name = underscorize(example.metadata[:full_description].split(/\s+/, 2).join("/")).gsub(/[^\w\/]+/, "_")
|
13
|
+
VCR.use_cassette(name) { example.call }
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: canada-post-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1a
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JONBRWN
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: vcr
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Ruby wrapper for the Canada Post API V3
|
126
|
+
email:
|
127
|
+
- jonathanbrown.a@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .gitignore
|
133
|
+
- Gemfile
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- canada-post-api.gemspec
|
138
|
+
- lib/canada_post.rb
|
139
|
+
- lib/canada_post/credentials.rb
|
140
|
+
- lib/canada_post/helpers.rb
|
141
|
+
- lib/canada_post/rate.rb
|
142
|
+
- lib/canada_post/request/base.rb
|
143
|
+
- lib/canada_post/request/rate.rb
|
144
|
+
- lib/canada_post/shipment.rb
|
145
|
+
- lib/canada_post/version.rb
|
146
|
+
- spec/config/canada_post_credentials.example.yml
|
147
|
+
- spec/rate_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/support/credentials.rb
|
150
|
+
- spec/support/vcr.rb
|
151
|
+
homepage: ''
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - '>'
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 1.3.1
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.2.2
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Canada Post API
|
175
|
+
test_files:
|
176
|
+
- spec/config/canada_post_credentials.example.yml
|
177
|
+
- spec/rate_spec.rb
|
178
|
+
- spec/spec_helper.rb
|
179
|
+
- spec/support/credentials.rb
|
180
|
+
- spec/support/vcr.rb
|