Skip to content

Commit 4cacf71

Browse files
committed
Sandbox support
1 parent eb16fd9 commit 4cacf71

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

AFeedly/AFLAppDelegate.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ @implementation AFLAppDelegate
1313

1414
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1515
{
16-
[[AFLClient sharedClient] initWithApplicationId:@"sandbox" andSecret:@"0AUDIAHZEB0ISJ1JLFWZ"];
16+
[[AFLClient createSharedClient:YES] initWithApplicationId:@"sandbox" andSecret:@"0AUDIAHZEB0ISJ1JLFWZ"];
1717
[[AFLClient sharedClient] setIsSyncWithServer:YES];
1818
return YES;
1919
}

Source/AFLClient.h

+4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ typedef enum {
3333
AFContentTypeCategory
3434
} AFContentType;
3535

36+
3637
@interface AFLClient : AFHTTPClient <LROAuth2ClientDelegate>
3738

39+
3840
@property (nonatomic,strong) LROAuth2Client *oauthClient;
3941

4042
@property (nonatomic,strong) NSString *applicationId;
4143
@property (nonatomic,strong) NSString *secretKey;
4244
@property (nonatomic,strong) AFProfile *profile;
4345
@property (nonatomic,assign) BOOL isSyncWithServer;
46+
@property (nonatomic,assign) BOOL isInSandbox;
4447

48+
+ (instancetype)createSharedClient:(BOOL)inSandbox;
4549
+ (instancetype) sharedClient;
4650
- (void)initWithApplicationId:(NSString*)appId andSecret:(NSString*)secret;
4751
- (BOOL)isAuthenticated;

Source/AFLClient.m

+22-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@
1212
#import <LROAuth2Client/LROAuth2AccessToken.h>
1313

1414

15-
static NSString * const kFeedlyAPIBaseURLString = @"http://sandbox.feedly.com/v3";
16-
static NSString * const kFeedlyUserURLString = @"http://sandbox.feedly.com/v3/auth/auth";
17-
static NSString * const kFeedlyTokenURLString = @"http://sandbox.feedly.com/v3/auth/token";
15+
static NSString * const kFeedlyAPIBaseURLString = @"http://cloud.feedly.com/v3";
16+
static NSString * const kFeedlyUserURLString = @"http://cloud.feedly.com/v3/auth/auth";
17+
static NSString * const kFeedlyTokenURLString = @"http://cloud.feedly.com/v3/auth/token";
18+
19+
static NSString * const kFeedlySandboxAPIBaseURLString = @"http://sandbox.feedly.com/v3";
20+
static NSString * const kFeedlySandboxUserURLString = @"http://sandbox.feedly.com/v3/auth/auth";
21+
static NSString * const kFeedlySandboxTokenURLString = @"http://sandbox.feedly.com/v3/auth/token";
22+
23+
static id _sharedInstance = nil;
24+
static dispatch_once_t onceToken;
1825

1926
@interface AFLClient ()
2027
@property (strong) AFeedlyAuthenticationBlock authenticationResultBlock;
@@ -26,9 +33,17 @@ @implementation AFLClient
2633

2734
#pragma mark - Initialization
2835

36+
+ (instancetype)createSharedClient:(BOOL)inSandbox
37+
{
38+
dispatch_once(&onceToken, ^{
39+
_sharedInstance = [[self alloc] initWithBaseURL:[NSURL URLWithString:(inSandbox)?kFeedlySandboxAPIBaseURLString:kFeedlyAPIBaseURLString]];
40+
[(AFLClient*)_sharedInstance setIsInSandbox:inSandbox];
41+
});
42+
43+
return _sharedInstance;
44+
}
45+
2946
+ (instancetype) sharedClient {
30-
static id _sharedInstance = nil;
31-
static dispatch_once_t onceToken;
3247
dispatch_once(&onceToken, ^{
3348
_sharedInstance = [[self alloc] initWithBaseURL:[NSURL URLWithString:kFeedlyAPIBaseURLString]];
3449
});
@@ -102,8 +117,8 @@ - (void)authenticateUsingWebview:(UIWebView*)webView
102117
_oauthClient.delegate = self;
103118
_oauthClient.debug = NO;
104119

105-
_oauthClient.userURL = [NSURL URLWithString:kFeedlyUserURLString];
106-
_oauthClient.tokenURL = [NSURL URLWithString:kFeedlyTokenURLString];
120+
_oauthClient.userURL = [NSURL URLWithString:(_isInSandbox)?kFeedlySandboxUserURLString:kFeedlyUserURLString];
121+
_oauthClient.tokenURL = [NSURL URLWithString:(_isInSandbox)?kFeedlySandboxTokenURLString:kFeedlyTokenURLString];
107122

108123
if ([self.token hasExpired]) {
109124
[_oauthClient refreshAccessToken:self.token];

0 commit comments

Comments
 (0)