canada-post-api 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39a73ea816a86070982aa8d0a11551e0a480d036
4
- data.tar.gz: 0d2a9fc8aa128652d992f6de3298457dc61666e7
3
+ metadata.gz: 88e2d29bd83c996e184b95fc0fca6a7d25ac8323
4
+ data.tar.gz: 0c0268d229f21fd51f99f958bd914c193db09ace
5
5
  SHA512:
6
- metadata.gz: 98c1ff9ca52cf3bdb3c3faa4896a40894a6c8f7be9edfaa8ba206c23fc65c93429949de8e7de0940c058b2b9542a0e9d161a635b4cc93ae12947f9f9de1dfbc0
7
- data.tar.gz: f2db6e397599d78b4eb7dd63edd4c5689834c36bbbc53ce28cfb03fe25009ce836fad42942096f6e84e5227a726ed8de9e7b4e3a5e54c4581ef10363da79c34f
6
+ metadata.gz: 25d7fa690c592963af7d1b4b8354330c140e65589c82fcab66d22b2e4047e01c36fe5d5545bd7a8817c48d696d8f1a20f8634502451abdde5bd389668e40f953
7
+ data.tar.gz: 990b8e3b095722ff6c048dc8039dc9bf6afc04c8c6ef8a61e27f392d50ef67ed1c9f153b57ca678742fe50ba88699d0e6251e188c6e62810a9ccefb8bcebf278
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # CanadaPost REST API V3 Wrapper
2
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
3
+ A Ruby wrapper for the CanadaPost REST API. Based extensively off the [fedex](https://github.com/jazminschroeder/fedex) gem.
4
+ Thanks to [jazminschroeder](https://github.com/jazminschroeder) and all contributors who helped make that a gem worth recreating for the Canada Post API
5
+
6
+ For more info see the [Official Canada Post Developer Docs](https://www.canadapost.ca/cpotools/apps/drc/home)
7
+
8
+ Current implementation for the rates endpoint only, feel free to let me know if there are other services you would like to see included or make a PR
5
9
 
6
10
  ## Installation
7
11
 
@@ -21,7 +25,97 @@ Or install it yourself as:
21
25
 
22
26
  ## Usage
23
27
 
24
- TODO: Write usage instructions here
28
+ Require the gem:
29
+
30
+ ```ruby
31
+ require 'canada_post'
32
+ ```
33
+
34
+ Create a service:
35
+
36
+ ```ruby
37
+ canada_post_service = CanadaPost::Shipment.new( username: 'xxxx',
38
+ password: 'xxxx',
39
+ customer_number: 'xxxx',
40
+ mode: 'development' )
41
+ # mode can be 'development' or 'production'
42
+ ```
43
+
44
+ ### Define shipper:
45
+
46
+ ```ruby
47
+ shipper = { postal_code: 'M5X1B8',
48
+ country_code: 'CA' }
49
+ # Post Code is required for US and CA shipments, not for International Shipments
50
+ ```
51
+
52
+ ### Define recipient:
53
+
54
+ ```ruby
55
+ recipient = { postal_code: 'M5R1C6',
56
+ country_code: 'CA' }
57
+ ```
58
+
59
+ ### Define package:
60
+
61
+ ```ruby
62
+ package = { weight: { value: 1, units: 'KG' },
63
+ dimensions: { length: 25, width: 15, height: 10, units: 'CM' } }
64
+ # weight is the only requirement for your package, Canada Post only accepts KG and CM for the time being
65
+ ```
66
+
67
+ ### To get service codes:
68
+ see [Canada Post Rating API docs](https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/rating/getrates/default.jsf) for service code descriptions
69
+ ```ruby
70
+ $ CanadaPost::Request::Rate::SERVICE_CODES
71
+ $ => ["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"]
72
+ ```
73
+
74
+ ## Get Rates:
75
+
76
+ ```ruby
77
+ $ rates = canada_post_service.rate( shipper: shipper,
78
+ recipient: recipient,
79
+ package: package)
80
+ ```
81
+
82
+ Not specifying a service type will return an array of all available rates
83
+
84
+ ```ruby
85
+ # complete response
86
+ $ [#<CanadaPost::Rate:0x007fd783f42a88 @service_type="Expedited Parcel", @service_code="DOM.EP", @total_net_charge="8.76", @total_base_charge="7.77", @gst_taxes="0.00", @pst_taxes="0.00", @hst_taxes="1.01", @transit_time="1">, #<CanadaPost::Rate:0x007fd783f42a60 @service_type="Priority", @service_code="DOM.PC", @total_net_charge="19.14", @total_base_charge="16.21", @gst_taxes="0.00", @pst_taxes="0.00", @hst_taxes="2.20", @transit_time="1">, #<CanadaPost::Rate:0x007fd783f42a10 @service_type="Regular Parcel", @service_code="DOM.RP", @total_net_charge="8.76", @total_base_charge="7.77", @gst_taxes="0.00", @pst_taxes="0.00", @hst_taxes="1.01", @transit_time="2">, #<CanadaPost::Rate:0x007fd783f429e8 @service_type="Xpresspost", @service_code="DOM.XP", @total_net_charge="11.31", @total_base_charge="9.58", @gst_taxes="0.00", @pst_taxes="0.00", @hst_taxes="1.30", @transit_time="1">]
87
+ ```
88
+
89
+ Specifying the service type will return one result
90
+
91
+ ```ruby
92
+ $ service_type = 'DOM.EP'
93
+ $ rates = canada_post_service.rate( shipper: shipper,
94
+ recipient: recipient,
95
+ package: package,
96
+ service_type: service_type)
97
+ # complete response
98
+ $ [
99
+ #<CanadaPost::Rate:0x007fd783fea238
100
+ @service_type="Expedited Parcel",
101
+ @service_code="DOM.EP",
102
+ @total_net_charge="8.76",
103
+ @total_base_charge="7.77",
104
+ @gst_taxes="0.00",
105
+ @pst_taxes="0.00",
106
+ @hst_taxes="1.01",
107
+ @transit_time="1">
108
+ ]
109
+ ```
110
+
111
+ Your final amount will be under `total_net_charge`:
112
+
113
+ ```ruby
114
+ $ rates.first.total_net_charge => '8.76' # all monetary values are CAD
115
+ ```
116
+
117
+ This is still a work in progress but feel free to contribute if it will benefit you!
118
+
25
119
 
26
120
  ## Contributing
27
121
 
@@ -18,9 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "httparty", ">= 0.13.3"
22
- spec.add_dependency "nokogiri", ">= 1.6.6"
23
- spec.add_dependency "activesupport"
21
+ spec.add_dependency "httparty"
22
+ spec.add_dependency "nokogiri"
24
23
 
25
24
  spec.add_development_dependency "bundler", "~> 1.7"
26
25
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,3 +1,3 @@
1
1
  module CanadaPost
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canada-post-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JONBRWN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-09 00:00:00.000000000 Z
11
+ date: 2015-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -16,30 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.13.3
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.13.3
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: 1.6.6
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: 1.6.6
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - '>='