Skip to content

Commit

Permalink
Eric/add enrichment endpoints (#52)
Browse files Browse the repository at this point in the history
* Added GeoReference Endpoint

* Removed unecessary methods

* Added Secondary Endpoint

* Added generic lookup

* Improved generic lookup

---------

Co-authored-by: Eric Devenport <eric@Eric-Devenports-MacBook-Air.local>
  • Loading branch information
smartyeric and Eric Devenport authored Aug 12, 2024
1 parent 1199738 commit 48dda29
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/smartystreets_ruby_sdk/us_enrichment/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
require_relative "property/principal/response"
require_relative "property/financial/lookup"
require_relative "property/principal/lookup"
require_relative "geo_reference/response"
require_relative "geo_reference/lookup"
require_relative "secondary/response"
require_relative "secondary/lookup"
require_relative "secondary/count/response"
require_relative "secondary/count/lookup"
require_relative "lookup"
require_relative '../request'

module SmartyStreets
Expand All @@ -20,12 +27,32 @@ def send_property_principal_lookup(smarty_key)
__send(USEnrichment::Property::Principal::Lookup.new(smarty_key))
end

def send_geo_reference_lookup(smarty_key)
__send(USEnrichment::GeoReference::Lookup.new(smarty_key))
end

def send_secondary_lookup(smarty_key)
__send(USEnrichment::Secondary::Lookup.new(smarty_key))
end

def send_secondary_count_lookup(smarty_key)
__send(USEnrichment::Secondary::Count::Lookup.new(smarty_key))
end

def send_generic_lookup(smarty_key, data_set, data_sub_set = nil)
__send(USEnrichment::Lookup.new(smarty_key, data_set, data_sub_set))
end

def __send(lookup)
smarty_request = Request.new

return if lookup.nil?

smarty_request.url_components = '/' + lookup.smarty_key + '/' + lookup.data_set + '/' + lookup.data_sub_set
if (lookup.data_sub_set.nil?)
smarty_request.url_components = '/' + lookup.smarty_key + '/' + lookup.data_set
else
smarty_request.url_components = '/' + lookup.smarty_key + '/' + lookup.data_set + '/' + lookup.data_sub_set
end

response = @sender.send(smarty_request)
results = @serializer.deserialize(response.payload)
Expand All @@ -42,6 +69,16 @@ def __send(lookup)
if lookup.data_sub_set == "principal"
result = USEnrichment::Property::Principal::Response.new(raw_result)
end
if lookup.data_set == "geo-reference"
result = USEnrichment::GeoReference::Response.new(raw_result)
end
if lookup.data_set == "secondary"
if lookup.data_sub_set == "count"
result = USEnrichment::Secondary::Count::Response.new(raw_result)
elsif lookup.data_sub_set.nil?
result = USEnrichment::Secondary::Response.new(raw_result)
end
end
output << result
end
output
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require_relative 'census_block_entry'
require_relative 'census_county_division_entry'
require_relative 'census_tract_entry'
require_relative 'core_based_stat_area_entry'
require_relative 'place_entry'

module SmartyStreets
module USEnrichment
module GeoReference
class Attributes
attr_reader :census_block, :census_county_division, :census_tract, :core_based_stat_area, :place

def initialize(obj)
@census_block = GeoReference::CensusBlockEntry.new(obj['census_block'])
@census_county_division = GeoReference::CensusCountyDivisionEntry.new(obj['census_county_division'])
@census_tract = GeoReference::CensusTractEntry.new(obj['census_tract'])
@core_based_stat_area = GeoReference::CoreBasedStatAreaEntry.new(obj['core_based_stat_area'])
@place = GeoReference::PlaceEntry.new(obj['place'])
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module SmartyStreets
module USEnrichment
module GeoReference
class CensusBlockEntry
attr_reader :accuracy, :geoid

def initialize(obj)
@accuracy = obj['accuracy']
@geoid = obj['geoid']
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module SmartyStreets
module USEnrichment
module GeoReference
class CensusCountyDivisionEntry
attr_reader :accuracy, :code, :name

def initialize(obj)
@accuracy = obj['accuracy']
@code = obj['code']
@name = obj['name']
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module SmartyStreets
module USEnrichment
module GeoReference
class CensusTractEntry
attr_reader :code

def initialize(obj)
@code = obj['code']
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module SmartyStreets
module USEnrichment
module GeoReference
class CoreBasedStatAreaEntry
attr_reader :code, :name

def initialize(obj)
@code = obj['code']
@name = obj['name']
end
end
end
end
end
15 changes: 15 additions & 0 deletions lib/smartystreets_ruby_sdk/us_enrichment/geo_reference/lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module SmartyStreets
module USEnrichment
module GeoReference
class Lookup
attr_reader :smarty_key, :data_set, :data_sub_set

def initialize(smarty_key)
@smarty_key = smarty_key
@data_set = 'geo-reference'
@data_sub_set = nil
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module SmartyStreets
module USEnrichment
module GeoReference
class PlaceEntry
attr_reader :accuracy, :code, :name, :type

def initialize(obj)
@accuracy = obj['accuracy']
@code = obj['code']
@name = obj['name']
@type = obj['type']
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/smartystreets_ruby_sdk/us_enrichment/geo_reference/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative "attributes"

module SmartyStreets
module USEnrichment
module GeoReference
class Response
attr_reader :smarty_key, :data_set, :attributes

def initialize(obj)
@smarty_key = obj['smarty_key']
@data_set = 'geo-reference'
@attributes = Attributes.new(obj['attributes'])
end
end
end
end
end
13 changes: 13 additions & 0 deletions lib/smartystreets_ruby_sdk/us_enrichment/lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module SmartyStreets
module USEnrichment
class Lookup
attr_reader :smarty_key, :data_set, :data_sub_set

def initialize(smarty_key, data_set, data_sub_set)
@smarty_key = smarty_key
@data_set = data_set
@data_sub_set = data_sub_set
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module SmartyStreets
module USEnrichment
module Secondary
class AliasesEntry
attr_reader :smarty_key, :primary_number, :street_predirection, :street_name, :street_suffix, :street_postdirection, :city_name,
:state_abbreviation, :zipcode, :plus4_code

def initialize(obj)
@smarty_key = obj['smarty_key']
@primary_number = obj['primary_number']
@street_predirection = obj['street_predirection']
@street_name = obj['street_name']
@street_suffix = obj['street_suffix']
@street_postdirection = obj['street_postdirection']
@city_name = obj['city_name']
@state_abbreviation = obj['state_abbreviation']
@zipcode = obj['zipcode']
@plus4_code = obj['plus4_code']
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/smartystreets_ruby_sdk/us_enrichment/secondary/count/lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module SmartyStreets
module USEnrichment
module Secondary
module Count
class Lookup
attr_reader :smarty_key, :data_set, :data_sub_set

def initialize(smarty_key)
@smarty_key = smarty_key
@data_set = "secondary"
@data_sub_set = "count"
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module SmartyStreets
module USEnrichment
module Secondary
module Count
class Response
attr_reader :smarty_key, :count

def initialize(obj)
@smarty_key = obj['smarty_key']
@count = obj['count']
end
end
end
end
end
end
15 changes: 15 additions & 0 deletions lib/smartystreets_ruby_sdk/us_enrichment/secondary/lookup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module SmartyStreets
module USEnrichment
module Secondary
class Lookup
attr_reader :smarty_key, :data_set, :data_sub_set

def initialize(smarty_key)
@smarty_key = smarty_key
@data_set = "secondary"
@data_sub_set = nil
end
end
end
end
end
38 changes: 38 additions & 0 deletions lib/smartystreets_ruby_sdk/us_enrichment/secondary/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require_relative 'root_address_entry'
require_relative 'aliases_entry'
require_relative 'secondaries_entry'

module SmartyStreets
module USEnrichment
module Secondary
class Response
attr_reader :smarty_key, :root_address, :aliases, :secondaries

def initialize(obj)
@smarty_key = obj['smarty_key']
@root_address = Secondary::RootAddressEntry.new(obj['root_address'])
if !obj['aliases'].nil?
@aliases = createAliasesArray(obj['aliases'])
end
@secondaries = createSecondariesArray(obj['secondaries'])
end

def createAliasesArray(obj)
aliasesArray = []
for item in obj do
aliasesArray << Secondary::AliasesEntry.new(item)
end
return aliasesArray
end

def createSecondariesArray(obj)
secondariesArray = []
for item in obj do
secondariesArray << Secondary::SecondariesEntry.new(item)
end
return secondariesArray
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module SmartyStreets
module USEnrichment
module Secondary
class RootAddressEntry
attr_reader :secondary_count, :smarty_key, :primary_number, :street_predirection, :street_name, :street_suffix, :street_postdirection,
:city_name, :state_abbreviation, :zipcode, :plus4_code

def initialize(obj)
@secondary_count = obj['secondary_count']
@smarty_key = obj['smarty_key']
@primary_number = obj['primary_number']
@street_predirection = obj['street_predirection']
@street_name = obj['street_name']
@street_suffix = obj['street_suffix']
@street_postdirection = obj['street_postdirection']
@city_name = obj['city_name']
@state_abbreviation = obj['state_abbreviation']
@zipcode = obj['zipcode']
@plus4_code = obj['plus4_code']
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module SmartyStreets
module USEnrichment
module Secondary
class SecondariesEntry
attr_reader :smarty_key, :secondary_designator, :secondary_number, :plus4_code

def initialize(obj)
@smarty_key = obj['smarty_key']
@secondary_designator = obj['secondary_designator']
@secondary_number = obj['secondary_number']
@plus4_code = obj['plus4_code']
end
end
end
end
end

0 comments on commit 48dda29

Please sign in to comment.