Skip to content

Commit

Permalink
Merge pull request #37 from smartystreets/xan/fix-url-prefix-bug
Browse files Browse the repository at this point in the history
Fix url prefix bug from retries
  • Loading branch information
XanSmarty authored Mar 21, 2024
2 parents 1b08082 + 862bfae commit d8ceaee
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions Sources/SmartyStreets/SmartyRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Sources/SmartyStreets/URLPrefixSender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
14 changes: 13 additions & 1 deletion Tests/SmartyStreetsTests/URLPrefixSenderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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")

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d8ceaee

Please sign in to comment.