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