Skip to content

Commit fbc0c2e

Browse files
committed
Removing the objectivec examples. We don't support these officially anymore.
We should be sending application/json for all POST requests. Making sure all the examples have both types of credentials in the example. Adding new fields to international autocomplete.
1 parent 181f1fe commit fbc0c2e

37 files changed

+167
-659
lines changed

Sources/SmartyStreets/HTTPSender.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class HttpSender: SmartySender {
6262
httpRequest.httpMethod = "GET"
6363
} else {
6464
httpRequest.setValue("gzip", forHTTPHeaderField: "Accept-Encoding")
65-
httpRequest.setValue("text/plain; charset=utf-8", forHTTPHeaderField: "Content-Type")
65+
httpRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
6666
httpRequest.httpMethod = "POST"
6767
httpRequest.httpBody = request.payload
6868
}

Sources/SmartyStreets/InternationalAutocomplete/InternationalAutocompleteClient.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ public class InternationalAutocompleteClient: NSObject {
4848

4949
request.setValue(value: lookup.search ?? "", HTTPParameterField: "search")
5050
request.setValue(value: lookup.country ?? "", HTTPParameterField: "country")
51-
request.setValue(value: lookup.getMaxResultsStringIfSet(), HTTPParameterField: "max_results")
51+
request.setValue(value: lookup.maxResults.flatMap { String($0) } ?? "10", HTTPParameterField: "max_results")
52+
request.setValue(value: lookup.distance.flatMap { String($0) } ?? "5", HTTPParameterField: "distance")
53+
if lookup.geolocation != InternationalAutocompleteLookup.InternationalGeolocateType.none {
54+
request.setValue(value: lookup.geolocation?.rawValue ?? "", HTTPParameterField: "geolocation")
55+
}
5256
request.setValue(value: lookup.administrativeArea ?? "", HTTPParameterField: "include_only_administrative_area")
5357
request.setValue(value: lookup.locality ?? "", HTTPParameterField: "include_only_locality")
5458
request.setValue(value: lookup.postalCode ?? "", HTTPParameterField: "include_only_postal_code")
59+
request.setValue(value: lookup.longitude.flatMap { String($0) } ?? "", HTTPParameterField: "longitude")
60+
request.setValue(value: lookup.latitude.flatMap { String($0) } ?? "", HTTPParameterField: "latitude")
5561

5662
return request
5763
}

Sources/SmartyStreets/InternationalAutocomplete/InternationalAutocompleteLookup.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,45 @@ import Foundation
66
//
77
// See "https://smartystreets.com/docs/cloud/international-address-autocomplete-api#pro-http-request-input-fields"
88

9-
let SSMaxResults = 10
9+
static let SSMaxResults = 10
10+
static let SSDistance = 5
1011

1112
public var result:InternationalAutocompleteResult?
1213
public var country:String?
1314
public var search:String?
1415
public var maxResults:Int?
16+
public var distance:Int?
17+
public var geolocation:InternationalGeolocateType?
1518
public var administrativeArea:String?
1619
public var locality:String?
1720
public var postalCode:String?
21+
public var latitude:Double?
22+
public var longitude:Double?
23+
24+
public enum InternationalGeolocateType: String, Codable {
25+
case adminarea
26+
case locality
27+
case postalcode
28+
case geocodes
29+
case none
30+
}
1831

1932
enum CodingKeys: String, CodingKey {
2033
case country = "country"
2134
case search = "search"
2235
case maxResults = "max_results"
36+
case distance = "distance"
37+
case geolocation = "geolocation"
2338
case administrativeArea = "include_only_administrative_area"
2439
case locality = "include_only_locality"
2540
case postalCode = "include_only_postal_code"
41+
case latitude = "latitude"
42+
case longitude = "longitude"
2643
}
2744

2845
override public init() {
29-
self.maxResults = SSMaxResults
46+
self.maxResults = InternationalAutocompleteLookup.SSMaxResults
47+
self.distance = InternationalAutocompleteLookup.SSDistance
3048
}
3149

3250
public func withSearch(search:String) -> InternationalAutocompleteLookup {
@@ -42,14 +60,6 @@ import Foundation
4260
}
4361
}
4462

