Class: CanadaPost::Request::Registration

Inherits:
Base
  • Object
show all
Defined in:
lib/canada_post/request/registration.rb

Constant Summary

Constants inherited from Base

Base::OPTION_CODES, Base::PRODUCTION_URL, Base::SERVICE_CODES, Base::TEST_CONTRACT_ID, Base::TEST_URL

Instance Method Summary collapse

Methods inherited from Base

#build_xml, #client, #parse_response, #process_request, #process_response, #sanitize_response_keys

Constructor Details

#initialize(credentials) ⇒ Registration

Returns a new instance of Registration.



5
6
7
8
# File 'lib/canada_post/request/registration.rb', line 5

def initialize(credentials)
  @credentials = credentials
  super(credentials)
end

Instance Method Details

#get_tokenObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/canada_post/request/registration.rb', line 10

def get_token
  api_response = self.class.post(
    api_url,
    headers: api_header,
    basic_auth: @authorization
  )
  shipping_response = process_response(api_response)
  if shipping_response[:token].present?
    shipping_response[:token]
  else
    shipping_response
  end
end

#merchant_info(token) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/canada_post/request/registration.rb', line 24

def merchant_info(token)
  merchant_url = api_url + "/#{token}"
  api_response = self.class.get(
    merchant_url,
    headers: api_header,
    basic_auth: @authorization
  )
  process_response(api_response)
end