Skip to content

Commit aaa161b

Browse files
committed
Merge pull request #207 from derrh/master
Maybe not critical, but good housekeeping?
2 parents 1f8d5c1 + 75322e5 commit aaa161b

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

CanvasKit.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = 'CanvasKit'
3-
s.version = '0.6.48'
3+
s.version = '0.6.49'
44
s.license = 'MIT'
55
s.summary = 'A Canvas API integration framework better than bamboo'
66
s.homepage = 'https://github.com/instructure/CanvasKit'
77
s.authors = { 'Rick Roberts' => 'elgreco84@gmail.com', 'Jason Larsen' => 'jason.larsen@gmail.com' }
8-
s.source = { :git => 'https://github.com/instructure/CanvasKit.git', :tag => '0.6.48' }
8+
s.source = { :git => 'https://github.com/instructure/CanvasKit.git', :tag => '0.6.49' }
99
s.requires_arc = true
1010

1111
s.ios.deployment_target = '7.0'

CanvasKit/Networking/CKIClient.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import <ReactiveCocoa/ReactiveCocoa.h>
99
#import <AFNetworking/AFHTTPRequestOperation.h>
1010
#import <Mantle/Mantle.h>
11+
#import <Mantle/EXTScope.h>
1112

1213
#import "CKIClient.h"
1314
#import "CKIClient+CKIUser.h"
@@ -27,6 +28,7 @@ @interface CKIClient ()
2728
@property (nonatomic, strong) NSString *clientSecret;
2829
@property (nonatomic, strong) NSString *accessToken;
2930
@property (nonatomic, strong) CKIUser *currentUser;
31+
@property (nonatomic, assign) BOOL invalidated;
3032

3133
#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE
3234
@property (nonatomic, weak) UIViewController *webLoginViewController;
@@ -46,6 +48,13 @@ - (instancetype)initWithBaseURL:(NSURL *)url
4648

4749
[self setRequestSerializer:[AFJSONRequestSerializer serializer]];
4850
[self setResponseSerializer:[AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments]];
51+
52+
@weakify(self);
53+
[self setSessionDidBecomeInvalidBlock:^(NSURLSession *session, NSError *error) {
54+
@strongify(self);
55+
56+
self.invalidated = true;
57+
}];
4958
}
5059
return self;
5160
}
@@ -89,6 +98,11 @@ - (id)copyWithZone:(NSZone *)zone
8998
dup.accessToken = self.accessToken;
9099
dup.currentUser = [self.currentUser copy];
91100
dup.actAsUserID = self.actAsUserID;
101+
@weakify(dup);
102+
[self setSessionDidBecomeInvalidBlock:^(NSURLSession *session, NSError *error) {
103+
@strongify(dup);
104+
dup.invalidated = true;
105+
}];
92106
return dup;
93107
}
94108

@@ -250,6 +264,11 @@ - (RACSignal *)fetchResponseAtPath:(NSString *)path parameters:(NSDictionary *)p
250264
NSDictionary *newParameters = [@{@"per_page": @50} dictionaryByAddingObjectsFromDictionary:parameters];
251265

252266
return [[[RACSignal createSignal:^RACDisposable *(id <RACSubscriber> subscriber) {
267+
if (self.invalidated) {
268+
[subscriber sendCompleted];
269+
return [RACDisposable disposableWithBlock:^{}];
270+
}
271+
253272
NSDictionary *finalParameters = newParameters;
254273
if ([self.actAsUserID length]) {
255274
finalParameters = [@{@"as_user_id": self.actAsUserID} dictionaryByAddingObjectsFromDictionary:finalParameters];
@@ -359,6 +378,11 @@ - (RACSignal *)createModelAtPath:(NSString *)path parameters:(NSDictionary *)par
359378
NSAssert([modelClass isSubclassOfClass:[CKIModel class]], @"Can only create CKIModels");
360379

361380
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
381+
if (self.invalidated) {
382+
[subscriber sendCompleted];
383+
return [RACDisposable disposableWithBlock:^{}];
384+
}
385+
362386
NSURLSessionDataTask *task = [self POST:path parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
363387

364388
NSString *jsonContentKey = [modelClass keyForJSONAPIContent];
@@ -383,6 +407,11 @@ - (RACSignal *)createModelAtPath:(NSString *)path parameters:(NSDictionary *)par
383407
- (RACSignal *)updateModel:(CKIModel *)model parameters:(NSDictionary *)parameters
384408
{
385409
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
410+
if (self.invalidated) {
411+
[subscriber sendCompleted];
412+
return [RACDisposable disposableWithBlock:^{}];
413+
}
414+
386415
NSURLSessionDataTask *task = [self PUT:model.path parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
387416
Class modelClass = model.class;
388417
NSAssert([modelClass isSubclassOfClass:[CKIModel class]], @"Can only create CKIModels");

0 commit comments

Comments
 (0)