commit | author | age
|
655e66
|
1 |
/* |
H |
2 |
* Copyright (C) 2017 Twitter, Inc. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
* |
|
16 |
*/ |
|
17 |
|
|
18 |
/** |
|
19 |
This header is private to the Twitter Core SDK and not exposed for public SDK consumption |
|
20 |
*/ |
a0a843
|
21 |
|
H |
22 |
#import <TwitterCore/TWTRSessionStore.h> |
|
23 |
|
|
24 |
NS_ASSUME_NONNULL_BEGIN |
|
25 |
|
|
26 |
@protocol TWTRNetworkingResponseValidating; |
|
27 |
|
|
28 |
typedef void (^TWTRNetworkingPipelineCallback)(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error); |
|
29 |
|
|
30 |
@interface TWTRNetworkingPipeline : NSObject |
|
31 |
|
|
32 |
/** |
|
33 |
*if set, this object will be used to validate network responses. |
|
34 |
*/ |
|
35 |
@property (nonatomic, readonly, nullable) id<TWTRNetworkingResponseValidating> responseValidator; |
|
36 |
|
|
37 |
/** |
|
38 |
* Use the initWithURLSession: method instead. |
|
39 |
*/ |
|
40 |
- (instancetype)init NS_UNAVAILABLE; |
|
41 |
|
|
42 |
/** |
|
43 |
* Returns an instance of the networking pipeline |
|
44 |
* |
|
45 |
* @param URLSession URLSession object to invoke network requests on. |
|
46 |
* @param responseValidator an optional response validator to use to validate responses. |
|
47 |
*/ |
|
48 |
- (instancetype)initWithURLSession:(NSURLSession *)URLSession responseValidator:(nullable id<TWTRNetworkingResponseValidating>)responseValidator NS_DESIGNATED_INITIALIZER; |
|
49 |
|
|
50 |
/** |
|
51 |
* Enqueues a request in the pipeline. |
|
52 |
* |
|
53 |
* @param request The HTTP Request to send |
|
54 |
* @param sessionStore The session store that will provide the session. |
|
55 |
* @param userID The userId to sign the request for or nil if using the guest session |
|
56 |
* @param completion The completion block to invoke on completion. |
|
57 |
*/ |
|
58 |
- (NSProgress *)enqueueRequest:(NSURLRequest *)request sessionStore:(id<TWTRSessionStore>)sessionStore; |
|
59 |
- (NSProgress *)enqueueRequest:(NSURLRequest *)request sessionStore:(id<TWTRSessionStore>)sessionStore requestingUser:(nullable NSString *)userID; |
|
60 |
|
|
61 |
/** |
|
62 |
* Enqueues a request in the pipeline. |
|
63 |
* |
|
64 |
* @param request The HTTP request to send. |
|
65 |
* @param sessionStore The session store that will provide the session. |
|
66 |
* @param userID The user to sign the request for or nil if using the guest session. |
|
67 |
* @param completion The completion block to invoke on completion. |
|
68 |
*/ |
|
69 |
- (NSProgress *)enqueueRequest:(NSURLRequest *)request sessionStore:(id<TWTRSessionStore>)sessionStore requestingUser:(nullable NSString *)userID completion:(nullable TWTRNetworkingPipelineCallback)completion; |
|
70 |
|
|
71 |
@end |
|
72 |
|
|
73 |
@protocol TWTRNetworkingResponseValidating <NSObject> |
|
74 |
|
|
75 |
@required |
|
76 |
/** |
|
77 |
* This method should return an NO if the response represents an error state. |
|
78 |
*/ |
|
79 |
- (BOOL)validateResponse:(nullable NSURLResponse *)response data:(nullable NSData *)data error:(NSError **)error; |
|
80 |
|
|
81 |
@end |
|
82 |
|
|
83 |
NS_ASSUME_NONNULL_END |