Skip to content

Commit 0bfc1dc

Browse files
author
Lukas Kukacka
committed
Deprecations of id and reference properties since they have been deprecated by Google
- See Readme -> Version history for more info
1 parent 7927bdb commit 0bfc1dc

9 files changed

Lines changed: 659 additions & 470 deletions

FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,23 @@
3737
*/
3838
@interface FTGooglePlacesAPIDetailRequest : NSObject <FTGooglePlacesAPIRequest>
3939

40+
@property (nonatomic, strong, readonly) NSString *placeId;
41+
42+
/**
43+
* Creates new request on a detail of place with given placeId
44+
*/
45+
- (instancetype)initWithPlaceId:(NSString *)placeId;
46+
47+
/**
48+
* Deprecations
49+
*/
50+
4051
/**
4152
* Reference with which the request was initialized.
4253
* This is a unique identifier for a place (itemId from the ResultItem)
4354
*/
44-
@property (nonatomic, strong, readonly) NSString *reference;
55+
@property (nonatomic, strong, readonly) NSString *reference DEPRECATED_MSG_ATTRIBUTE("Deprecated in API by Google as of June 24, 2014. Use placeId instead. See https://developers.google.com/places/documentation/details#deprecation for more info.");
4556

46-
- (instancetype)initWithReference:(NSString *)reference;
57+
- (instancetype)initWithReference:(NSString *)reference DEPRECATED_MSG_ATTRIBUTE("Uses deprecated property reference (see @reference)");
4758

4859
@end

FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.m

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ @implementation FTGooglePlacesAPIDetailRequest
3434

3535
#pragma mark Lifecycle
3636