45-
func getMaxResultsStringIfSet() -> String {
46-
if self.maxResults == SSMaxResults {
47-
return String()
48-
} else {
49-
return "\(self.maxResults ?? 0)"
50-
}
51-
}
52-
5363
public func setMaxResults(maxResults: Int, error: inout NSError?) {
5464
if maxResults > 0 && maxResults <= 10 {
5565
self.maxResults = maxResults

Sources/SmartyStreets/USExtract/USExtractAddress.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import Foundation
1111
public var candidates:[USStreetCandidate]?
1212

1313
enum CodingKeys: String, CodingKey {
14+
case text = "text"
15+
case verified = "verified"
16+
case line = "line"
17+
case start = "start"
18+
case end = "end"
1419
case candidates = "api_output"
1520
}
1621

Sources/SmartyStreets/USReverseGeo/USReverseGeoAddress.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import Foundation
66
public var stateAbbreviation:String?
77
public var zipcode:String?
88

9+
enum CodingKeys: String, CodingKey {
10+
case street = "street"
11+
case city = "city"
12+
case stateAbbreviation = "state_abbreviation"
13+
case zipcode = "zipcode"
14+
}
15+
916
init(dictionary: NSDictionary) {
1017
self.street = dictionary["street"] as? String
1118
self.city = dictionary["city"] as? String

Tests/SmartyStreetsTests/InternationalAutocompleteTests/InternationalAutocompleteClientTests.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ class InternationalAutocompleteClientTests: XCTestCase {
2828
lookup.locality = "3"
2929
lookup.administrativeArea = "4"
3030
lookup.maxResults = 5
31+
lookup.distance = 7
32+
lookup.geolocation = InternationalAutocompleteLookup.InternationalGeolocateType.geocodes
3133
lookup.postalCode = "6"
34+
lookup.longitude = 112.1
35+
lookup.latitude = -23.4
3236

3337
_ = client.sendLookup(lookup:&lookup, error:&error)
3438

@@ -37,7 +41,34 @@ class InternationalAutocompleteClientTests: XCTestCase {
3741
XCTAssertEqual("3", capturingSender.request.parameters["include_only_locality"])
3842
XCTAssertEqual("4", capturingSender.request.parameters["include_only_administrative_area"])
3943
XCTAssertEqual("5", capturingSender.request.parameters["max_results"])
44+
XCTAssertEqual("7", capturingSender.request.parameters["distance"])
45+
XCTAssertEqual("geocodes", capturingSender.request.parameters["geolocation"])
4046
XCTAssertEqual("6", capturingSender.request.parameters["include_only_postal_code"])
47+
XCTAssertEqual("112.1", capturingSender.request.parameters["longitude"])
48+
XCTAssertEqual("-23.4", capturingSender.request.parameters["latitude"])
49+
XCTAssertNil(self.error)
50+
}
51+
52+
func testSendingSingleMinimumParams() {
53+
let sender = URLPrefixSender(urlPrefix: "http://localhost/", inner: self.capturingSender as Any)
54+
let serializer = MockSerializer(result: InternationalAutocompleteResult(dictionary: NSDictionary()))
55+
let client = InternationalAutocompleteClient(sender:sender, serializer:serializer)
56+
var lookup = InternationalAutocompleteLookup()
57+
lookup.search = "1"
58+
lookup.country = "2"
59+
60+
_ = client.sendLookup(lookup:&lookup, error:&error)
61+
62+
XCTAssertEqual("1", capturingSender.request.parameters["search"])
63+
XCTAssertEqual("2", capturingSender.request.parameters["country"])
64+
XCTAssertEqual(nil, capturingSender.request.parameters["include_only_locality"])
65+
XCTAssertEqual(nil, capturingSender.request.parameters["include_only_administrative_area"])
66+
XCTAssertEqual("10", capturingSender.request.parameters["max_results"])
67+
XCTAssertEqual("5", capturingSender.request.parameters["distance"])
68+
XCTAssertEqual(nil, capturingSender.request.parameters["geolocation"])
69+
XCTAssertEqual(nil, capturingSender.request.parameters["include_only_postal_code"])
70+
XCTAssertEqual(nil, capturingSender.request.parameters["longitude"])
71+
XCTAssertEqual(nil, capturingSender.request.parameters["latitude"])
4172
XCTAssertNil(self.error)
4273
}
4374
}

samples/Package.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ let package = Package(
1010
.target(
1111
name: "swiftExamples",
1212
dependencies: ["SmartyStreets"]),
13-
.target(
14-
name: "objcExamples",
15-
dependencies: ["SmartyStreets"]),
1613
.testTarget(
1714
name: "samplesTests",
1815
dependencies: ["swiftExamples"],

samples/Sources/objcExamples/InternationalAutocompleteExample.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

samples/Sources/objcExamples/InternationalAutocompleteExample.m

Lines changed: 0 additions & 45 deletions
This file was deleted.

samples/Sources/objcExamples/InternationalStreetExample.h

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)