Sha256: 8cc6acea3d2742d96b60f20e8f13e4a037702532c1200581a1e1ede5f5bb5b92

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

class EasyPost::Services::Address < EasyPost::Services::Service
  MODEL_CLASS = EasyPost::Models::Address

  # Create an address.
  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

    @client.make_request(:post, 'addresses', MODEL_CLASS, params)
  end

  # Create and verify an Address in one call.
  def create_and_verify(params = {})
    wrapped_params = {}
    wrapped_params[:address] = params

    @client.make_request(:post, 'addresses/create_and_verify', MODEL_CLASS, wrapped_params).address
  end

  # Verify an Address.
  def verify(id)
    @client.make_request(:get, "addresses/#{id}/verify", MODEL_CLASS).address
  end

  # Retrieve an Address.
  def retrieve(id)
    @client.make_request(:get, "addresses/#{id}", MODEL_CLASS)
  end

  # Retrieve all Addresses.
  def all(filters = {})
    @client.make_request(:get, 'addresses', MODEL_CLASS, filters)
  end

  # Get the next page of addresses.
  def get_next_page(collection, page_size = nil)
    get_next_page_helper(collection, collection.addresses, 'addresses', MODEL_CLASS, page_size)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
easypost-5.3.0 lib/easypost/services/address.rb
easypost-5.2.0 lib/easypost/services/address.rb
easypost-5.1.1 lib/easypost/services/address.rb
easypost-5.1.0 lib/easypost/services/address.rb
easypost-5.0.1 lib/easypost/services/address.rb
easypost-5.0.0 lib/easypost/services/address.rb