37-
- (instancetype)initWithReference:(NSString *)reference
37+
- (instancetype)initWithPlaceId:(NSString *)placeId
3838
{
39-
if ([reference length] == 0) {
40-
NSLog(@"WARNING: Trying to create FTGooglePlacesAPIDetailRequest with empty reference. Returning nil");
39+
if ([placeId length] == 0) {
40+
NSLog(@"WARNING: Trying to create FTGooglePlacesAPIDetailRequest with empty placeId. Returning nil");
4141
return nil;
4242
}
4343

4444
self = [super init];
4545
if (self) {
46-
_reference = reference;
46+
_placeId = placeId;
4747
}
4848
return self;
4949
}
@@ -52,7 +52,7 @@ - (instancetype)initWithReference:(NSString *)reference
5252

5353
- (NSString *)description
5454
{
55-
return [NSString stringWithFormat:@"<%@: %p> Reference: %@", [self class], self, _reference];
55+
return [NSString stringWithFormat:@"<%@: %p> Place ID: %@", [self class], self, _placeId];
5656
}
5757

5858
#pragma mark - FTGooglePlacesAPIRequest protocol
@@ -64,7 +64,29 @@ - (NSString *)placesAPIRequestMethod
6464

6565
- (NSDictionary *)placesAPIRequestParams
6666
{
67-
return @{@"reference": _reference};
67+
if (_placeId) {
68+
return @{@"placeid": _placeId};
69+
}
70+
else {
71+
return @{@"reference": _reference};
72+
}
73+
74+
}
75+
76+
#pragma mark - Deprecations
77+
78+
- (instancetype)initWithReference:(NSString *)reference
79+
{
80+
if ([reference length] == 0) {
81+
NSLog(@"WARNING: Trying to create FTGooglePlacesAPIDetailRequest with empty reference. Returning nil");
82+
return nil;
83+
}
84+
85+
self = [super init];
86+
if (self) {
87+
_reference = reference;
88+
}
89+
return self;
6890
}
6991

7092
@end

FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ typedef NS_ENUM(NSUInteger, FTGooglePlacesAPISearchResultItemOpenedState) {
4040

4141
@interface FTGooglePlacesAPISearchResultItem : NSObject
4242

43-
@property (nonatomic, strong, readonly) NSString *itemId; // Google's id for the item
43+
@property (nonatomic, strong, readonly) NSString *placeId; // Google's id for the item
4444
@property (nonatomic, strong, readonly) NSString *name;
4545

4646
/**
@@ -76,12 +76,18 @@ typedef NS_ENUM(NSUInteger, FTGooglePlacesAPISearchResultItemOpenedState) {
7676

7777
/**
7878
* Method for comparing equality of two result item objects.
79-
* Objects are considered to be equal if their "itemId" equals.
79+
* Objects are considered to be equal if their "placeId" equals.
8080
*
8181
* @param item Item to compare with
8282
*
8383
* @return YES if both objects are considered to be equal
8484
*/
8585
- (BOOL)isEqualToSearchResultItem:(FTGooglePlacesAPISearchResultItem *)item;
8686

87+
88+
/**
89+
* Deprecations
90+
*/
91+
@property (nonatomic, strong, readonly) NSString *itemId DEPRECATED_MSG_ATTRIBUTE("Deprecated in API by Google as of June 24, 2014. Use placeId instead. See https://developers.google.com/places/documentation/details#deprecation for more info.");
92+
8793
@end

FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary
5454
[self ftgpi_importDictionary:dictionary];
5555

5656
// Object cannot be valid with no id
57-
if ([_itemId length] == 0) {
57+
if ([_placeId length] == 0) {
5858
return nil;
5959
}
6060

@@ -77,7 +77,7 @@ - (NSString *)debugDescription
7777
- (NSUInteger)hash
7878
{
7979
// Google's ID is unique identifier of the item
80-
return [_itemId hash];
80+
return [_placeId hash];
8181
}
8282

8383
- (BOOL)isEqual:(id)object
@@ -93,7 +93,7 @@ - (BOOL)isEqual:(id)object
9393

9494
- (BOOL)isEqualToSearchResultItem:(FTGooglePlacesAPISearchResultItem *)item
9595
{
96-
return [_itemId isEqualToString:item.itemId];
96+
return [_placeId isEqualToString:item.placeId];
9797
}
9898

9999
@end
@@ -108,7 +108,7 @@ - (void)ftgpi_importDictionary:(NSDictionary *)dictionary
108108
{
109109
_originalDictionaryRepresentation = dictionary;
110110

111-
_itemId = [dictionary ftgp_nilledObjectForKey:@"id"];
111+
_placeId = [dictionary ftgp_nilledObjectForKey:@"place_id"];
112112
_name = [dictionary ftgp_nilledObjectForKey:@"name"];
113113

114114

@@ -148,6 +148,9 @@ - (void)ftgpi_importDictionary:(NSDictionary *)dictionary
148148
_rating = [[dictionary ftgp_nilledObjectForKey:@"rating"] floatValue];
149149
_reference = [dictionary ftgp_nilledObjectForKey:@"reference"];
150150
_types = [dictionary ftgp_nilledObjectForKey:@"types"];
151+
152+
// Deprecated, left for backwards compatibility
153+
_itemId = [dictionary ftgp_nilledObjectForKey:@"id"];
151154
}
152155

153156
@end

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ Pull requests are very welcome expecting you follow few rules:
145145

146146
##Version history
147147

148+
#### 1.1
149+
- Implemented deprecations for usage of `id` and `reference` properties as these has been deprecated by Google as of June 24, 2014. See [Deprecation notice in documentation](https://developers.google.com/places/documentation/details#deprecation) for more info.
150+
148151
#### 1.0
149152
- First official public release
150153

XcodeProject/FTGooglePlacesAPI/FTGooglePlacesAPIExampleResultsViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
157157
FTGooglePlacesAPISearchResultItem *resultItem = _results[indexPath.row];
158158

159159
// Create detail request
160-
FTGooglePlacesAPIDetailRequest *request = [[FTGooglePlacesAPIDetailRequest alloc] initWithReference:resultItem.reference];
160+
FTGooglePlacesAPIDetailRequest *request = [[FTGooglePlacesAPIDetailRequest alloc] initWithPlaceId:resultItem.placeId];
161161

162162
// Create detail controller
163163
FTGooglePlacesAPIExampleDetailViewController *detailController = [[FTGooglePlacesAPIExampleDetailViewController alloc] initWithRequest:request];

XcodeProject/FTGooglePlacesAPILogicTests/Source/FTGooglePlacesAPISearchResponseTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ - (void)testRequestAndNextPageRequestMethod
118118
XCTAssertNotNil(nextPageRequest, @"nextPageRequest should not be nil");
119119

120120
XCTAssertEqualObjects([nextPageRequest placesAPIRequestMethod], @"testrequest", @"nextPageRequest requestTypeUrlString is wrong");
121-
NSDictionary *expectedRequestParams = @{@"pagetoken": @"CmRbAAAAPRe43WuMoqKDiLcauzH5NR5Agm6U5pqiP5gPALHlvKSe89bdGpjNj7VCnHXn0-7gr1b2CeuZyJW0PvUultBCu8IAFOWINBvhQ2u_b1URH6Fs_MI_P6jN551VrBxSYjEKEhBf08hzwZ3fXu4zMRhhIpMfGhR75rfrvBBpTtlS9AwJ2JpIeCrMBA"};
121+
NSDictionary *expectedRequestParams = @{@"pagetoken": @"CoQCAAEAACUEBVd58EGiJKFOe1KoEFks9jia46vhv6Bi4sR0ExZaFgvu6XqK2xgB6RXYqdWX1QP26UlcCR7DGiBwhH2-FN528X9J-CUH0JjUxauAzJjuxhyyxt946AW1ETRqecANfJdZ5_cjRwhR-0qQ13HeiQaB_riQPMG4SAqKcb8OMcHMtSJrJUacIIifXTNyxJpEbP8dvETT-pDM-0zl9qmTO0aqGdmz0EzyPAEuMCmZEMUI0gnZJvvDvaar_L4KCL6bhjGFqs5OrW-DIn1Vo5CI8bVD4VRINLdxAk7ovLOxT04p1M9qo6JNJ5ZZYntyX2MC64SvIe2RtFIGDGy046xJho4SECVEEiNhLUaQw1_2dUSO4zUaFKqr08lGcqbMqGhRJ9VG69t6YMgj"};
122122
XCTAssertEqualObjects([nextPageRequest placesAPIRequestParams], expectedRequestParams, @"pageToken returned by nextPageRequest: is wrong");
123123
}
124124

@@ -132,7 +132,7 @@ - (void)testParsingRealResponseOK
132132

133133
XCTAssertNotNil(response, @"response should not be nil");
134134
XCTAssertEqual(response.status, FTGooglePlacesAPIResponseStatusOK, @"status should be FTGooglePlacesAPIResponseStatusOK");
135-
XCTAssertEqualObjects(response.nextPageToken, @"CmRbAAAAPRe43WuMoqKDiLcauzH5NR5Agm6U5pqiP5gPALHlvKSe89bdGpjNj7VCnHXn0-7gr1b2CeuZyJW0PvUultBCu8IAFOWINBvhQ2u_b1URH6Fs_MI_P6jN551VrBxSYjEKEhBf08hzwZ3fXu4zMRhhIpMfGhR75rfrvBBpTtlS9AwJ2JpIeCrMBA", @"nextPageToken is wrong");
135+
XCTAssertEqualObjects(response.nextPageToken, @"CoQCAAEAACUEBVd58EGiJKFOe1KoEFks9jia46vhv6Bi4sR0ExZaFgvu6XqK2xgB6RXYqdWX1QP26UlcCR7DGiBwhH2-FN528X9J-CUH0JjUxauAzJjuxhyyxt946AW1ETRqecANfJdZ5_cjRwhR-0qQ13HeiQaB_riQPMG4SAqKcb8OMcHMtSJrJUacIIifXTNyxJpEbP8dvETT-pDM-0zl9qmTO0aqGdmz0EzyPAEuMCmZEMUI0gnZJvvDvaar_L4KCL6bhjGFqs5OrW-DIn1Vo5CI8bVD4VRINLdxAk7ovLOxT04p1M9qo6JNJ5ZZYntyX2MC64SvIe2RtFIGDGy046xJho4SECVEEiNhLUaQw1_2dUSO4zUaFKqr08lGcqbMqGhRJ9VG69t6YMgj", @"nextPageToken is wrong");
136136
XCTAssertNotNil([response nextPageRequest], @"nextPageRequest should not be nil");
137137

138138
XCTAssertEqual([response.results count], (NSUInteger)20, @"response should have 20 results items");

XcodeProject/FTGooglePlacesAPILogicTests/Source/FTGooglePlacesAPISearchResultItemTests.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ - (void)testParsingFromManualDictionary
4343
}
4444
],
4545
@"rating": @(3.6),
46+
@"place_id": @"ChIJyWEHuEmuEmsRm9hTkapTCrk",
4647
@"reference": @"CoQBgAAAAFjx_1xLA2D3kuZ83rCChllMEaGrxSeoPh6",
4748
@"types": @[@"museum", @"establishment"],
4849
@"vicinity": @"1st Floor, Riverside Building, County Hall, London"
@@ -52,7 +53,7 @@ - (void)testParsingFromManualDictionary
5253
FTGooglePlacesAPISearchResultItem *item = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:dictionary];
5354
XCTAssertNotNil(item, @"Initialiazation should succeed");
5455

