Skip to content
22 changes: 22 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacePhotoItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// FTGooglePlacePhotoItem.h
// Aniways
//
// Created by Danny Shmueli on 5/15/14.
// Copyright (c) 2014 Ram Greenberg. All rights reserved.
//

#import <Foundation/Foundation.h>
@class UIImage;

@interface FTGooglePlacePhotoItem : NSObject

@property (nonatomic, strong) NSArray *htmlAttributions;
@property (nonatomic, copy) NSString *photoReference;
@property (nonatomic) NSInteger height, width;

-(void)resolveImage:(void(^)(UIImage *))completion;

-(id)initWithDictionary:(NSDictionary *)dictionary;

@end
39 changes: 39 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacePhotoItem.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// FTGooglePlacePhotoItem.m
// Aniways
//
// Created by Danny Shmueli on 5/15/14.
// Copyright (c) 2014 Ram Greenberg. All rights reserved.
//

#import "FTGooglePlacePhotoItem.h"
#import "FTGooglePlacesAPIService.h"
#import "FTGooglePlacesAPIPhotoRequest.h"

@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];

[FTGooglePlacesAPIService executePhotoRequest:photoRequest withCompletionHandler:^(UIImage *image, NSError *error)
{
completion(image);
}];
}

@end
20 changes: 20 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlaceReviewItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// FTGooglePlaceReviewItem.h
// Aniways
//
// Created by Danny Shmueli on 5/15/14.
// Copyright (c) 2014 Ram Greenberg. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface FTGooglePlaceReviewItem : NSObject

@property (nonatomic, copy) NSString *authorName, *authorURL, *reviewBody;
@property (nonatomic) float rating;
@property (nonatomic) NSInteger time;


-(id)initWithDictionary:(NSDictionary *)dictionary;

@end
29 changes: 29 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlaceReviewItem.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// FTGooglePlaceReviewItem.m
// Aniways
//
// Created by Danny Shmueli on 5/15/14.
// Copyright (c) 2014 Ram Greenberg. All rights reserved.
//

#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
8 changes: 8 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPICommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPIDetailRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ - (NSDictionary *)placesAPIRequestParams
return @{@"reference": _reference};
}

-(BOOL)isJSONRequest
{
return YES;
}

@end
4 changes: 3 additions & 1 deletion FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
@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;
@property (nonatomic, strong) NSArray *reviews;

/**
* Contains a unique token that you can use to retrieve additional information
Expand Down
25 changes: 25 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPIDetailResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#import "FTGooglePlacesAPIDetailResponse.h"

#import "FTGooglePlacesAPICommon.h"
#import "FTGooglePlacePhotoItem.h"
#import "FTGooglePlaceReviewItem.h"

@interface FTGooglePlacesAPIDetailResponse (Private)

Expand Down Expand Up @@ -103,6 +105,29 @@ - (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 alloc] initWithDictionary:photoDic];
[photosArray addObject:photo];
}
_photos = photosArray;
}

NSArray *reviews = [dictionary ftgp_nilledObjectForKey:@"reviews"];
if (reviews)
{
NSMutableArray *reviewsArray = [NSMutableArray arrayWithCapacity:reviews.count];
for (NSDictionary *reviewDic in reviews) {
FTGooglePlaceReviewItem *review = [[FTGooglePlaceReviewItem alloc] initWithDictionary: reviewDic];
[reviewsArray addObject:review];
}
_reviews = reviewsArray;
}
}

@end
5 changes: 5 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPIDictionaryRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ - (NSDictionary *)placesAPIRequestParams
return _placesAPIRequestParams;
}

-(BOOL)isJSONRequest
{
return YES;
}

@end
5 changes: 5 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPINearbySearchRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ - (NSDictionary *)placesAPIRequestParams
return [params copy];
}

-(BOOL)isJSONRequest
{
return YES;
}

@end

#pragma mark - Private methods category
Expand Down
21 changes: 21 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// FTGooglePlacesAPIPhotoRequest.h
// Aniways
//
// Created by Danny Shmueli on 5/16/14.
// Copyright (c) 2014 Ram Greenberg. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "FTGooglePlacesAPICommon.h"

@interface FTGooglePlacesAPIPhotoRequest : NSObject <FTGooglePlacesAPIRequest>


@property (nonatomic, copy, readonly) NSString *reference;
@property (nonatomic, strong, readonly) NSNumber *maxHeight, *maxWidth;

- (instancetype)initWithReference:(NSString *)reference maxWidth:(NSNumber *)maxWidth maxHeight:(NSNumber *)maxHeight;

@end
60 changes: 60 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPIPhotoRequest.m
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ 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) 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
Expand Down
14 changes: 14 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPISearchResultItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#import "FTGooglePlacesAPISearchResultItem.h"
#import "FTGooglePlacesAPICommon.h"
#import "FTGooglePlacePhotoItem.h"

/**
* Private methods interface
Expand Down Expand Up @@ -135,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"];
Expand All @@ -148,6 +150,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
12 changes: 12 additions & 0 deletions FTGooglePlacesAPI/FTGooglePlacesAPIService.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import <Foundation/Foundation.h>

#import "FTGooglePlacesAPICommon.h"
@class UIImage;

@class FTGooglePlacesAPISearchResponse;
@class FTGooglePlacesAPIDetailResponse;
Expand All @@ -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
*/
Expand Down Expand Up @@ -86,6 +89,15 @@ typedef void (^FTGooglePlacesAPIDetailRequestCompletionhandler)(FTGooglePlacesAP
+ (void)executeDetailRequest:(id<FTGooglePlacesAPIRequest>)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<FTGooglePlacesAPIRequest>)request
withCompletionHandler:(FTGooglePlacesAPIPhotoRequestCompletionhandler)completion;

/**
* If set to YES and running in debug mode (#ifdef DEBUG), service will print some information
* info console, including:
Expand Down
Loading