Skip to content

Commit

Permalink
- Added Address Search functionality for the US Address Enrichment API
Browse files Browse the repository at this point in the history
 - Added include and exclude parameters for the US Address Enrichment API
 - Added etag header and 304 Info code for the US Address Enrichment API
 - Updated Enrichment Tests to reflect the new additions
  • Loading branch information
smartyeric committed Jan 21, 2025
1 parent 2203d7d commit cc493c5
Show file tree
Hide file tree
Showing 15 changed files with 421 additions and 23 deletions.
1 change: 1 addition & 0 deletions Sources/SmartyStreets/SmartyErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SmartyErrors {
case NotPositiveIntergerError
case JSONSerializationError
case MaxRetriesExceededError
case NotModifiedInfo = 304
case BadRequestError = 400
case BadCredentialsError = 401
case PaymentRequiredError = 402
Expand Down
4 changes: 4 additions & 0 deletions Sources/SmartyStreets/StatusCodeSender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class StatusCodeSender: SmartySender {
switch response?.statusCode {
case 200:
return response
case 304:
let details = [NSLocalizedDescriptionKey:"Not Modified. This data has not been modified since it was last retrieved."]
error = NSError(domain: smartyErrors.SSErrorDomain, code: SmartyErrors.SSErrors.NotModifiedInfo.rawValue, userInfo: details)
return response
case 400:
let details = [NSLocalizedDescriptionKey:"Bad Request (Malformed Payload): A GET request lacked a street field or the request body of a POST request contained malformed JSON."]
error = NSError(domain: smartyErrors.SSErrorDomain, code: SmartyErrors.SSErrors.BadRequestError.rawValue, userInfo: details)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import Foundation

public class EnrichmentLookup: Encodable {
private let smarty_key: String
private var smarty_key: String
private let data_set_name: String
private let data_subset_name: String
private var include_array: [String]
private var exclude_array: [String]
private var street: String
private var city: String
private var state: String
private var zipcode: String
private var freeform: String
private var etag: String

public init(smartyKey: String, datasetName: String, dataSubsetName: String) {
self.smarty_key = smartyKey
self.data_set_name = datasetName
self.data_subset_name = dataSubsetName
self.include_array = [String]()
self.exclude_array = [String]()
self.street = ""
self.city = ""
self.state = ""
self.zipcode = ""
self.freeform = ""
self.etag = ""
}

public init() {
self.smarty_key = ""
self.data_set_name = ""
self.data_subset_name = ""
self.include_array = [String]()
self.exclude_array = [String]()
self.street = ""
self.city = ""
self.state = ""
self.zipcode = ""
self.freeform = ""
self.etag = ""
}

public func getSmartyKey() -> String {
Expand All @@ -22,6 +52,74 @@ public class EnrichmentLookup: Encodable {
public func getDataSubsetName() -> String {
return data_subset_name
}

public func getIncludeAttributes() -> [String] {
return self.include_array
}

public func getExcludeAttributes() -> [String] {
return self.exclude_array
}

public func getStreet() -> String {
return self.street
}

public func getCity() -> String {
return self.city
}

public func getState() -> String {
return self.state
}

public func getZipcode() -> String {
return self.zipcode
}

public func getFreeform() -> String {
return self.freeform
}

public func getEtag() -> String{
return self.etag
}

public func setSmartyKey(smarty_key: String) {
self.smarty_key = smarty_key
}

public func addIncludeAttribute(attribute: String) {
self.include_array.append(attribute)
}

public func addExcludeAttribute(attribute: String) {
self.exclude_array.append(attribute)
}

public func setStreet(street: String) {
self.street = street
}

public func setCity(city: String) {
self.city = city
}

public func setState(state: String) {
self.state = state
}

public func setZipcode(zipcode: String) {
self.zipcode = zipcode
}

public func setFreeform(freeform: String) {
self.freeform = freeform
}

public func setEtag(etag: String) {
self.etag = etag
}

public func deserializeAndSetResults(serializer: SmartySerializer, payload: Data, error: UnsafeMutablePointer<NSError?>) {
fatalError("You must use a Lookup subclass with an implemented version of deserializeAndSetResults")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ public class GeoReferenceEnrichmentLookup: EnrichmentLookup {
super.init(smartyKey: smartyKey, datasetName: "geo-reference", dataSubsetName: "")
}

init(lookup: EnrichmentLookup) {
self.results = nil
super.init(smartyKey: lookup.getSmartyKey(), datasetName: "geo-reference", dataSubsetName: "")
for key in lookup.getIncludeAttributes() {
self.addIncludeAttribute(attribute: key)
}
for key in lookup.getExcludeAttributes() {
self.addExcludeAttribute(attribute: key)
}
self.setStreet(street: lookup.getStreet())
self.setCity(city: lookup.getCity())
self.setState(state: lookup.getState())
self.setZipcode(zipcode: lookup.getZipcode())
self.setFreeform(freeform: lookup.getFreeform())
self.setEtag(etag: lookup.getEtag())
}

override public func deserializeAndSetResults(serializer: SmartySerializer, payload: Data, error: UnsafeMutablePointer<NSError?>) {
self.results = serializer.Deserialize(payload: payload, error: &error.pointee) as? [GeoReferenceResult]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ public class PropertyFinancialEnrichmentLookup: EnrichmentLookup {
super.init(smartyKey: smartyKey, datasetName: "property", dataSubsetName: "financial")
}

init(lookup: EnrichmentLookup) {
self.results = nil
super.init(smartyKey: lookup.getSmartyKey(), datasetName: "property", dataSubsetName: "financial")
for key in lookup.getIncludeAttributes() {
self.addIncludeAttribute(attribute: key)
}
for key in lookup.getExcludeAttributes() {
self.addExcludeAttribute(attribute: key)
}
self.setStreet(street: lookup.getStreet())
self.setCity(city: lookup.getCity())
self.setState(state: lookup.getState())
self.setZipcode(zipcode: lookup.getZipcode())
self.setFreeform(freeform: lookup.getFreeform())
self.setEtag(etag: lookup.getEtag())
}

override public func deserializeAndSetResults(serializer: SmartySerializer, payload: Data, error: UnsafeMutablePointer<NSError?>) {
self.results = serializer.Deserialize(payload: payload, error: &error.pointee) as? [FinancialResult]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ public class PropertyPrincipalEnrichmentLookup: EnrichmentLookup {
super.init(smartyKey: smartyKey, datasetName: "property", dataSubsetName: "principal")
}

init(lookup: EnrichmentLookup) {
self.results = nil
super.init(smartyKey: lookup.getSmartyKey(), datasetName: "property", dataSubsetName: "principal")
for key in lookup.getIncludeAttributes() {
self.addIncludeAttribute(attribute: key)
}
for key in lookup.getExcludeAttributes() {
self.addExcludeAttribute(attribute: key)
}
self.setStreet(street: lookup.getStreet())
self.setCity(city: lookup.getCity())
self.setState(state: lookup.getState())
self.setZipcode(zipcode: lookup.getZipcode())
self.setFreeform(freeform: lookup.getFreeform())
self.setEtag(etag: lookup.getEtag())
}

override public func deserializeAndSetResults(serializer: SmartySerializer, payload: Data, error: UnsafeMutablePointer<NSError?>) {
self.results = serializer.Deserialize(payload: payload, error: &error.pointee) as? [PrincipalResult]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ public class SecondaryCountEnrichmentLookup: EnrichmentLookup {
super.init(smartyKey: smartyKey, datasetName: "secondary", dataSubsetName: "count")
}

init(lookup: EnrichmentLookup) {
self.results = nil
super.init(smartyKey: lookup.getSmartyKey(), datasetName: "secondary", dataSubsetName: "count")
for key in lookup.getIncludeAttributes() {
self.addIncludeAttribute(attribute: key)
}
for key in lookup.getExcludeAttributes() {
self.addExcludeAttribute(attribute: key)
}
self.setStreet(street: lookup.getStreet())
self.setCity(city: lookup.getCity())
self.setState(state: lookup.getState())
self.setZipcode(zipcode: lookup.getZipcode())
self.setFreeform(freeform: lookup.getFreeform())
self.setEtag(etag: lookup.getEtag())
}

override public func deserializeAndSetResults(serializer: SmartySerializer, payload: Data, error: UnsafeMutablePointer<NSError?>) {
self.results = serializer.Deserialize(payload: payload, error: &error.pointee) as? [SecondaryCountResult]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ public class SecondaryEnrichmentLookup: EnrichmentLookup {
super.init(smartyKey: smartyKey, datasetName: "secondary", dataSubsetName: "")
}

init(lookup: EnrichmentLookup) {
self.results = nil
super.init(smartyKey: lookup.getSmartyKey(), datasetName: "secondary", dataSubsetName: "")
for key in lookup.getIncludeAttributes() {
self.addIncludeAttribute(attribute: key)
}
for key in lookup.getExcludeAttributes() {
self.addExcludeAttribute(attribute: key)
}
self.setStreet(street: lookup.getStreet())
self.setCity(city: lookup.getCity())
self.setState(state: lookup.getState())
self.setZipcode(zipcode: lookup.getZipcode())
self.setFreeform(freeform: lookup.getFreeform())
self.setEtag(etag: lookup.getEtag())
}

override public func deserializeAndSetResults(serializer: SmartySerializer, payload: Data, error: UnsafeMutablePointer<NSError?>) {
self.results = serializer.Deserialize(payload: payload, error: &error.pointee) as? [SecondaryResult]
}
Expand Down
Loading

0 comments on commit cc493c5

Please sign in to comment.