diff --git a/Sources/SmartyStreets/InternationalAutocomplete/InternationalAutocompleteClient.swift b/Sources/SmartyStreets/InternationalAutocomplete/InternationalAutocompleteClient.swift index c9d4e7f..6568e14 100644 --- a/Sources/SmartyStreets/InternationalAutocomplete/InternationalAutocompleteClient.swift +++ b/Sources/SmartyStreets/InternationalAutocomplete/InternationalAutocompleteClient.swift @@ -43,7 +43,7 @@ public class InternationalAutocompleteClient: NSObject { let request = SmartyRequest() if let unwrappedPrefix = lookup.addressID { - request.urlPrefix = "/" + unwrappedPrefix + request.urlComponents = "/" + unwrappedPrefix } request.setValue(value: lookup.search ?? "", HTTPParameterField: "search") diff --git a/Sources/SmartyStreets/SmartyRequest.swift b/Sources/SmartyStreets/SmartyRequest.swift index 81e397e..7a1a8fd 100644 --- a/Sources/SmartyStreets/SmartyRequest.swift +++ b/Sources/SmartyStreets/SmartyRequest.swift @@ -5,6 +5,7 @@ public class SmartyRequest { public var headers:[String:String] public var parameters:[String:String] public var urlPrefix:String + public var urlComponents:String public var payload:Data? public var referer:String? public var method:String @@ -14,6 +15,7 @@ public class SmartyRequest { self.headers = NSMutableDictionary() as! [String : String] self.parameters = NSMutableDictionary() as! [String : String] self.urlPrefix = "" + self.urlComponents = "" self.payload = nil self.referer = nil self.method = "GET" diff --git a/Sources/SmartyStreets/URLPrefixSender.swift b/Sources/SmartyStreets/URLPrefixSender.swift index f91207c..d2414e3 100644 --- a/Sources/SmartyStreets/URLPrefixSender.swift +++ b/Sources/SmartyStreets/URLPrefixSender.swift @@ -11,8 +11,8 @@ public class URLPrefixSender: SmartySender { } override func sendRequest(request: SmartyRequest, error: inout NSError!) -> SmartyResponse! { - if !request.urlPrefix.isEmpty { - request.urlPrefix = self.urlPrefix + request.urlPrefix + if !request.urlComponents.isEmpty { + request.urlPrefix = self.urlPrefix + request.urlComponents } else { request.urlPrefix = self.urlPrefix } diff --git a/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyFinancial/FinancialResult.swift b/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyFinancial/FinancialResult.swift index d15b271..f4471cb 100644 --- a/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyFinancial/FinancialResult.swift +++ b/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyFinancial/FinancialResult.swift @@ -1,8 +1,8 @@ import Foundation public struct FinancialResult: Codable { - let smartyKey, dataSetName, dataSubsetName: String - let attributes: FinancialAttributes + public let smartyKey, dataSetName, dataSubsetName: String? + public let attributes: FinancialAttributes? enum CodingKeys: String, CodingKey { case smartyKey = "smarty_key" diff --git a/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyPrincipal/PrincipalResult.swift b/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyPrincipal/PrincipalResult.swift index 5a6c643..9ba557e 100644 --- a/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyPrincipal/PrincipalResult.swift +++ b/Sources/SmartyStreets/USEnrichment/ResultTypes/PropertyPrincipal/PrincipalResult.swift @@ -1,8 +1,8 @@ import Foundation public struct PrincipalResult: Codable { - let smartyKey, dataSetName, dataSubsetName: String - let attributes: PrincipalAttributes + public let smartyKey, dataSetName, dataSubsetName: String? + public let attributes: PrincipalAttributes? enum CodingKeys: String, CodingKey { case smartyKey = "smarty_key" diff --git a/Sources/SmartyStreets/USEnrichment/USEnrichmentClient.swift b/Sources/SmartyStreets/USEnrichment/USEnrichmentClient.swift index edc1f88..b4fdf59 100644 --- a/Sources/SmartyStreets/USEnrichment/USEnrichmentClient.swift +++ b/Sources/SmartyStreets/USEnrichment/USEnrichmentClient.swift @@ -62,7 +62,7 @@ public class USEnrichmentClient: NSObject { func buildRequest(lookup:EnrichmentLookup) -> SmartyRequest { let request = SmartyRequest() - request.urlPrefix = "/" + lookup.getSmartyKey() + "/" + lookup.getDatasetName() + "/" + lookup.getDataSubsetName() + request.urlComponents = "/" + lookup.getSmartyKey() + "/" + lookup.getDatasetName() + "/" + lookup.getDataSubsetName() return request } } diff --git a/Tests/SmartyStreetsTests/URLPrefixSenderTests.swift b/Tests/SmartyStreetsTests/URLPrefixSenderTests.swift index c95bf75..1616900 100644 --- a/Tests/SmartyStreetsTests/URLPrefixSenderTests.swift +++ b/Tests/SmartyStreetsTests/URLPrefixSenderTests.swift @@ -22,7 +22,7 @@ class URLPrefixSenderTests: XCTestCase { func testRequestURLPresent() { let request:SmartyRequest = SmartyRequest() - request.urlPrefix = "/jimbo" + request.urlComponents = "/jimbo" _ = self.urlPrefixSender.sendRequest(request: request, error: &self.error) @@ -39,4 +39,16 @@ class URLPrefixSenderTests: XCTestCase { } + func testMultipleSends() { + let request:SmartyRequest = SmartyRequest() + request.urlComponents = "/jimbo" + + _ = self.urlPrefixSender.sendRequest(request: request, error: &self.error) + _ = self.urlPrefixSender.sendRequest(request: request, error: &self.error) + + XCTAssertEqual(request.urlPrefix, "http://mysite.com/lookup/jimbo") + + } + + } \ No newline at end of file diff --git a/Tests/SmartyStreetsTests/USEnrichmentTests/FinancialResultTest.swift b/Tests/SmartyStreetsTests/USEnrichmentTests/FinancialResultTest.swift index bd7c014..586c101 100644 --- a/Tests/SmartyStreetsTests/USEnrichmentTests/FinancialResultTest.swift +++ b/Tests/SmartyStreetsTests/USEnrichmentTests/FinancialResultTest.swift @@ -47,12 +47,15 @@ class USEnrichmentFinancialResultTest: XCTestCase { let results = serializer.Deserialize(payload: jsonData, error: &self.error) as? [FinancialResult] print(results!) let result = results![0] + + guard let attributes = result.attributes else { + print("Attributes was null") + return + } XCTAssertEqual("xxx", result.smartyKey) - XCTAssertEqual("property", result.dataSetName.lowercased()) - XCTAssertEqual("financial", result.dataSubsetName.lowercased()) - - let attributes = result.attributes + XCTAssertEqual("property", result.dataSetName) + XCTAssertEqual("financial", result.dataSubsetName) XCTAssertEqual("assessed_improvement_percent", attributes.assessedImprovementPercent!.lowercased()) XCTAssertEqual("assessed_improvement_value", attributes.assessedImprovementValue!.lowercased()) diff --git a/Tests/SmartyStreetsTests/USEnrichmentTests/PrincipalResultTest.swift b/Tests/SmartyStreetsTests/USEnrichmentTests/PrincipalResultTest.swift index b990149..b0ce3c9 100644 --- a/Tests/SmartyStreetsTests/USEnrichmentTests/PrincipalResultTest.swift +++ b/Tests/SmartyStreetsTests/USEnrichmentTests/PrincipalResultTest.swift @@ -51,7 +51,10 @@ class USEnrichmentPrincipalResultTest: XCTestCase { let results = serializer.Deserialize(payload: jsonData, error: &self.error) as? [PrincipalResult] print(results!) let result = results![0] - let attributes = result.attributes + guard let attributes = result.attributes else { + print("Attributes was null") + return + } XCTAssertEqual("xxx", result.smartyKey) XCTAssertEqual("property", result.dataSetName)