Skip to content

Commit 3c94980

Browse files
committed
Merge pull request octokit#43 from octokit/octclient-enqueuerequest-cleanup
Clean up the NSURLRequest creation and enqueueing methods.
2 parents aed8528 + 9a0733b commit 3c94980

File tree

8 files changed

+213
-122
lines changed

8 files changed

+213
-122
lines changed

OctoKit.xcodeproj/project.pbxproj

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@
224224
D0D8C09E16DFF1540070399E /* rate_limit.json in Resources */ = {isa = PBXBuildFile; fileRef = D0D8C09416DFF1540070399E /* rate_limit.json */; };
225225
D0E41B8716DFF37E00E321CF /* notifications.json in Resources */ = {isa = PBXBuildFile; fileRef = D0E41B8616DFF37E00E321CF /* notifications.json */; };
226226
D0E41B8816DFF37E00E321CF /* notifications.json in Resources */ = {isa = PBXBuildFile; fileRef = D0E41B8616DFF37E00E321CF /* notifications.json */; };
227+
F6CF78D416E993A500A75F63 /* RACSignal+OCTClientAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = F6CF78D216E993A500A75F63 /* RACSignal+OCTClientAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
228+
F6CF78D516E993A500A75F63 /* RACSignal+OCTClientAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = F6CF78D216E993A500A75F63 /* RACSignal+OCTClientAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
229+
F6CF78D616E993A500A75F63 /* RACSignal+OCTClientAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = F6CF78D316E993A500A75F63 /* RACSignal+OCTClientAdditions.m */; };
230+
F6CF78D816E993A500A75F63 /* RACSignal+OCTClientAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = F6CF78D316E993A500A75F63 /* RACSignal+OCTClientAdditions.m */; };
231+
F6E2EC4016EB04C60096C268 /* RACSignalAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = F6E2EC3F16EB04C50096C268 /* RACSignalAdditionsSpec.m */; };
232+
F6E2EC4116EB04C60096C268 /* RACSignalAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = F6E2EC3F16EB04C50096C268 /* RACSignalAdditionsSpec.m */; };
227233
/* End PBXBuildFile section */
228234

229235
/* Begin PBXContainerItemProxy section */
@@ -461,7 +467,7 @@
461467
D0872109169E35DE00016ACA /* Specta.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Specta.xcodeproj; path = External/Mantle/MantleTests/specta/Specta.xcodeproj; sourceTree = "<group>"; };
462468
D0872124169E365A00016ACA /* OctoKitTests-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "OctoKitTests-Prefix.pch"; sourceTree = "<group>"; };
463469
D0872127169E395F00016ACA /* OCTClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCTClient.h; sourceTree = "<group>"; };
464-
D0872128169E395F00016ACA /* OCTClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCTClient.m; sourceTree = "<group>"; };
470+
D0872128169E395F00016ACA /* OCTClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCTClient.m; sourceTree = "<group>"; usesTabs = 1; };
465471
D0872129169E395F00016ACA /* OCTCommitComment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCTCommitComment.h; sourceTree = "<group>"; };
466472
D087212A169E395F00016ACA /* OCTCommitComment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCTCommitComment.m; sourceTree = "<group>"; };
467473
D087212B169E395F00016ACA /* OCTCommitCommentEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCTCommitCommentEvent.h; sourceTree = "<group>"; };
@@ -537,6 +543,9 @@
537543
D0D8C09316DFF1540070399E /* page3.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = page3.json; sourceTree = "<group>"; };
538544
D0D8C09416DFF1540070399E /* rate_limit.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = rate_limit.json; sourceTree = "<group>"; };
539545
D0E41B8616DFF37E00E321CF /* notifications.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = notifications.json; sourceTree = "<group>"; };
546+
F6CF78D216E993A500A75F63 /* RACSignal+OCTClientAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RACSignal+OCTClientAdditions.h"; sourceTree = "<group>"; };
547+
F6CF78D316E993A500A75F63 /* RACSignal+OCTClientAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RACSignal+OCTClientAdditions.m"; sourceTree = "<group>"; };
548+
F6E2EC3F16EB04C50096C268 /* RACSignalAdditionsSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RACSignalAdditionsSpec.m; sourceTree = "<group>"; };
540549
/* End PBXFileReference section */
541550

