From 15bc0a651a10ad4efa1dc4114513f467d4f12d4c Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Tue, 6 May 2014 17:21:42 +0300 Subject: [PATCH 1/9] Added photos to FTGooglePlacesAPISearchResultItem and FTGooglePlacesAPIDetailResponse --- FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h | 3 ++- FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h index cf2059d..8714fd5 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h @@ -85,7 +85,8 @@ @property (nonatomic, strong, readonly) NSString *internationalPhoneNumber; @property (nonatomic, strong, readonly) NSString *iconImageUrl; -@property (nonatomic, assign, readonly) CGFloat rating; +@property (nonatomic, assign, readonly) float rating; +@property (nonatomic, strong) NSArray *photos; /** * Contains a unique token that you can use to retrieve additional information diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h index cdcbc0a..e992629 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h +++ b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h @@ -52,10 +52,10 @@ typedef NS_ENUM(NSUInteger, FTGooglePlacesAPISearchResultItemOpenedState) { @property (nonatomic, strong, readonly) NSString *addressString; // "vicinity" from the response @property (nonatomic, assign, readonly) FTGooglePlacesAPISearchResultItemOpenedState openedState; @property (nonatomic, strong, readonly) NSString *iconImageUrl; -@property (nonatomic, assign, readonly) CGFloat rating; +@property (nonatomic, assign, readonly) float rating; @property (nonatomic, strong, readonly) NSString *reference; @property (nonatomic, strong, readonly) NSArray *types; - +@property (nonatomic, strong) NSArray *photos; /** * You can access complete response dictionary using this property. * In case implementation changes in a future and there will be new values From 4cae7bed0ca0c73b944500e3ed89b408bec788f6 Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Thu, 15 May 2014 21:13:13 +0300 Subject: [PATCH 2/9] completed parsing of photos --- FTGooglePlacesAPI/FTGooglePlacePhotoItem.h | 17 +++++++++++++++++ FTGooglePlacesAPI/FTGooglePlacePhotoItem.m | 13 +++++++++++++ .../FTGooglePlacesAPIDetailResponse.m | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 FTGooglePlacesAPI/FTGooglePlacePhotoItem.h create mode 100644 FTGooglePlacesAPI/FTGooglePlacePhotoItem.m diff --git a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h new file mode 100644 index 0000000..f2f12f7 --- /dev/null +++ b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h @@ -0,0 +1,17 @@ +// +// FTGooglePlacePhotoItem.h +// Aniways +// +// Created by Danny Shmueli on 5/15/14. +// Copyright (c) 2014 Ram Greenberg. All rights reserved. +// + +#import + +@interface FTGooglePlacePhotoItem : NSObject + +@property (nonatomic, strong) NSArray *htmlAttributions; +@property (nonatomic, copy) NSString *photoReference; +@property (nonatomic) NSInteger height, width; + +@end diff --git a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m new file mode 100644 index 0000000..4369673 --- /dev/null +++ b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m @@ -0,0 +1,13 @@ +// +// FTGooglePlacePhotoItem.m +// Aniways +// +// Created by Danny Shmueli on 5/15/14. +// Copyright (c) 2014 Ram Greenberg. All rights reserved. +// + +#import "FTGooglePlacePhotoItem.h" + +@implementation FTGooglePlacePhotoItem + +@end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m index c6f09ea..c0fd42b 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m @@ -31,6 +31,7 @@ #import "FTGooglePlacesAPIDetailResponse.h" #import "FTGooglePlacesAPICommon.h" +#import "FTGooglePlacePhotoItem.h" @interface FTGooglePlacesAPIDetailResponse (Private) @@ -103,6 +104,23 @@ - (void)ftgp_importDictionary:(NSDictionary *)dictionary _websiteUrl = [NSURL URLWithString:[dictionary ftgp_nilledObjectForKey:@"website"]]; _utcOffset = [[dictionary ftgp_nilledObjectForKey:@"utc_offset"] doubleValue]; + + NSArray *photos = [dictionary ftgp_nilledObjectForKey:@"photos"]; + if (photos) + { + NSMutableArray *photosArray = [NSMutableArray arrayWithCapacity:photos.count]; + for (NSDictionary *photoDic in photos) { + FTGooglePlacePhotoItem *photo = [FTGooglePlacePhotoItem new]; + photo.photoReference = photoDic[@"photo_reference"]; + photo.htmlAttributions = photoDic[@"html_attributions"]; + photo.height = [[photoDic ftgp_nilledObjectForKey:@"height"] floatValue]; + photo.width = [[photoDic ftgp_nilledObjectForKey:@"width"] floatValue]; + + [photosArray addObject:photo]; + } + _photos = photosArray; + } + } @end \ No newline at end of file From a72466e2070c9584194dd4f6e8d03152891e7ce8 Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Fri, 16 May 2014 16:22:23 +0300 Subject: [PATCH 3/9] added reviews parsing for PlaceDetailsResponse --- FTGooglePlacesAPI/FTGooglePlaceReviewItem.h | 16 ++++++++++++++++ FTGooglePlacesAPI/FTGooglePlaceReviewItem.m | 13 +++++++++++++ .../FTGooglePlacesAPIDetailResponse.h | 1 + .../FTGooglePlacesAPIDetailResponse.m | 14 ++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 FTGooglePlacesAPI/FTGooglePlaceReviewItem.h create mode 100644 FTGooglePlacesAPI/FTGooglePlaceReviewItem.m diff --git a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h new file mode 100644 index 0000000..17967ee --- /dev/null +++ b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h @@ -0,0 +1,16 @@ +// +// FTGooglePlaceReviewItem.h +// Aniways +// +// Created by Danny Shmueli on 5/15/14. +// Copyright (c) 2014 Ram Greenberg. All rights reserved. +// + +#import + +@interface FTGooglePlaceReviewItem : NSObject + +@property (nonatomic, copy) NSString *authorName, *authorURL, *reviewBody; +@property (nonatomic) float rating; + +@end diff --git a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.m b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.m new file mode 100644 index 0000000..f2fa103 --- /dev/null +++ b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.m @@ -0,0 +1,13 @@ +// +// FTGooglePlaceReviewItem.m +// Aniways +// +// Created by Danny Shmueli on 5/15/14. +// Copyright (c) 2014 Ram Greenberg. All rights reserved. +// + +#import "FTGooglePlaceReviewItem.h" + +@implementation FTGooglePlaceReviewItem + +@end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h index 8714fd5..2d5bbb0 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h @@ -87,6 +87,7 @@ @property (nonatomic, strong, readonly) NSString *iconImageUrl; @property (nonatomic, assign, readonly) float rating; @property (nonatomic, strong) NSArray *photos; +@property (nonatomic, strong) NSArray *reviews; /** * Contains a unique token that you can use to retrieve additional information diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m index c0fd42b..7300a00 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m @@ -32,6 +32,7 @@ #import "FTGooglePlacesAPICommon.h" #import "FTGooglePlacePhotoItem.h" +#import "FTGooglePlaceReviewItem.h" @interface FTGooglePlacesAPIDetailResponse (Private) @@ -121,6 +122,19 @@ - (void)ftgp_importDictionary:(NSDictionary *)dictionary _photos = photosArray; } + NSArray *reviews = [dictionary ftgp_nilledObjectForKey:@"reviews"]; + if (reviews) + { + NSMutableArray *reviewsArray = [NSMutableArray arrayWithCapacity:reviews.count]; + for (NSDictionary *reviewDic in reviews) { + FTGooglePlaceReviewItem *review = [FTGooglePlaceReviewItem new]; + review.authorName = [reviewDic ftgp_nilledObjectForKey:@"author_name"]; + review.authorURL = [reviewDic ftgp_nilledObjectForKey:@"author_url"]; + review.reviewBody = [reviewDic ftgp_nilledObjectForKey:@"text"]; + [reviewsArray addObject:review]; + } + _reviews = reviewsArray; + } } @end \ No newline at end of file From d5a1ebe114a139a24f4c3f1d174ba63ee88cdb01 Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Fri, 16 May 2014 16:22:23 +0300 Subject: [PATCH 4/9] added reviews parsing for PlaceDetailsResponse --- FTGooglePlacesAPI/FTGooglePlaceReviewItem.h | 1 + FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m | 2 ++ 2 files changed, 3 insertions(+) diff --git a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h index 17967ee..a423560 100644 --- a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h +++ b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h @@ -12,5 +12,6 @@ @property (nonatomic, copy) NSString *authorName, *authorURL, *reviewBody; @property (nonatomic) float rating; +@property (nonatomic) NSInteger time; @end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m index 7300a00..606d0f5 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m @@ -131,6 +131,8 @@ - (void)ftgp_importDictionary:(NSDictionary *)dictionary review.authorName = [reviewDic ftgp_nilledObjectForKey:@"author_name"]; review.authorURL = [reviewDic ftgp_nilledObjectForKey:@"author_url"]; review.reviewBody = [reviewDic ftgp_nilledObjectForKey:@"text"]; + review.rating = [[reviewDic ftgp_nilledObjectForKey:@"rating"] doubleValue]; + review.time = [[reviewDic ftgp_nilledObjectForKey:@"time"] doubleValue]; [reviewsArray addObject:review]; } _reviews = reviewsArray; From 3f90eb2d1cf3286534652d9603cb8867aff97f70 Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Fri, 16 May 2014 18:41:16 +0300 Subject: [PATCH 5/9] added isJSONRequest to protocol: GooglePlacesAPIRequest implemented new method in all requests. (returned YES) --- FTGooglePlacesAPI/FTGooglePlacesAPICommon.h | 8 ++++++++ FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.m | 5 +++++ FTGooglePlacesAPI/FTGooglePlacesAPIDictionaryRequest.m | 5 +++++ FTGooglePlacesAPI/FTGooglePlacesAPINearbySearchRequest.m | 5 +++++ FTGooglePlacesAPI/FTGooglePlacesAPIService.m | 7 +++++-- FTGooglePlacesAPI/FTGooglePlacesAPITextSearchRequest.m | 4 ++++ 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPICommon.h b/FTGooglePlacesAPI/FTGooglePlacesAPICommon.h index e409190..c890840 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPICommon.h +++ b/FTGooglePlacesAPI/FTGooglePlacesAPICommon.h @@ -61,6 +61,14 @@ extern NSString * const FTGooglePlacesAPIErrorDomain; */ - (NSDictionary *)placesAPIRequestParams; +/** + * Most of the request are asking for JSON response from the API. + * Some requests - like GoogleAPIPhotoRequest do not. + * + * @return BOOL YES if the request requires JSON. + */ +- (BOOL)isJSONRequest; + @end // Utilities diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.m b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.m index 85c8bb4..cc65e41 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.m @@ -67,4 +67,9 @@ - (NSDictionary *)placesAPIRequestParams return @{@"reference": _reference}; } +-(BOOL)isJSONRequest +{ + return YES; +} + @end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDictionaryRequest.m b/FTGooglePlacesAPI/FTGooglePlacesAPIDictionaryRequest.m index ade8173..507c4da 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDictionaryRequest.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDictionaryRequest.m @@ -66,4 +66,9 @@ - (NSDictionary *)placesAPIRequestParams return _placesAPIRequestParams; } +-(BOOL)isJSONRequest +{ + return YES; +} + @end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPINearbySearchRequest.m b/FTGooglePlacesAPI/FTGooglePlacesAPINearbySearchRequest.m index 6a3fcc6..7563091 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPINearbySearchRequest.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPINearbySearchRequest.m @@ -163,6 +163,11 @@ - (NSDictionary *)placesAPIRequestParams return [params copy]; } +-(BOOL)isJSONRequest +{ + return YES; +} + @end #pragma mark - Private methods category diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIService.m b/FTGooglePlacesAPI/FTGooglePlacesAPIService.m index e131bca..6080b04 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIService.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIService.m @@ -236,8 +236,11 @@ + (void)executeRequest:(id)request // Create relative request path // Places API base URL is already configured in AFNetworking HTTP manager - NSString *requestPath = [NSString stringWithFormat:@"%@/json", [request placesAPIRequestMethod]]; - + NSString *requestPath = [request placesAPIRequestMethod]; + if ([request isJSONRequest]) + { + requestPath = [requestPath stringByAppendingString:@"/json"]; + } // Perform request using AFNetworking AFHTTPRequestOperationManager *manager = service.httpRequestOperationManager; diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPITextSearchRequest.m b/FTGooglePlacesAPI/FTGooglePlacesAPITextSearchRequest.m index c35ce6c..6ecb3d5 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPITextSearchRequest.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPITextSearchRequest.m @@ -149,4 +149,8 @@ - (NSDictionary *)placesAPIRequestParams return [params copy]; } +-(BOOL)isJSONRequest +{ + return YES; +} @end From b48e201b4b1f4889ce33379b31dffdce5736de56 Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Fri, 16 May 2014 19:06:07 +0300 Subject: [PATCH 6/9] added photo request and PhotoItem executes the request. --- FTGooglePlacesAPI/FTGooglePlacePhotoItem.h | 3 + FTGooglePlacesAPI/FTGooglePlacePhotoItem.m | 12 ++++ .../FTGooglePlacesAPIPhotoRequest.h | 21 +++++++ .../FTGooglePlacesAPIPhotoRequest.m | 60 +++++++++++++++++++ FTGooglePlacesAPI/FTGooglePlacesAPIService.h | 12 ++++ FTGooglePlacesAPI/FTGooglePlacesAPIService.m | 26 ++++++++ 6 files changed, 134 insertions(+) create mode 100644 FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.h create mode 100644 FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.m diff --git a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h index f2f12f7..bbe7ed5 100644 --- a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h +++ b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h @@ -7,6 +7,7 @@ // #import +@class UIImage; @interface FTGooglePlacePhotoItem : NSObject @@ -14,4 +15,6 @@ @property (nonatomic, copy) NSString *photoReference; @property (nonatomic) NSInteger height, width; +-(void)resolveImage:(void(^)(UIImage *))completion; + @end diff --git a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m index 4369673..049e22c 100644 --- a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m +++ b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m @@ -7,7 +7,19 @@ // #import "FTGooglePlacePhotoItem.h" +#import "FTGooglePlacesAPIService.h" +#import "FTGooglePlacesAPIPhotoRequest.h" @implementation FTGooglePlacePhotoItem +-(void)resolveImage:(void(^)(UIImage *))completion +{ + FTGooglePlacesAPIPhotoRequest *photoRequest =[[FTGooglePlacesAPIPhotoRequest alloc] initWithReference:self.photoReference maxWidth:@(1600) maxHeight:nil]; + + [FTGooglePlacesAPIService executePhotoRequest:photoRequest withCompletionHandler:^(UIImage *image, NSError *error) + { + completion(image); + }]; +} + @end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.h b/FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.h new file mode 100644 index 0000000..a19da99 --- /dev/null +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.h @@ -0,0 +1,21 @@ +// +// FTGooglePlacesAPIPhotoRequest.h +// Aniways +// +// Created by Danny Shmueli on 5/16/14. +// Copyright (c) 2014 Ram Greenberg. All rights reserved. +// + +#import + +#import "FTGooglePlacesAPICommon.h" + +@interface FTGooglePlacesAPIPhotoRequest : NSObject + + +@property (nonatomic, copy, readonly) NSString *reference; +@property (nonatomic, strong, readonly) NSNumber *maxHeight, *maxWidth; + +- (instancetype)initWithReference:(NSString *)reference maxWidth:(NSNumber *)maxWidth maxHeight:(NSNumber *)maxHeight; + +@end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.m b/FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.m new file mode 100644 index 0000000..0313cdc --- /dev/null +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.m @@ -0,0 +1,60 @@ +// +// FTGooglePlacesAPIPhotoRequest.m +// Aniways +// +// Created by Danny Shmueli on 5/16/14. +// Copyright (c) 2014 Ram Greenberg. All rights reserved. +// + +#import "FTGooglePlacesAPIPhotoRequest.h" + +@implementation FTGooglePlacesAPIPhotoRequest + +- (instancetype)initWithReference:(NSString *)reference maxWidth:(NSNumber *)maxWidth maxHeight:(NSNumber *)maxHeight +{ + if ([reference length] == 0) { + NSLog(@"WARNING: Trying to create FTGooglePlacesAPIDetailRequest with empty reference. Returning nil"); + return nil; + } + + self = [super init]; + if (self) { + _reference = reference; + _maxHeight = maxHeight; + _maxWidth = maxWidth; + } + return self; +} + +#pragma mark - Superclass overrides + +- (NSString *)description +{ + return [NSString stringWithFormat:@"<%@: %p> Reference: %@", [self class], self, self.reference]; +} + +#pragma mark - FTGooglePlacesAPIRequest protocol + +- (NSString *)placesAPIRequestMethod +{ + return @"photo"; +} + +- (NSDictionary *)placesAPIRequestParams +{ + NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:self.reference forKey:@"photoreference"]; + if (self.maxHeight) + [params setObject:self.maxHeight forKey:@"maxheight"]; + + if (self.maxWidth) + [params setObject:self.maxWidth forKey:@"maxwidth"]; + + return params; +} + +-(BOOL)isJSONRequest +{ + return NO; +} + +@end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIService.h b/FTGooglePlacesAPI/FTGooglePlacesAPIService.h index efa1cb8..04df9b4 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIService.h +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIService.h @@ -29,6 +29,7 @@ #import #import "FTGooglePlacesAPICommon.h" +@class UIImage; @class FTGooglePlacesAPISearchResponse; @class FTGooglePlacesAPIDetailResponse; @@ -39,6 +40,8 @@ typedef void (^FTGooglePlacesAPISearchRequestCompletionHandler)(FTGooglePlacesAP typedef void (^FTGooglePlacesAPIDetailRequestCompletionhandler)(FTGooglePlacesAPIDetailResponse *response, NSError *error); +typedef void (^FTGooglePlacesAPIPhotoRequestCompletionhandler)(UIImage *response, NSError *error); + /** * This class provides encapsulated functionality for communication with Google Places API */ @@ -86,6 +89,15 @@ typedef void (^FTGooglePlacesAPIDetailRequestCompletionhandler)(FTGooglePlacesAP + (void)executeDetailRequest:(id)request withCompletionHandler:(FTGooglePlacesAPIDetailRequestCompletionhandler)completion; +/** + * Asks the service to execute the given Google Places API Photo request. + * + * @param request Request object implementing FTGooglePlacesAPIRequest protocol. This will probably be instance of FTGooglePlacesAPIPhotoRequest, but you are free to provide own request implementing requred FTGooglePlacesAPIRequest protocol + * @param completion Completion block to be called after the request was finished. If everything went without problems, response will be non-nill and error will be nil. In case of failure, response will be nil and error will be either AFNetworking error caused by networking problem or error with FTGooglePlacesAPIErrorDomain domain indicating that the networking request was successfull, but Google Places API responded with non-OK status code + */ ++ (void)executePhotoRequest:(id)request + withCompletionHandler:(FTGooglePlacesAPIPhotoRequestCompletionhandler)completion; + /** * If set to YES and running in debug mode (#ifdef DEBUG), service will print some information * info console, including: diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIService.m b/FTGooglePlacesAPI/FTGooglePlacesAPIService.m index 6080b04..f523647 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIService.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIService.m @@ -209,6 +209,22 @@ + (void)executeDetailRequest:(id)request }]; } ++ (void)executePhotoRequest:(id)request + withCompletionHandler:(FTGooglePlacesAPIPhotoRequestCompletionhandler)completion +{ + [[self class] executeRequest:request withCompletionHandler:^(id responseObject, NSError *error) { + + // Networing, parsing or other general error + if (error) { + completion(nil, error); + return; + } + + completion(responseObject, nil); + }]; +} + + + (void)setDebugLoggingEnabled:(BOOL)enabled { FTGooglePlacesAPIDebugLoggingEnabled = enabled; @@ -244,6 +260,16 @@ + (void)executeRequest:(id)request // Perform request using AFNetworking AFHTTPRequestOperationManager *manager = service.httpRequestOperationManager; + //Set the manager responseSerializer to AFImageResponseSerializer in case not JSON Request. + if ([request isJSONRequest]) + { + manager.responseSerializer = [AFJSONResponseSerializer serializer]; + } + else + { + manager.responseSerializer = [AFImageResponseSerializer serializer]; + } + // Perform request [manager GET:requestPath parameters:params From 5b874a804fc7c79210bd0b156716565231eb31d5 Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Sun, 18 May 2014 13:04:46 +0300 Subject: [PATCH 7/9] nicer parsing of photos and reviews --- FTGooglePlacesAPI/FTGooglePlacePhotoItem.h | 2 ++ FTGooglePlacesAPI/FTGooglePlacePhotoItem.m | 14 ++++++++++++++ FTGooglePlacesAPI/FTGooglePlaceReviewItem.h | 3 +++ FTGooglePlacesAPI/FTGooglePlaceReviewItem.m | 16 ++++++++++++++++ .../FTGooglePlacesAPIDetailResponse.m | 13 ++----------- .../FTGooglePlacesAPISearchResultItem.m | 13 +++++++++++++ 6 files changed, 50 insertions(+), 11 deletions(-) diff --git a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h index bbe7ed5..48a30e6 100644 --- a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h +++ b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.h @@ -17,4 +17,6 @@ -(void)resolveImage:(void(^)(UIImage *))completion; +-(id)initWithDictionary:(NSDictionary *)dictionary; + @end diff --git a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m index 049e22c..e89ddbb 100644 --- a/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m +++ b/FTGooglePlacesAPI/FTGooglePlacePhotoItem.m @@ -12,6 +12,20 @@ @implementation FTGooglePlacePhotoItem +-(id)initWithDictionary:(NSDictionary *)dictionary +{ + self = [super init]; + if (!self) + return nil; + + self.photoReference = dictionary[@"photo_reference"]; + self.htmlAttributions = dictionary[@"html_attributions"]; + self.height = [[dictionary ftgp_nilledObjectForKey:@"height"] floatValue]; + self.width = [[dictionary ftgp_nilledObjectForKey:@"width"] floatValue]; + + return self; +} + -(void)resolveImage:(void(^)(UIImage *))completion { FTGooglePlacesAPIPhotoRequest *photoRequest =[[FTGooglePlacesAPIPhotoRequest alloc] initWithReference:self.photoReference maxWidth:@(1600) maxHeight:nil]; diff --git a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h index a423560..6ab681f 100644 --- a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h +++ b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.h @@ -14,4 +14,7 @@ @property (nonatomic) float rating; @property (nonatomic) NSInteger time; + +-(id)initWithDictionary:(NSDictionary *)dictionary; + @end diff --git a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.m b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.m index f2fa103..6aa615d 100644 --- a/FTGooglePlacesAPI/FTGooglePlaceReviewItem.m +++ b/FTGooglePlacesAPI/FTGooglePlaceReviewItem.m @@ -7,7 +7,23 @@ // #import "FTGooglePlaceReviewItem.h" +#import "FTGooglePlacesAPICommon.h" @implementation FTGooglePlaceReviewItem +-(id)initWithDictionary:(NSDictionary *)dictionary +{ + self = [super init]; + if (!self) + return nil; + + self.authorName = [dictionary ftgp_nilledObjectForKey:@"author_name"]; + self.authorURL = [dictionary ftgp_nilledObjectForKey:@"author_url"]; + self.reviewBody = [dictionary ftgp_nilledObjectForKey:@"text"]; + self.rating = [[dictionary ftgp_nilledObjectForKey:@"rating"] doubleValue]; + self.time = [[dictionary ftgp_nilledObjectForKey:@"time"] doubleValue]; + + return self; +} + @end diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m index 606d0f5..741e16d 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m @@ -111,12 +111,8 @@ - (void)ftgp_importDictionary:(NSDictionary *)dictionary { NSMutableArray *photosArray = [NSMutableArray arrayWithCapacity:photos.count]; for (NSDictionary *photoDic in photos) { - FTGooglePlacePhotoItem *photo = [FTGooglePlacePhotoItem new]; - photo.photoReference = photoDic[@"photo_reference"]; - photo.htmlAttributions = photoDic[@"html_attributions"]; - photo.height = [[photoDic ftgp_nilledObjectForKey:@"height"] floatValue]; - photo.width = [[photoDic ftgp_nilledObjectForKey:@"width"] floatValue]; + FTGooglePlacePhotoItem *photo = [[FTGooglePlacePhotoItem alloc] initWithDictionary:photoDic]; [photosArray addObject:photo]; } _photos = photosArray; @@ -127,12 +123,7 @@ - (void)ftgp_importDictionary:(NSDictionary *)dictionary { NSMutableArray *reviewsArray = [NSMutableArray arrayWithCapacity:reviews.count]; for (NSDictionary *reviewDic in reviews) { - FTGooglePlaceReviewItem *review = [FTGooglePlaceReviewItem new]; - review.authorName = [reviewDic ftgp_nilledObjectForKey:@"author_name"]; - review.authorURL = [reviewDic ftgp_nilledObjectForKey:@"author_url"]; - review.reviewBody = [reviewDic ftgp_nilledObjectForKey:@"text"]; - review.rating = [[reviewDic ftgp_nilledObjectForKey:@"rating"] doubleValue]; - review.time = [[reviewDic ftgp_nilledObjectForKey:@"time"] doubleValue]; + FTGooglePlaceReviewItem *review = [[FTGooglePlaceReviewItem alloc] initWithDictionary: reviewDic]; [reviewsArray addObject:review]; } _reviews = reviewsArray; diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m index 4771d39..86da29e 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m @@ -28,6 +28,7 @@ #import "FTGooglePlacesAPISearchResultItem.h" #import "FTGooglePlacesAPICommon.h" +#import "FTGooglePlacePhotoItem.h" /** * Private methods interface @@ -148,6 +149,18 @@ - (void)ftgpi_importDictionary:(NSDictionary *)dictionary _rating = [[dictionary ftgp_nilledObjectForKey:@"rating"] floatValue]; _reference = [dictionary ftgp_nilledObjectForKey:@"reference"]; _types = [dictionary ftgp_nilledObjectForKey:@"types"]; + + NSArray *photos = [dictionary ftgp_nilledObjectForKey:@"photos"]; + if (photos) + { + NSMutableArray *photosArray = [NSMutableArray arrayWithCapacity:photos.count]; + for (NSDictionary *photoDic in photos) { + + FTGooglePlacePhotoItem *photo = [[FTGooglePlacePhotoItem alloc] initWithDictionary:photoDic]; + [photosArray addObject:photo]; + } + _photos = photosArray; + } } @end From 0e47f3baff7a3005bdc934ea0f615855d788b228 Mon Sep 17 00:00:00 2001 From: Ram Greenberg Date: Tue, 1 Jul 2014 17:14:25 +0300 Subject: [PATCH 8/9] set NSURLRequestReturnCacheDataElseLoad as cache policy --- FTGooglePlacesAPI/FTGooglePlacesAPIService.m | 1 + 1 file changed, 1 insertion(+) diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPIService.m b/FTGooglePlacesAPI/FTGooglePlacesAPIService.m index f523647..2392482 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPIService.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPIService.m @@ -270,6 +270,7 @@ + (void)executeRequest:(id)request manager.responseSerializer = [AFImageResponseSerializer serializer]; } + manager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad; // Perform request [manager GET:requestPath parameters:params From 5d584277a26af8aeebf6abd4a003959d4b7d6a18 Mon Sep 17 00:00:00 2001 From: Danny Shmueli Date: Tue, 12 Aug 2014 17:46:21 +0300 Subject: [PATCH 9/9] added formatted address property also to FTGooglePlacesAPISearchResultItem --- FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h | 1 + FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m | 1 + 2 files changed, 2 insertions(+) diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h index e992629..0d60f9b 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h +++ b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h @@ -50,6 +50,7 @@ typedef NS_ENUM(NSUInteger, FTGooglePlacesAPISearchResultItemOpenedState) { @property (nonatomic, strong, readonly) CLLocation *location; @property (nonatomic, strong, readonly) NSString *addressString; // "vicinity" from the response +@property (nonatomic, strong, readonly) NSString *formattedAddress; @property (nonatomic, assign, readonly) FTGooglePlacesAPISearchResultItemOpenedState openedState; @property (nonatomic, strong, readonly) NSString *iconImageUrl; @property (nonatomic, assign, readonly) float rating; diff --git a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m index 86da29e..4a1490b 100644 --- a/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m +++ b/FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m @@ -136,6 +136,7 @@ - (void)ftgpi_importDictionary:(NSDictionary *)dictionary } _addressString = [dictionary ftgp_nilledObjectForKey:@"vicinity"]; + _formattedAddress = [dictionary ftgp_nilledObjectForKey:@"formatted_address"]; // Openeed state may or may not be present NSNumber *openedState = [dictionary ftgp_nilledValueForKeyPath:@"opening_hours.open_now"];