Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Classes/Client/YLPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern NSString *const kYLPAPIHost;
@interface YLPClient : NSObject

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

+ (void)authorizeWithAppId:(NSString *)appId
secret:(NSString *)secret
Expand Down
12 changes: 6 additions & 6 deletions Classes/Client/YLPClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ - (NSURLRequest *)requestWithPath:(NSString *)path params:(NSDictionary *)params
urlComponents.scheme = @"https";
urlComponents.host = kYLPAPIHost;
urlComponents.path = path;

NSArray *queryItems = [YLPClient queryItemsForParams:params];
if (queryItems.count > 0) {
urlComponents.queryItems = queryItems;
}

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlComponents.URL];
request.HTTPMethod = @"GET";
NSString *authHeader = [NSString stringWithFormat:@"Bearer %@", self.accessToken];
[request setValue:authHeader forHTTPHeaderField:@"Authorization"];

return request;
}

Expand Down Expand Up @@ -110,19 +110,19 @@ + (NSURLRequest *)authRequestWithAppId:(NSString *)appId secret:(NSString *)secr
urlComponents.scheme = @"https";
urlComponents.host = kYLPAPIHost;
urlComponents.path = @"/oauth2/token";

NSCharacterSet *allowedCharacters = [self URLEncodeAllowedCharacters];
NSString *body = [NSString stringWithFormat:@"grant_type=client_credentials&client_id=%@&client_secret=%@",
[appId stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters],
[secret stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters]];
NSData *bodyData = [body dataUsingEncoding:NSUTF8StringEncoding];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:urlComponents.URL];
request.HTTPMethod = @"POST";
request.HTTPBody = bodyData;
[request setValue:[NSString stringWithFormat:@"%zd", bodyData.length] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

return request;
}

Expand Down
10 changes: 6 additions & 4 deletions Classes/Common/YLPCoordinate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
//
//

#import <Foundation/Foundation.h>
#import "YLPBaseObject.h"

NS_ASSUME_NONNULL_BEGIN

@interface YLPCoordinate : NSObject
@interface YLPCoordinate : YLPBaseObject

@property (nonatomic, readonly) double latitude;
@property (nonatomic, readonly) double longitude;

- (instancetype)initWithLatitude:(double)latitude longitude:(double)longitude;
- (instancetype)initWithLatitude:(double)latitude longitude:(double)longitude NS_DESIGNATED_INITIALIZER;

- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions Classes/Request/YLPGeoBoundingBox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// GeoBoundingBox.h
// Pods
//
// Created by David Chen on 1/22/16.
//
//

#import "YLPBaseObject.h"

@class YLPCoordinate;

NS_ASSUME_NONNULL_BEGIN

@interface YLPGeoBoundingBox : YLPBaseObject

@property (nonatomic, copy, readonly) YLPCoordinate *southwestCoordinate;
@property (nonatomic, copy, readonly) YLPCoordinate *northeastCoordinate;

- (instancetype)initWithSouthWestLongitude:(double)southwestLongitude
southWestLatitude:(double)southwestLatitude
northEastLatitude:(double)northeastLatitude
northEastLongitude:(double)northeastLongitude NS_DESIGNATED_INITIALIZER;

- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
32 changes: 32 additions & 0 deletions Classes/Request/YLPGeoCoordinate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// YLPGeoCoordinate.h
// Pods
//
// Created by David Chen on 1/25/16.
//
//

#import "YLPBaseObject.h"

@class YLPCoordinate;

NS_ASSUME_NONNULL_BEGIN

@interface YLPGeoCoordinate : YLPBaseObject

@property (nonatomic, copy, readonly) YLPCoordinate *coordinate;
@property (nonatomic, readonly) double accuracy;
@property (nonatomic, readonly) double altitude;
@property (nonatomic, readonly) double altitudeAccuracy;

- (instancetype)initWithLatitude:(double)latitude
longitude:(double)longitude
accuracy:(double)accuracy
altitude:(double)altitude
altitudeAccuracy:(double)altitudeAccuracy NS_DESIGNATED_INITIALIZER;

- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
10 changes: 6 additions & 4 deletions Classes/Request/YLPQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@
//
//

#import <Foundation/Foundation.h>
#import "YLPBaseObject.h"
#import "YLPSortType.h"

@class YLPCoordinate;

NS_ASSUME_NONNULL_BEGIN

@interface YLPQuery : NSObject
@interface YLPQuery : YLPBaseObject

/**
Initializes a query with a location specified by text.
@param location the particular neighborhood, address or city to search in
*/
- (instancetype)initWithLocation:(NSString *)location;
- (instancetype)initWithLocation:(NSString *)location NS_DESIGNATED_INITIALIZER;

/**
Initializes a query with a location specified by a coordinate.
@param coordinate coordinate around which to search
*/
- (instancetype)initWithCoordinate:(YLPCoordinate *)coordinate;
- (instancetype)initWithCoordinate:(YLPCoordinate *)coordinate NS_DESIGNATED_INITIALIZER;

- (instancetype)init NS_UNAVAILABLE;

/**
Search term (e.g. "food", "restaurants"). If term is nil, everything will be searched.
Expand Down
15 changes: 15 additions & 0 deletions Classes/Response/YLPBaseObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// YLPBaseObject.h
// YelpAPI
//
// Created by Brian Sharrief Alim Bowman on 11/7/16.
//
//

@import Foundation;

@interface YLPBaseObject : NSObject

+ (instancetype)new NS_UNAVAILABLE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I hadn't even thought about +new... is it necessary to annotate both -init and +new? i.e. will Swift still let you call things like YLPBusiness() if -init is unavailable but +new is still available?

I'm learning new things about swift interop all the time 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I typically do to avoid unwanted initializers if we want to force users building on top of the API to use a certain initializer. I'm open to leaving it available but for the objective c people it may avoid unwanted confusion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a fair point, I guess I was thinking mainly that YLPBaseObject seems a little odd as a class with no functionality.

I'm debating whether it's worth it or if it'd be fine to just copy-paste this + (instancetype)new NS_UNAVAILABLE line everywhere... the convenience of only having to write it once is pretty nice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea its a pet peeve of mine to write the same code all over the place. I can adjust it however you like. The base may come in handy later if other functionality comes up that will be shared. I'll review the API changes and update sometime between tonight and tomorrow. Just let me know about other changes you like, i'll be happy to make them!


@end
13 changes: 13 additions & 0 deletions Classes/Response/YLPBaseObject.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// YLPBaseObject.m
// YelpAPI
//
// Created by Brian Sharrief Alim Bowman on 11/7/16.
//
//

#import "YLPBaseObject.h"

@implementation YLPBaseObject

@end
6 changes: 4 additions & 2 deletions Classes/Response/YLPBusiness.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
//
//

#import <Foundation/Foundation.h>
#import "YLPBaseObject.h"

@class YLPLocation;
@class YLPCategory;

NS_ASSUME_NONNULL_BEGIN

@interface YLPBusiness : NSObject
@interface YLPBusiness : YLPBaseObject

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic, getter=isClosed, readonly) BOOL closed;

Expand Down
8 changes: 5 additions & 3 deletions Classes/Response/YLPCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
//
//

#import <Foundation/Foundation.h>
#import "YLPBaseObject.h"

NS_ASSUME_NONNULL_BEGIN

@interface YLPCategory : NSObject
@interface YLPCategory : YLPBaseObject

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic, readonly, copy) NSString *name;
@property (nonatomic, readonly, copy) NSString *alias;

@end

NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
22 changes: 22 additions & 0 deletions Classes/Response/YLPCoordinateDelta.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// YLPCoordinateDelta.h
// Pods
//
// Created by David Chen on 1/20/16.
//
//

#import "YLPBaseObject.h"

NS_ASSUME_NONNULL_BEGIN

@interface YLPCoordinateDelta : YLPBaseObject

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic, readonly) double latitudeDelta;
@property (nonatomic, readonly) double longitudeDelta;

@end

NS_ASSUME_NONNULL_END
38 changes: 38 additions & 0 deletions Classes/Response/YLPDeal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// YLPDeal.h
// Pods
//
// Created by David Chen on 1/15/16.
//
//

#import "YLPBaseObject.h"

@class YLPDealOption;

NS_ASSUME_NONNULL_BEGIN

@interface YLPDeal : YLPBaseObject

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic, copy, readonly) NSString *identifier;
@property (nonatomic, copy, readonly) NSString *title;
@property (nonatomic, copy, readonly) NSString *currencyCode;
@property (nonatomic, copy, readonly) NSString *whatYouGet;
@property (nonatomic, copy, readonly) NSString *additionalRestrictions;
@property (nonatomic, copy, nullable, readonly) NSString *importantRestrictions;

@property (nonatomic, copy, readonly) NSURL *URL;
@property (nonatomic, copy, readonly) NSURL *imageURL;

@property (nonatomic, copy, readonly) NSDate *timeStart;
@property (nonatomic, copy, nullable, readonly) NSDate *timeEnd;

@property (nonatomic, getter=isPopular, readonly) BOOL popular;

@property (nonatomic, copy, readonly) NSArray<YLPDealOption *> *options;

@end

NS_ASSUME_NONNULL_END
31 changes: 31 additions & 0 deletions Classes/Response/YLPDealOption.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// YLPDealOption.h
// Pods
//
// Created by David Chen on 1/15/16.
//
//

#import "YLPBaseObject.h"

NS_ASSUME_NONNULL_BEGIN

@interface YLPDealOption : YLPBaseObject

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic, copy, readonly) NSString *title;
@property (nonatomic, copy, readonly) NSString *formattedPrice;
@property (nonatomic, copy, readonly) NSString *formattedOriginalPrice;

@property (nonatomic, copy, readonly) NSURL *purchaseURL;

@property (nonatomic, readonly) NSUInteger price;
@property (nonatomic, readonly) NSUInteger originalPrice;
@property (nonatomic, copy, nullable, readonly) NSNumber *remainingCount;

@property (nonatomic, getter=isQuantityLimited, readonly) BOOL quantityLimited;

@end

NS_ASSUME_NONNULL_END
34 changes: 34 additions & 0 deletions Classes/Response/YLPGiftCertificate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// YLPGiftCertificate.h
// Pods
//
// Created by David Chen on 1/13/16.
//
//

#import "YLPBaseObject.h"

@class YLPGiftCertificateOption;

typedef NS_ENUM(NSInteger, YLPBalanceType) {
YLPBalanceTypeCash,
YLPBalanceTypeCredit
};

NS_ASSUME_NONNULL_BEGIN

@interface YLPGiftCertificate : YLPBaseObject

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic, copy, readonly) NSString *identifier;
@property (nonatomic, copy, readonly) NSString *currencyCode;
@property (nonatomic, readonly) YLPBalanceType unusedBalances;

@property (nonatomic, copy, readonly) NSURL *URL;
@property (nonatomic, copy, readonly) NSURL *imageURL;

@property (nonatomic, copy, readonly) NSArray<YLPGiftCertificateOption *> *options;
@end

NS_ASSUME_NONNULL_END
22 changes: 22 additions & 0 deletions Classes/Response/YLPGiftCertificateOption.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// YLPGiftCertificateOption.h
// Pods
//
// Created by David Chen on 1/14/16.
//
//

#import "YLPBaseObject.h"

NS_ASSUME_NONNULL_BEGIN

@interface YLPGiftCertificateOption : YLPBaseObject

- (instancetype)init NS_UNAVAILABLE;

@property (nonatomic, readonly) NSUInteger price;
@property (nonatomic, copy, readonly) NSString *formattedPrice;

@end

NS_ASSUME_NONNULL_END
Loading