Skip to content

Commit 0dd9c0a

Browse files
committed
Added compatibility with captcha and PoW similar to Android
1 parent a3b7f9a commit 0dd9c0a

File tree

4 files changed

+61
-34
lines changed

4 files changed

+61
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
QueueITLib.xcworkspace/xcuserdata/queut-it.xcuserdatad/xcdebugger/**
22
QueueITLib.xcworkspace/xcuserdata
3+
QueueITLib.xcworkspace

QueueITLib/QueueITEngine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ typedef enum {
4040
-(void)updateQueuePageUrl:(NSString*)queuePageUrl;
4141
-(void)raiseViewClosed;
4242
-(void)close: (void (^ __nullable)(void))onComplete;
43+
-(void)handleAppEnqueueResponse:(NSString*) queueId
44+
queueURL:(NSString*) queueURL
45+
queueURLTTLInMinutes:(int) ttl
46+
eventTargetURL:(NSString*) targetURL
47+
queueItToken:(NSString*) token;
4348

4449
@end
4550

QueueITLib/QueueITEngine.m

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,50 @@ -(void)tryEnqueue
166166
}];
167167
}
168168

169+
-(BOOL)isSafetyNet:(NSString*) queueId
170+
queueURL:(NSString*) queueURL
171+
{
172+
bool queueIdExists = queueId != nil && queueId != (id)[NSNull null];
173+
bool queueUrlExists = queueURL != nil && queueURL != (id)[NSNull null];
174+
return queueIdExists && !queueUrlExists;
175+
}
176+
177+
-(BOOL)isDisabled:(NSString*) queueId
178+
queueURL:(NSString*) queueURL
179+
{
180+
bool queueIdExists = queueId != nil && queueId != (id)[NSNull null];
181+
bool queueUrlExists = queueURL != nil && queueURL != (id)[NSNull null];
182+
return !queueIdExists && !queueUrlExists;
183+
}
184+
185+
-(void)handleAppEnqueueResponse:(NSString*) queueId
186+
queueURL:(NSString*) queueURL
187+
queueURLTTLInMinutes:(int) ttl
188+
eventTargetURL:(NSString*) targetURL
189+
queueItToken:(NSString*) token {
190+
//SafetyNet
191+
if ([self isSafetyNet:queueId queueURL:queueURL])
192+
{
193+
[self raiseQueuePassed:token];
194+
return;
195+
}
196+
//Disabled
197+
else if ([self isDisabled:queueId queueURL:queueURL]){
198+
self.requestInProgress = NO;
199+
[self raiseQueueDisabled];
200+
return;
201+
}
202+
203+
//InQueue, PostQueue or Idle
204+
self.queueUrlTtl = ttl;
205+
[self showQueue:queueURL targetUrl:targetURL];
206+
207+
if(ttl>0){
208+
NSString* urlTtlString = [self convertTtlMinutesToSecondsString:ttl];
209+
[self.cache update:queueURL urlTTL:urlTtlString targetUrl:targetURL];
210+
}
211+
}
212+
169213
-(void)tryEnqueueWithUserAgent:(NSString*)secretAgent
170214
{
171215
NSString* userId = [IOSUtils getUserId];
@@ -186,34 +230,11 @@ -(void)tryEnqueueWithUserAgent:(NSString*)secretAgent
186230
return;
187231
}
188232

189-
bool queueIdExists = queueStatus.queueId != nil && queueStatus.queueId != (id)[NSNull null];
190-
bool queueUrlExists = queueStatus.queueUrlString != nil && queueStatus.queueUrlString != (id)[NSNull null];
191-
192-
//SafetyNet
193-
if (queueIdExists && !queueUrlExists)
194-
{
195-
[self raiseQueuePassed:queueStatus.queueitToken];
196-
}
197-
//InQueue
198-
else if (queueIdExists && queueUrlExists)
199-
{
200-
self.queueUrlTtl = queueStatus.queueUrlTTL;
201-
[self showQueue:queueStatus.queueUrlString targetUrl:queueStatus.eventTargetUrl];
202-
203-
NSString* urlTtlString = [self convertTtlMinutesToSecondsString:queueStatus.queueUrlTTL];
204-
[self.cache update:queueStatus.queueUrlString urlTTL:urlTtlString targetUrl:queueStatus.eventTargetUrl];
205-
}
206-
//PostQueue or Idle
207-
else if (!queueIdExists && queueUrlExists)
208-
{
209-
[self showQueue:queueStatus.queueUrlString targetUrl:queueStatus.eventTargetUrl];
210-
}
211-
//Disabled
212-
else
213-
{
214-
self.requestInProgress = NO;
215-
[self raiseQueueDisabled];
216-
}
233+
[self handleAppEnqueueResponse: queueStatus.queueId
234+
queueURL:queueStatus.queueUrlString
235+
queueURLTTLInMinutes:queueStatus.queueUrlTTL
236+
eventTargetURL:queueStatus.eventTargetUrl
237+
queueItToken:queueStatus.queueitToken];
217238
}
218239
failure:^(NSError *error, NSString* errorMessage)
219240
{

QueueITLib/QueueService.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
static QueueService *SharedInstance;
55

6-
static NSString * const API_ROOT = @"https://%@.queue-it.net/api/queue";
7-
static NSString * const TESTING_API_ROOT = @"https://%@.test.queue-it.net/api/queue";
6+
static NSString * const API_ROOT = @"https://%@.queue-it.net/api/mobileapp/queue";
7+
static NSString * const TESTING_API_ROOT = @"https://%@.test.queue-it.net/api/mobileapp/queue";
88
static bool testingIsEnabled = NO;
99

1010
@implementation QueueService
@@ -53,9 +53,9 @@ -(NSString*)enqueue:(NSString *)customerId
5353
}
5454
urlAsString = [urlAsString stringByAppendingString:[NSString stringWithFormat:@"/%@", customerId]];
5555
urlAsString = [urlAsString stringByAppendingString:[NSString stringWithFormat:@"/%@", eventorAliasId]];
56-
urlAsString = [urlAsString stringByAppendingString:[NSString stringWithFormat:@"/appenqueue"]];
56+
urlAsString = [urlAsString stringByAppendingString:[NSString stringWithFormat:@"/enqueue"]];
5757

58-
return [self submitPUTPath:urlAsString body:bodyDict
58+
return [self submitPOSTPath:urlAsString body:bodyDict
5959
success:^(NSData *data)
6060
{
6161
NSError *error = nil;
@@ -77,14 +77,14 @@ -(NSString*)enqueue:(NSString *)customerId
7777
}];
7878
}
7979

80-
- (NSString *)submitPUTPath:(NSString *)path
80+
- (NSString *)submitPOSTPath:(NSString *)path
8181
body:(NSDictionary *)bodyDict
8282
success:(QueueServiceSuccess)success
8383
failure:(QueueServiceFailure)failure
8484
{
8585
NSURL *url = [NSURL URLWithString:path];
8686
return [self submitRequestWithURL:url
87-
method:@"PUT"
87+
method:@"POST"
8888
body:bodyDict
8989
expectedStatus:200
9090
success:success

0 commit comments

Comments
 (0)