542551
/* Begin PBXFrameworksBuildPhase section */
@@ -626,6 +635,7 @@
626635
D0871EA9169E2EFC00016ACA /* Products */,
627636
);
628637
sourceTree = "<group>";
638+
usesTabs = 1;
629639
};
630640
D0871EA9169E2EFC00016ACA /* Products */ = {
631641
isa = PBXGroup;
@@ -851,6 +861,7 @@
851861
children = (
852862
D0B9C8FC16BC7A260029C5B4 /* NSDateFormatterAdditionsSpec.m */,
853863
D0772E7B16BD2AD5009DFF72 /* NSValueTransformerAdditionsSpec.m */,
864+
F6E2EC3F16EB04C50096C268 /* RACSignalAdditionsSpec.m */,
854865
D05E751F16D35886001AA17B /* OCTClientSpec.m */,
855866
D08721BD169E396F00016ACA /* OCTCommitCommentSpec.m */,
856867
D08721BE169E396F00016ACA /* OCTEventSpec.m */,
@@ -988,6 +999,8 @@
988999
D0B9C8F116BC78970029C5B4 /* NSDateFormatter+OCTFormattingAdditions.m */,
9891000
D0772E7516BD2A05009DFF72 /* NSValueTransformer+OCTPredefinedTransformerAdditions.h */,
9901001
D0772E7616BD2A06009DFF72 /* NSValueTransformer+OCTPredefinedTransformerAdditions.m */,
1002+
F6CF78D216E993A500A75F63 /* RACSignal+OCTClientAdditions.h */,
1003+
F6CF78D316E993A500A75F63 /* RACSignal+OCTClientAdditions.m */,
9911004
);
9921005
name = Extensions;
9931006
sourceTree = "<group>";
@@ -1050,6 +1063,7 @@
10501063
8848E19D16AF630B005449AB /* OCTNotification.h in Headers */,
10511064
D0772E7316BD27B5009DFF72 /* NSDateFormatter+OCTFormattingAdditions.h in Headers */,
10521065
D0772E7716BD2A06009DFF72 /* NSValueTransformer+OCTPredefinedTransformerAdditions.h in Headers */,
1066+
F6CF78D416E993A500A75F63 /* RACSignal+OCTClientAdditions.h in Headers */,
10531067
);
10541068
runOnlyForDeploymentPostprocessing = 0;
10551069
};
@@ -1095,6 +1109,7 @@
10951109
8848E19E16AF630B005449AB /* OCTNotification.h in Headers */,
10961110
D0772E7416BD27B6009DFF72 /* NSDateFormatter+OCTFormattingAdditions.h in Headers */,
10971111
D0772E7816BD2A06009DFF72 /* NSValueTransformer+OCTPredefinedTransformerAdditions.h in Headers */,
1112+
F6CF78D516E993A500A75F63 /* RACSignal+OCTClientAdditions.h in Headers */,
10981113
);
10991114
runOnlyForDeploymentPostprocessing = 0;
11001115
};
@@ -1439,6 +1454,7 @@
14391454
8848E19F16AF630B005449AB /* OCTNotification.m in Sources */,
14401455
D0B9C8F416BC78970029C5B4 /* NSDateFormatter+OCTFormattingAdditions.m in Sources */,
14411456
D0772E7916BD2A06009DFF72 /* NSValueTransformer+OCTPredefinedTransformerAdditions.m in Sources */,
1457+
F6CF78D616E993A500A75F63 /* RACSignal+OCTClientAdditions.m in Sources */,
14421458
);
14431459
runOnlyForDeploymentPostprocessing = 0;
14441460
};
@@ -1459,6 +1475,7 @@
14591475
D0B9C8FD16BC7A260029C5B4 /* NSDateFormatterAdditionsSpec.m in Sources */,
14601476
D0772E7C16BD2AD5009DFF72 /* NSValueTransformerAdditionsSpec.m in Sources */,
14611477
D05E752016D35886001AA17B /* OCTClientSpec.m in Sources */,
1478+
F6E2EC4016EB04C60096C268 /* RACSignalAdditionsSpec.m in Sources */,
14621479
);
14631480
runOnlyForDeploymentPostprocessing = 0;
14641481
};
@@ -1503,6 +1520,7 @@
15031520
8848E1A016AF630B005449AB /* OCTNotification.m in Sources */,
15041521
D0B9C8F516BC78970029C5B4 /* NSDateFormatter+OCTFormattingAdditions.m in Sources */,
15051522
D0772E7A16BD2A06009DFF72 /* NSValueTransformer+OCTPredefinedTransformerAdditions.m in Sources */,
1523+
F6CF78D816E993A500A75F63 /* RACSignal+OCTClientAdditions.m in Sources */,
15061524
);
15071525
runOnlyForDeploymentPostprocessing = 0;
15081526
};
@@ -1523,6 +1541,7 @@
15231541
D0B9C8FE16BC7A260029C5B4 /* NSDateFormatterAdditionsSpec.m in Sources */,
15241542
D0772E7D16BD2AD5009DFF72 /* NSValueTransformerAdditionsSpec.m in Sources */,
15251543
D05E752116D35886001AA17B /* OCTClientSpec.m in Sources */,
1544+
F6E2EC4116EB04C60096C268 /* RACSignalAdditionsSpec.m in Sources */,
15261545
);
15271546
runOnlyForDeploymentPostprocessing = 0;
15281547
};

OctoKit/OCTClient.h

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -108,61 +108,41 @@ extern NSString * const OCTClientErrorHTTPStatusCodeKey;
108108
// Returns a new client.
109109
+ (instancetype)unauthenticatedClientWithUser:(OCTUser *)user;
110110

