Class: SmartyStreets::InternationalStreet::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/smartystreets_ruby_sdk/international_street/client.rb

Overview

It is recommended to instantiate this class using ClientBuilder.build_international_street_api_client()

Instance Method Summary collapse

Constructor Details

#initialize(sender, serializer) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/smartystreets_ruby_sdk/international_street/client.rb', line 8

def initialize(sender, serializer)
  @sender = sender
  @serializer = serializer
end

Instance Method Details

#add_parameter(request, key, value) ⇒ Object



60
61
62
# File 'lib/smartystreets_ruby_sdk/international_street/client.rb', line 60

def add_parameter(request, key, value)
  request.parameters[key] = value unless value.nil? or value.empty?
end

#build_request(lookup) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/smartystreets_ruby_sdk/international_street/client.rb', line 40

def build_request(lookup)
  request = SmartyStreets::Request.new

  add_parameter(request, 'input_id', lookup.input_id)
  add_parameter(request, 'country', lookup.country)
  add_parameter(request, 'geocode', lookup.geocode.to_s)
  add_parameter(request, 'language', lookup.language)
  add_parameter(request, 'freeform', lookup.freeform)
  add_parameter(request, 'address1', lookup.address1)
  add_parameter(request, 'address2', lookup.address2)
  add_parameter(request, 'address3', lookup.address3)
  add_parameter(request, 'address4', lookup.address4)
  add_parameter(request, 'organization', lookup.organization)
  add_parameter(request, 'locality', lookup.locality)
  add_parameter(request, 'administrative_area', lookup.administrative_area)
  add_parameter(request, 'postal_code', lookup.postal_code)

  request
end

#convert_candidates(raw_candidates) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/smartystreets_ruby_sdk/international_street/client.rb', line 64

def convert_candidates(raw_candidates)
  candidates = []

  unless raw_candidates.nil?
    raw_candidates.each do |candidate|
      candidates.push(Candidate.new(candidate))
    end
  end

  candidates
end

#send(lookup) ⇒ Object

Sends a Lookup object to the International Street API and stores the result in the Lookup’s result field. Deprecated, please use send_lookup instead.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/smartystreets_ruby_sdk/international_street/client.rb', line 15

def send(lookup)
  lookup.ensure_enough_info
  request = build_request(lookup)

  response = @sender.send(request)

  raise response.error if response.error

  candidates = convert_candidates(@serializer.deserialize(response.payload))
  lookup.result = candidates
end

#send_lookup(lookup) ⇒ Object

Sends a Lookup object to the International Street API and stores the result in the Lookup’s result field.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/smartystreets_ruby_sdk/international_street/client.rb', line 28

def send_lookup(lookup)
  lookup.ensure_enough_info
  request = build_request(lookup)

  response = @sender.send(request)

  raise response.error if response.error

  candidates = convert_candidates(@serializer.deserialize(response.payload))
  lookup.result = candidates
end