Class: Io::Flow::V0::Clients::Addresses

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Addresses

Returns a new instance of Addresses.



5164
5165
5166
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5164

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#get(incoming = {}) ⇒ Object

Geolocates the request based on the provided parameters, returning a list of potential matching addresses.



5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5170

def get(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :address => (x = opts.delete(:address); x.nil? ? nil : HttpClient::Preconditions.assert_class('address', x, String)),
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String)),
    :country => (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String)),
    :postal_prefix => (x = opts.delete(:postal_prefix); x.nil? ? nil : HttpClient::Preconditions.assert_class('postal_prefix', x, String))
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/addresses").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Address.new(x) }
end

#post_verifications(address) ⇒ Object



5182
5183
5184
5185
5186
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5182

def post_verifications(address)
  (x = address; x.is_a?(::Io::Flow::V0::Models::Address) ? x : ::Io::Flow::V0::Models::Address.new(x))
  r = @client.request("/addresses/verifications").with_json(address.to_json).post
  ::Io::Flow::V0::Models::AddressVerification.new(r)
end