111-
// Enqueues a request that always fetches the latest data from the server.
111+
// Creates a mutable URL request, which when sent will conditionally fetch the
112+
// latest data from the server. If the latest data matches `etag`, nothing is
113+
// downloaded and the call does not count toward the API rate limit.
114+
//
115+
// method - The HTTP method to use in the request
116+
// (e.g., "GET" or "POST").
117+
// path - The path to request, relative to the base API endpoint.
118+
// This path should _not_ begin with a forward slash.
119+
// parameters - HTTP parameters to encode and send with the request.
120+
// notMatchingEtag - An ETag to compare the server data against, previously
121+
// retrieved from an instance of OCTResponse. If the content
122+
// has not changed since, no new data will be fetched when
123+
// this request is sent. This argument may be nil to always
124+
// fetch the latest data.
125+
//
126+
// Returns an NSMutableURLRequest that you can enqueue using
127+
// -enqueueRequest:resultClass:.
128+
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters notMatchingEtag:(NSString *)etag;
129+
130+
// Enqueues a request to be sent to the server.
112131
//
113132
// This will automatically fetch all pages of the given endpoint. Each object
114133
// from each page will be sent independently on the returned signal, so
115134
// subscribers don't have to know or care about this pagination behavior.
116135
//
117-
// To stop fetching pages, simply dispose of all subscriptions to the signal.
136+
// request - The previously constructed URL request for the endpoint.
137+
// resultClass - A subclass of OCTObject that the response data should be
138+
// returned as, and will be accessible from the parsedResult
139+
// property on each OCTResponse. If this is nil, NSDictionary
140+
// will be used for each object in the JSON received.
118141
//
119-
// method - The HTTP method to use in the request (e.g., "GET" or "POST").
120-
// path - The path to request, relative to the base API endpoint. This
121-
// path should _not_ begin with a forward slash.
122-
// parameters - HTTP parameters to encode and send with the request.
123-
// resultClass - A subclass of OCTObject that the response data should be
124-
// returned as. If this is nil, the returned signal will send an
125-
// NSDictionary for each object in the JSON received.
126-
//
127-
// Returns a signal which will send an instance of `resultClass` for each parsed
142+
// Returns a signal which will send an instance of `OCTResponse` for each parsed
128143
// JSON object, then complete. If an error occurs at any point, the returned
129144
// signal will send it immediately, then terminate.
130-
- (RACSignal *)enqueueRequestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters resultClass:(Class)resultClass;
131-
132-
// Enqueues a request which will conditionally fetch the latest data from the
133-
// server. If the latest data matches `etag`, nothing is downloaded and the call
134-
// does not count toward the API rate limit.
135-
//
136-
// If the latest data does not match `etag`, this will automatically fetch all
137-
// pages of the given endpoint. Each object from each page will be sent as
138-
// independent OCTResponse objects on the returned signal, so subscribers don't
139-
// have to know or care about this pagination behavior.
140-
//
141-
// To stop fetching pages, simply dispose of all subscriptions to the signal.
142-
//
143-
// method - The HTTP method to use in the request (e.g., "GET" or
144-
// "POST").
145-
// path - The path to request, relative to the base API endpoint.
146-
// This path should _not_ begin with a forward slash.
147-
// parameters - HTTP parameters to encode and send with the request.
148-
// notMatchingEtag - An ETag to compare the server data against, previously
149-
// retrieved from an instance of OCTResponse. If the content
150-
// has not changed since, no new data will be fetched. This
151-
// argument may be nil to always fetch the latest data.
152-
// resultClass - A subclass of OCTObject to use for each
153-
// OCTResponse.parsedResult. If this is nil, the
154-
// `parsedResult` will be an NSDictionary.
155-
//
156-
// Returns a signal which will send an instance of OCTResponse for each JSON
157-
// object _if new data was retrieved_. On success, the signal will send
158-
// completed regardless of whether there was new data. If an error occurs at any
159-
// point, the returned signal will send it immediately, then terminate.
160-
- (RACSignal *)enqueueConditionalRequestWithMethod:(NSString *)method path:(NSString *)path parameters:(NSDictionary *)parameters notMatchingEtag:(NSString *)etag resultClass:(Class)resultClass;
161-
162-
// Behaves like
163-
// -enqueueConditionalRequestWithMethod:path:parameters:notMatchingEtag:resultClass:,
164-
// but allows a full URL to be passed in.
165-
- (RACSignal *)enqueueConditionalRequestWithMethod:(NSString *)method URL:(NSURL *)URL parameters:(NSDictionary *)parameters notMatchingEtag:(NSString *)etag resultClass:(Class)resultClass;
145+
- (RACSignal *)enqueueRequest:(NSURLRequest *)request resultClass:(Class)resultClass;
166146

167147
@end
168148

0 commit comments

Comments
 (0)