class EasyPost::Services::Address

Constants

MODEL_CLASS

Address objects are used to represent people, places, and organizations in a number of contexts.

Public Instance Methods

all(params = {}) click to toggle source

Retrieve all Addresses.

# File lib/easypost/services/address.rb, line 50
def all(params = {})
  filters = { key: 'addresses' }

  get_all_helper('addresses', MODEL_CLASS, params, filters)
end
create(params = {}) click to toggle source

Create an address.

# File lib/easypost/services/address.rb, line 7
def create(params = {})
  address = params.reject { |k, _| [:verify, :verify_strict].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

  response = @client.make_request(:post, 'addresses', params)

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end
create_and_verify(params = {}) click to toggle source

Create and verify an Address in one call.

# File lib/easypost/services/address.rb, line 26
def create_and_verify(params = {})
  wrapped_params = {}
  wrapped_params[:address] = params

  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) click to toggle source

Get the next page of addresses.

# File lib/easypost/services/address.rb, line 57
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) click to toggle source

Retrieve an Address.

# File lib/easypost/services/address.rb, line 43
def retrieve(id)
  response = @client.make_request(:get, "addresses/#{id}")

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end
verify(id) click to toggle source

Verify an Address.

# File lib/easypost/services/address.rb, line 36
def verify(id)
  response = @client.make_request(:get, "addresses/#{id}/verify")

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS).address
end