Class: EasyPost::Address
- Inherits:
-
Resource
- Object
- EasyPostObject
- Resource
- EasyPost::Address
- Defined in:
- lib/easypost/address.rb
Overview
Address objects are used to represent people, places, and organizations in a number of contexts.
Instance Attribute Summary collapse
-
#message ⇒ Object
Backwards compatibility.
Attributes inherited from EasyPostObject
#api_key, #name, #parent, #unsaved_values
Class Method Summary collapse
-
.create(params = {}, api_key = nil) ⇒ Object
Create an Address.
-
.create_and_verify(params = {}, carrier = nil, api_key = nil) ⇒ Object
Create and verify an Address in one call.
Instance Method Summary collapse
-
#verify ⇒ Object
Verify an Address.
Methods inherited from Resource
all, class_name, #delete, each, #refresh, retrieve, #save, url, #url
Methods inherited from EasyPostObject
#[], #[]=, #as_json, construct_from, #deconstruct_keys, #each, #id, #id=, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values
Constructor Details
This class inherits a constructor from EasyPost::EasyPostObject
Instance Attribute Details
#message ⇒ Object
Backwards compatibility
5 6 7 |
# File 'lib/easypost/address.rb', line 5 def end |
Class Method Details
.create(params = {}, api_key = nil) ⇒ Object
Create an Address.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/easypost/address.rb', line 8 def self.create(params = {}, api_key = nil) url = self.url address = params.reject { |k, _| [:verify, :verify_strict].include?(k) } if params[:verify] || params[:verify_strict] verify = params[:verify] || [] verify_strict = params[:verify_strict] || [] url += '?' verify.each do |verification| url += "verify[]=#{verification}&" end verify_strict.each do |verification| url += "verify_strict[]=#{verification}&" end end response = EasyPost.make_request(:post, url, api_key, { address: address }) EasyPost::Util.convert_to_easypost_object(response, api_key) end |
.create_and_verify(params = {}, carrier = nil, api_key = nil) ⇒ Object
Create and verify an Address in one call.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/easypost/address.rb', line 31 def self.create_and_verify(params = {}, carrier = nil, api_key = nil) wrapped_params = {} wrapped_params[class_name.to_sym] = params wrapped_params[:carrier] = carrier response = EasyPost.make_request(:post, "#{url}/create_and_verify", api_key, wrapped_params) raise EasyPost::Error.new('Unable to verify address.') unless response.key?('address') if response.key?('message') response['address']['message'] = response['message'] end EasyPost::Util.convert_to_easypost_object(response['address'], api_key) end |
Instance Method Details
#verify ⇒ Object
Verify an Address.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/easypost/address.rb', line 47 def verify begin response = EasyPost.make_request(:get, "#{url}/verify", @api_key) rescue StandardError raise EasyPost::Error.new('Unable to verify address.') end raise EasyPost::Error.new('Unable to verify address.') unless response.key?('address') EasyPost::Util.convert_to_easypost_object(response['address'], api_key) end |