Permalink
Browse files

Add default to the production API

  • Loading branch information...
1 parent e6a61fb commit 333205cd17ef0c451add56d6c70d5ab48503df27 @soffes soffes committed Jul 26, 2012
View
@@ -27,6 +27,10 @@ extern NSString *const kCDKAPIScheme;
extern NSString *const kCDKAPIHost;
extern NSString *const kCDKPusherAPIKey;
+extern NSString *const kCDKDevelopmentAPIScheme;
+extern NSString *const kCDKDevelopmentAPIHost;
+extern NSString *const kCDKDevelopmentPusherAPIKey;
+
#pragma mark - User Defaults Keys
View
@@ -10,15 +10,13 @@
#pragma mark - API
-#if IN_PRODUCTION
NSString *const kCDKAPIScheme = @"https";
NSString *const kCDKAPIHost = @"api.cheddarapp.com";
NSString *const kCDKPusherAPIKey = @"675f10a650f18b4eb0a8";
-#else
-NSString *const kCDKAPIScheme = @"http";
-NSString *const kCDKAPIHost = @"localhost:5000";
-NSString *const kCDKPusherAPIKey = @"a02cb793e9d5fb919023";
-#endif
+
+NSString *const kCDKDevelopmentAPIScheme = @"http";
+NSString *const kCDKDevelopmentAPIHost = @"localhost:5000";
+NSString *const kCDKDevelopmentPusherAPIKey = @"a02cb793e9d5fb919023";
#pragma mark - User Defaults Keys
@@ -19,6 +19,8 @@ typedef void (^CDKHTTPClientFailure)(AFJSONRequestOperation *operation, NSError
@interface CDKHTTPClient : AFHTTPClient
+ (CDKHTTPClient *)sharedClient;
++ (void)setDevelopmentModeEnabled:(BOOL)enabled;
++ (NSString *)apiVersion;
- (void)setClientID:(NSString *)clientID secret:(NSString *)clientSecret;
- (void)changeUser:(CDKUser *)user;
View
@@ -13,6 +13,8 @@
#import "CDKDefines.h"
#import <Bully/Bully.h>
+static BOOL __developmentMode = NO;
+
@interface CDKHTTPClient ()
- (void)_userChanged:(NSNotification *)notification;
@end
@@ -35,10 +37,27 @@ + (CDKHTTPClient *)sharedClient {
}
++ (void)setDevelopmentModeEnabled:(BOOL)enabled {
+ __developmentMode = enabled;
+}
+
+
++ (NSString *)apiVersion {
+ return @"v1";
+}
+
+
#pragma mark - NSObject
- (id)init {
- NSURL *base = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/v1/", kCDKAPIScheme, kCDKAPIHost]];
+ NSURL *base = nil;
+ NSString *version = [[self class] apiVersion];
+ if (__developmentMode) {
+ base = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@/", kCDKDevelopmentAPIScheme, kCDKDevelopmentAPIHost, version]];
+ } else {
+ base = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@/", kCDKAPIScheme, kCDKAPIHost, version]];
+ }
+
if ((self = [super initWithBaseURL:base])) {
// Use JSON
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
@@ -17,5 +17,6 @@
@property (nonatomic, strong, readonly) BLYChannel *userChannel;
+ (CDKPushController *)sharedController;
++ (void)setDevelopmentModeEnabled:(BOOL)enabled;
@end
@@ -15,6 +15,8 @@
#import <Bully/Bully.h>
#import "Reachability.h"
+static BOOL __developmentMode = NO;
+
@interface CDKPushController () <BLYClientDelegate>
@property (nonatomic, strong, readwrite) BLYClient *client;
@property (nonatomic, strong, readwrite) BLYChannel *userChannel;
@@ -129,11 +131,16 @@ + (CDKPushController *)sharedController {
}
++ (void)setDevelopmentModeEnabled:(BOOL)enabled {
+ __developmentMode = enabled;
+}
+
+
#pragma mark - NSObject
- (id)init {
if ((self = [super init])) {
- _client = [[BLYClient alloc] initWithAppKey:kCDKPusherAPIKey delegate:self];
+ _client = [[BLYClient alloc] initWithAppKey:(__developmentMode ? kCDKDevelopmentPusherAPIKey : kCDKPusherAPIKey) delegate:self];
self.userID = [CDKUser currentUser].remoteID.description;

0 comments on commit 333205c

Please sign in to comment.