Skip to content

Instantly share code, notes, and snippets.

@jacobvanorder
Created February 7, 2019 02:41
Show Gist options
  • Save jacobvanorder/63d17fe8f559efa8f5913ef89dbd7f4f to your computer and use it in GitHub Desktop.
Save jacobvanorder/63d17fe8f559efa8f5913ef89dbd7f4f to your computer and use it in GitHub Desktop.
Here ya go
- (void)fetchTrainResponseForLine:(NSString *)lineCode
origin:(NSString *)originCode
destination:(NSString *)destinationCode
andCallback:(SGMetraTrainResponseCallback)trainResponseCallback {
NSURL *metraURL = [NSURL URLWithString:@"http://12.205.200.243/AJAXTrainTracker.svc/GetAcquityTrainData"];
NSMutableURLRequest *metraRequest = [[NSMutableURLRequest alloc] initWithURL:metraURL];
NSData *requestJson = [[NSString stringWithFormat:@"{\"stationRequest\":{\"Corridor\":\"%@\",\"Destination\":\"%@\",\"Origin\":\"%@\",\"timestamp\":\"/Date(%i-0000)/\"}}", lineCode, destinationCode, originCode, (int)[[NSDate date] timeIntervalSince1970]] dataUsingEncoding:NSUTF8StringEncoding];
[metraRequest setHTTPBody:requestJson];
[metraRequest setHTTPMethod:@"POST"];
[metraRequest addValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[metraRequest addValue:@"Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54" forHTTPHeaderField:@"User-Agent"];
self.dataTask = [[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]] dataTaskWithRequest:metraRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
SGMetraTrainResponse *trainResponse = nil;
if (response) {
trainResponse = [[SGMetraTrainResponse alloc] initWithTrainResponseJsonData:data];
dispatch_async(dispatch_get_main_queue(), ^{
if (trainResponseCallback) {
trainResponseCallback(trainResponse, error);
}
});
}
[self setNetworkActivityIndicatorVisible:NO];
}];
[self.dataTask resume];
[self setNetworkActivityIndicatorVisible:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment