Class: EasyPost::Services::Address
- Defined in:
- lib/easypost/services/address.rb
Constant Summary collapse
- MODEL_CLASS =
:nodoc:
EasyPost::Models::Address
Instance Method Summary collapse
-
#all(params = {}) ⇒ Object
Retrieve all Addresses.
-
#create(params = {}) ⇒ Object
Create an address.
-
#create_and_verify(params = {}) ⇒ Object
Create and verify an Address in one call.
-
#get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of addresses.
-
#retrieve(id) ⇒ Object
Retrieve an Address.
-
#verify(id) ⇒ Object
Verify an Address.
Methods inherited from Service
Constructor Details
This class inherits a constructor from EasyPost::Services::Service
Instance Method Details
#all(params = {}) ⇒ Object
Retrieve all Addresses.
59 60 61 62 63 |
# File 'lib/easypost/services/address.rb', line 59 def all(params = {}) filters = { key: 'addresses' } get_all_helper('addresses', MODEL_CLASS, params, filters) end |
#create(params = {}) ⇒ Object
Create an address.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/easypost/services/address.rb', line 7 def create(params = {}) address = params.reject { |k, _| [:verify, :verify_strict, :verify_carrier].include?(k) } wrapped_params = { address: address } if params[:verify] wrapped_params[:verify] = params[:verify] end if params[:verify_strict] wrapped_params[:verify_strict] = params[:verify_strict] end if params[:verify_carrier] wrapped_params[:verify_carrier] = params[:verify_carrier] end response = @client.make_request(:post, 'addresses', params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#create_and_verify(params = {}) ⇒ Object
Create and verify an Address in one call.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/easypost/services/address.rb', line 30 def create_and_verify(params = {}) address = params.reject { |k, _| [:verify_carrier].include?(k) } wrapped_params = { address: address } if params[:verify_carrier] wrapped_params[:verify_carrier] = params[:verify_carrier] end response = @client.make_request(:post, 'addresses/create_and_verify', wrapped_params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS).address end |
#get_next_page(collection, page_size = nil) ⇒ Object
Get the next page of addresses.
66 67 68 69 70 71 72 73 |
# File 'lib/easypost/services/address.rb', line 66 def get_next_page(collection, page_size = nil) raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection) params = { before_id: collection.addresses.last.id } params[:page_size] = page_size unless page_size.nil? all(params) end |
#retrieve(id) ⇒ Object
Retrieve an Address.
52 53 54 55 56 |
# File 'lib/easypost/services/address.rb', line 52 def retrieve(id) response = @client.make_request(:get, "addresses/#{id}") EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#verify(id) ⇒ Object
Verify an Address.
45 46 47 48 49 |
# File 'lib/easypost/services/address.rb', line 45 def verify(id) response = @client.make_request(:get, "addresses/#{id}/verify") EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS).address end |