55-
XCTAssertEqualObjects(item.itemId, @"5139d09fbccf4c974fce66f7d88269c149bac0a5", @"itemId is wrong");
56+
XCTAssertEqualObjects(item.placeId, @"ChIJyWEHuEmuEmsRm9hTkapTCrk", @"placeId is wrong");
5657
XCTAssertEqualObjects(item.name, @"London Film Museum South Bank", @"name is wrong");
5758

5859
XCTAssertNotNil(item.location, @"location should be non-nil");
@@ -74,8 +75,8 @@ - (void)testParsingFromManualDictionary
7475

7576
- (void)testVeryBasicObjectWithJustId
7677
{
77-
FTGooglePlacesAPISearchResultItem *item = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:@{@"id": @"someValue"}];
78-
XCTAssertNotNil(item, @"item should be valid once it has id");
78+
FTGooglePlacesAPISearchResultItem *item = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:@{@"place_id": @"someValue"}];
79+
XCTAssertNotNil(item, @"item should be valid once it has placeId");
7980

8081
item = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:@{}];
8182
XCTAssertNil(item, @"item should be nil when no id is provided");
@@ -86,17 +87,17 @@ - (void)testVeryBasicObjectWithJustId
8687

8788
- (void)testEqualityChecking
8889
{
89-
NSDictionary *dictionary1a = @{@"id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
90-
NSDictionary *dictionary1b = @{@"id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
90+
NSDictionary *dictionary1a = @{@"place_id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
91+
NSDictionary *dictionary1b = @{@"place_id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
9192

9293
FTGooglePlacesAPISearchResultItem *item1a = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:dictionary1a];
9394
FTGooglePlacesAPISearchResultItem *item1b = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:dictionary1b];
9495

9596
XCTAssertEqualObjects(item1a, item1b, @"object are not considered to be equal, but should be");
9697

9798

98-
NSDictionary *dictionary2a = @{@"id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
99-
NSDictionary *dictionary2b = @{@"id": @"XAXAGFKANGOKANOAOGNAOGOIANGOI AOAANGO"};
99+
NSDictionary *dictionary2a = @{@"place_id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
100+
NSDictionary *dictionary2b = @{@"place_id": @"XAXAGFKANGOKANOAOGNAOGOIANGOI AOAANGO"};
100101

101102
FTGooglePlacesAPISearchResultItem *item2a = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:dictionary2a];
102103
FTGooglePlacesAPISearchResultItem *item2b = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:dictionary2b];
@@ -106,7 +107,7 @@ - (void)testEqualityChecking
106107

107108
- (void)testEmptyValues
108109
{
109-
NSDictionary *dictionary = @{@"id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
110+
NSDictionary *dictionary = @{@"place_id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"};
110111

111112
FTGooglePlacesAPISearchResultItem *item = [[FTGooglePlacesAPISearchResultItem alloc] initWithDictionary:dictionary];
112113

@@ -119,7 +120,7 @@ - (void)testEmptyValues
119120
XCTAssertNil(item.reference, @"reference should be nil");
120121
XCTAssertNil(item.types, @"types should be nil");
121122

122-
XCTAssertEqualObjects(item.originalDictionaryRepresentation, @{@"id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"}, @"originalDictionaryRepresentation is wrong");
123+
XCTAssertEqualObjects(item.originalDictionaryRepresentation, @{@"place_id": @"5139d09fbccf4c974fce66f7d88269c149bac0a5"}, @"originalDictionaryRepresentation is wrong");
123124
}
124125

125126
@end

0 commit comments

Comments
 (0)