Skip to content

Instantly share code, notes, and snippets.

@nwalter08
Created October 31, 2013 21:42
Show Gist options
  • Save nwalter08/7257700 to your computer and use it in GitHub Desktop.
Save nwalter08/7257700 to your computer and use it in GitHub Desktop.
//
// ViewController.m
// fixtestingthing
//
// Created by Nick Walter on 10/31/13.
// Copyright (c) 2013 Nikki. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:@"http://letsrevolutionizetesting.com/challenge.json"]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
NSLog(@"STATUS CODE:%ld",(long)[(NSHTTPURLResponse*)response statusCode]);
if ([(NSHTTPURLResponse*)response statusCode] == 200)
{
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Result:%@",result);
NSError* error;
NSDictionary *JSONArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *urlString = [JSONArray objectForKey:@"follow"];
NSString *value = [urlString substringWithRange:NSMakeRange(49, 9)];
[self makeRequestWithId:value];
}
}];
}
- (void)makeRequestWithId:(NSString*)theId {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://letsrevolutionizetesting.com/challenge.json?id=%@",theId]]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
NSLog(@"STATUS CODE:%ld",(long)[(NSHTTPURLResponse*)response statusCode]);
if ([(NSHTTPURLResponse*)response statusCode] == 200)
{
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Result:%@",result);
NSError* error;
NSDictionary *JSONArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *urlString = [JSONArray objectForKey:@"follow"];
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"(?<=id=).*"
options:NSRegularExpressionCaseInsensitive
error:&error];
[regex enumerateMatchesInString:urlString options:0 range:NSMakeRange(0, [urlString length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
// your code to handle matches here
// detect
NSString *insideString = [urlString substringWithRange:[match rangeAtIndex:0]];
//print
NSLog(@"%@",insideString);
[self makeRequestWithId:insideString];
}];
}
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment