Sha256: 6abf51b80423f48282291ec8720630ff66dfb017b76ab4e20191641d4e30d59a

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module EasyPost
  class Address < Resource

    def self.create_and_verify(params={}, carrier=nil, api_key=nil)
      wrapped_params = {}
      wrapped_params[self.class_name().to_sym] = params
      wrapped_params[:carrier] = carrier
      response, api_key = EasyPost.request(:post, url + '/create_and_verify', api_key, wrapped_params)

      if response.has_key?(:address)
        if response.has_key?(:message)
          response[:address][:message] = response[:message]
        end
        verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
        return verified_address
      else
        raise Error.new("Unable to verify address.")
      end
    end

    def verify(params={}, carrier=nil)
      response, api_key = EasyPost.request(:get, url + '/verify?carrier=' + String(carrier), @api_key, params)

      if response.has_key?(:address)
        if response.has_key?(:message)
          response[:address][:message] = response[:message]
        end
        verified_address = EasyPost::Util::convert_to_easypost_object(response[:address], api_key)
        return verified_address
      else
        raise Error.new("Unable to verify address.")
      end

      return self
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
easypost-2.1.0 lib/easypost/address.rb
easypost-2.0.13 lib/easypost/address.rb