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 <Foundation/Foundation.h> |
|
23 |
|
|
24 |
#ifndef NS_DESIGNATED_INITIALIZER |
|
25 |
#define NS_DESIGNATED_INITIALIZER __attribute((objc_designated_initializer)) |
|
26 |
#endif |
|
27 |
|
|
28 |
FOUNDATION_EXTERN NSString *const TFSScribeDebugPreferencesKey; |
|
29 |
|
|
30 |
FOUNDATION_EXTERN NSString *const TFSScribeEventNotification; // Triggered when the scribe API call returns |
|
31 |
FOUNDATION_EXTERN NSString *const TFSScribeFlushNotification; // Triggered after scribe flush |
|
32 |
FOUNDATION_EXTERN NSString *const TFSScribeFlushTokenInfoKey; // Key in userInfo dictionary corresponding to the token used in the flush request. |
|
33 |
|
|
34 |
FOUNDATION_EXTERN const NSInteger TFSScribeServiceUpdateValue; |
|
35 |
|
|
36 |
/** |
|
37 |
* Result of handling outgoing scribe events. |
|
38 |
*/ |
|
39 |
typedef NS_ENUM(NSUInteger, TFSScribeServiceRequestDisposition) { |
|
40 |
/** |
|
41 |
* Indicates that the outgoing events were handled successfully. |
|
42 |
*/ |
|
43 |
TFSScribeServiceRequestDispositionSuccess, |
|
44 |
/** |
|
45 |
* Indicates that handling failed due to a client side problem, such as a network |
|
46 |
* timeout or the request being cancelled. |
|
47 |
*/ |
|
48 |
TFSScribeServiceRequestDispositionClientError, |
|
49 |
/** |
|
50 |
* Indicates that handling failed due to the server rejecting the sent data. |
|
51 |
*/ |
|
52 |
TFSScribeServiceRequestDispositionServerError, |
|
53 |
}; |
|
54 |
|
|
55 |
/** |
|
56 |
* Object representing a scribe event. These methods must be thread safe. |
|
57 |
*/ |
|
58 |
@protocol TFSScribeEventParameters <NSObject> |
|
59 |
|
|
60 |
/** |
|
61 |
* Binary representation of the scribe event. This is what will be kept in |
|
62 |
* the store and returned when flush is called. |
|
63 |
*/ |
|
64 |
- (NSData *)data; |
|
65 |
/** |
|
66 |
* Dictionary representation of the event used for logging purposes. |
|
67 |
*/ |
|
68 |
- (NSDictionary *)dictionaryRepresentation; |
|
69 |
/** |
|
70 |
* User ID of event |
|
71 |
*/ |
|
72 |
- (NSString *)userID; |
|
73 |
|
|
74 |
@end |
|
75 |
|
|
76 |
@class TFSScribe; |
|
77 |
|
|
78 |
@protocol TFSScribeErrorDelegate <NSObject> |
|
79 |
|
|
80 |
/** |
|
81 |
* Scribe will call this method on an arbitrary queue if it encounters |
|
82 |
* an internal error. |
|
83 |
*/ |
|
84 |
- (void)scribeService:(TFSScribe *)service didEncounterError:(NSError *)error; |
|
85 |
|
|
86 |
@end |
|
87 |
|
|
88 |
typedef void (^TFSScribeRequestBatchedImpressionEventBlock)(id<TFSScribeEventParameters> scribeEventParameters); |
|
89 |
typedef void (^TFSScribeRequestCompletionBlock)(TFSScribeServiceRequestDisposition disposition); |
|
90 |
|
|
91 |
@protocol TFSScribeRequestHandler <NSObject> |
|
92 |
|
|
93 |
/** |
|
94 |
* TFSScribe will call this method once it has prepared all of the outgoing events. |
|
95 |
* This method will be called on a background queue. |
|
96 |
* |
|
97 |
* @param outgoingEvents Prepared outgoing events |
|
98 |
* @param userID User ID to send events for. Must not be nil. |
|
99 |
* @param completionHandler Execute the completion block once the events have been handled with the appropriate disposition. The completion block can be executed on any queue. |
|
100 |
*/ |
|
101 |
- (void)handleScribeOutgoingEvents:(NSString *)outgoingEvents userID:(NSString *)userID completionHandler:(TFSScribeRequestCompletionBlock)completionHandler; |
|
102 |
|
|
103 |
@optional |
|
104 |
|
|
105 |
/** |
|
106 |
* When flushing a user ID, this method will be called with an array of impressions |
|
107 |
* for you to batch. After the method is executed, the impressions will be deleted |
|
108 |
* from the store. If this method is not implemented, impressions will still be |
|
109 |
* deleted. |
|
110 |
* |
|
111 |
* @param impressions Array of TFSScribeImpressions objects. |
|
112 |
* @param batchedHandler Call the batchedHandler block for each event data you generate from the impressions. |
|
113 |
*/ |
|
114 |
- (void)handleImpressionsBatch:(NSArray *)impressions batchedImpressionHandler:(TFSScribeRequestBatchedImpressionEventBlock)batchedHandler; |
|
115 |
|
|
116 |
@end |
|
117 |
|
|
118 |
@interface TFSScribe : NSObject |
|
119 |
|
|
120 |
@property (nonatomic, weak) id<TFSScribeErrorDelegate> errorDelegate; |
|
121 |
|
|
122 |
+ (BOOL)isDebugEnabled; |
|
123 |
+ (void)setDebugEnabled:(BOOL)enabled; |
|
124 |
|
|
125 |
/** |
|
126 |
* Init the scribe. |
|
127 |
* |
|
128 |
* @param storeURL File URL to store the persisted data. Pass nil to use an in-memory store. |
|
129 |
*/ |
|
130 |
- (instancetype)initWithStoreURL:(NSURL *)storeURL; |
|
131 |
|
|
132 |
/** |
|
133 |
* Init the scribe. |
|
134 |
* |
|
135 |
* @param storeURL File URL to store the persisted data. Pass nil to use an in-memory store. |
|
136 |
* @param modelURL File URL to the location of the mom on disk. Not necessary if you are using the framework, or if your mom is in the mainBundle. |
|
137 |
*/ |
|
138 |
- (instancetype)initWithStoreURL:(NSURL *)storeURL modelURL:(NSURL *)modelURL NS_DESIGNATED_INITIALIZER; |
|
139 |
|
|
140 |
/** |
|
141 |
* Opens the scribe asynchronously. |
|
142 |
*/ |
|
143 |
- (void)open; |
|
144 |
|
|
145 |
/** |
|
146 |
* Opens the scribe asynchronously. |
|
147 |
* |
|
148 |
* @param startBlock Block will be executed on a background queue immediately prior to opening. Can be nil. |
|
149 |
* @param completionBlock Block will be executed on a background queue immediately after opening. Can be nil. |
|
150 |
*/ |
|
151 |
- (void)openWithStartBlock:(dispatch_block_t)startBlock completionBlock:(dispatch_block_t)completionBlock; |
|
152 |
|
|
153 |
/** |
|
154 |
* Closes the scribe asynchronously. |
|
155 |
*/ |
|
156 |
- (void)close; |
|
157 |
|
|
158 |
/** |
|
159 |
* Closes the scribe asynchronously. |
|
160 |
* |
|
161 |
* @param startBlock Block will be executed on a background queue immediately prior to closing. Can be nil. |
|
162 |
* @param completionBlock Block will be executed on a background queue immediately after closing. Can be nil. |
|
163 |
*/ |
|
164 |
- (void)closeWithStartBlock:(dispatch_block_t)startBlock completionBlock:(dispatch_block_t)completionBlock; |
|
165 |
|
|
166 |
/** |
|
167 |
* Suspend the scribe's internal background queue. This could be used to improve scrolling performance on older devices. |
|
168 |
*/ |
|
169 |
- (void)suspend; |
|
170 |
/** |
|
171 |
* Resume the scribe's internal background queue. |
|
172 |
*/ |
|
173 |
- (void)resume; |
|
174 |
|
|
175 |
/** |
|
176 |
* Flush all events for the given userID. If no events or impressions exist |
|
177 |
* |
|
178 |
* @param userID User ID to flush events for. Must not be nil. |
|
179 |
* @param requestHandler Once the events have been prepared, the request handler will be called to handle the events. Must not be nil. |
|
180 |
*/ |
|
181 |
- (void)flushUserID:(NSString *)userID requestHandler:(id<TFSScribeRequestHandler>)requestHandler; |
|
182 |
|
|
183 |
/** |
|
184 |
* Flush all events for the given userID. |
|
185 |
* |
|
186 |
* @param userID User ID to flush events for. Must not be nil. |
|
187 |
* @param token A token to be included with notification userInfo dictionaries. |
|
188 |
* @param requestHandler Once the events have been prepared, the request handler will be called to handle the events. Must not be nil. |
|
189 |
*/ |
|
190 |
- (void)flushUserID:(NSString *)userID token:(NSString *)token requestHandler:(id<TFSScribeRequestHandler>)requestHandler; |
|
191 |
|
|
192 |
/** |
|
193 |
* Delete all events for the given userID. Events for user ID of 0 (anonymous user) will not be deleted. |
|
194 |
*/ |
|
195 |
- (void)deleteUserID:(NSString *)userID; |
|
196 |
|
|
197 |
/** |
|
198 |
* Schedule an event to be added to scribe. |
|
199 |
*/ |
|
200 |
- (void)enqueueEvent:(id<TFSScribeEventParameters>)eventParameters; |
|
201 |
|
|
202 |
/** |
|
203 |
* Schedule an impression to be added to scribe. |
|
204 |
*/ |
|
205 |
- (void)enqueueImpression:(NSData *)contentData eventName:(NSString *)eventName query:(NSString *)query clientVersion:(NSString *)clientVersion userID:(NSString *)userID; |
|
206 |
|
|
207 |
#if UIAUTOMATION |
|
208 |
- (void)clearScribeDatabase; |
|
209 |
#endif |
|
210 |
|
|
211 |
@end |