Class: Canadapost
- Inherits:
-
Object
- Object
- Canadapost
- Defined in:
- lib/canadapost.rb
Overview
CanadaPost gem for use with Canada Post REST API
Instance Attribute Summary collapse
-
#accept_header ⇒ Object
Returns the value of attribute accept_header.
-
#auth ⇒ Object
Returns the value of attribute auth.
-
#content_type_header ⇒ Object
Returns the value of attribute content_type_header.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#customer_number ⇒ Object
Returns the value of attribute customer_number.
-
#development ⇒ Object
Returns the value of attribute development.
-
#dimensions ⇒ Object
Returns the value of attribute dimensions.
-
#origin_postal_code ⇒ Object
Returns the value of attribute origin_postal_code.
-
#password ⇒ Object
Returns the value of attribute password.
-
#response ⇒ Object
Returns the value of attribute response.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#get_rates(params = {}) ⇒ Object
Hash a hash of services.
-
#initialize(params = {}) ⇒ Canadapost
constructor
A new instance of Canadapost.
Constructor Details
#initialize(params = {}) ⇒ Canadapost
Returns a new instance of Canadapost.
22 23 24 25 26 27 28 |
# File 'lib/canadapost.rb', line 22 def initialize(params = {}) @username = params[:username] @password = params[:password] @development = params[:development] @customer_number = params[:customer_number] @auth = { username: username, password: password } end |
Instance Attribute Details
#accept_header ⇒ Object
Returns the value of attribute accept_header.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def accept_header @accept_header end |
#auth ⇒ Object
Returns the value of attribute auth.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def auth @auth end |
#content_type_header ⇒ Object
Returns the value of attribute content_type_header.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def content_type_header @content_type_header end |
#customer ⇒ Object
Returns the value of attribute customer.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def customer @customer end |
#customer_number ⇒ Object
Returns the value of attribute customer_number.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def customer_number @customer_number end |
#development ⇒ Object
Returns the value of attribute development.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def development @development end |
#dimensions ⇒ Object
Returns the value of attribute dimensions.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def dimensions @dimensions end |
#origin_postal_code ⇒ Object
Returns the value of attribute origin_postal_code.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def origin_postal_code @origin_postal_code end |
#password ⇒ Object
Returns the value of attribute password.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def password @password end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def response @response end |
#username ⇒ Object
Returns the value of attribute username.
3 4 5 |
# File 'lib/canadapost.rb', line 3 def username @username end |
Instance Method Details
#get_rates(params = {}) ⇒ Object
Returns Hash a hash of services.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/canadapost.rb', line 77 def get_rates(params = {}) self.origin_postal_code = params[:origin_postal_code].gsub(/\s+/, "") if params[:origin_postal_code].present? self.customer = params[:customer] if params[:customer].present? self.dimensions = params[:dimensions] if params[:dimensions].present? self.content_type_header = self.accept_header = 'application/vnd.cpc.ship.rate-v2+xml' begin do_request(get_rates_xml, get_rates_url) services = results[:price_quotes][:price_quote] services = services.map(&:deep_symbolize_keys!) return services rescue return nil end return services end |