Last active
December 14, 2015 13:08
-
-
Save rnystrom/5091412 to your computer and use it in GitHub Desktop.
Fast upload of test data to Parse https://parse.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
NSMutableURLRequest *parseRequest() { | |
NSMutableURLRequest *request = [[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://api.parse.com/1/classes/YOUR_CLASS_NAME"]] mutableCopy]; | |
[request setValue:@"YOUR_APPLICATION_ID" forHTTPHeaderField:@"X-Parse-Application-Id"]; | |
[request setValue:@"YOUR_REST_API_KEY" forHTTPHeaderField:@"X-Parse-REST-API-Key"]; | |
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | |
[request setHTTPMethod:@"POST"]; | |
return request; | |
} | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
formatter.dateFormat = @"YYYY-MM-dd'T'HH:mm:ss'Z'"; | |
// can change the # to upload | |
for(NSInteger i = 0; i < 100; i++) { | |
// example JSON setup | |
NSDate *date = [[NSDate date] dateByAddingTimeInterval:- 24 * 60 * 60 * i]; | |
NSDictionary *preppedJSON = @{ | |
@"publishedAt" : @{ | |
@"__type" : @"Date", | |
@"iso" : [formatter stringFromDate:date] | |
}, | |
@"subtitle" : @"TEST SUBTITLE", | |
@"text" : @"Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Cras mattis consectetur purus sit amet fermentum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Nullam quis risus eget urna mollis ornare vel eu leo. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.", | |
@"title" : @"TEST TITLE", | |
@"isDev" : @(YES) | |
}; | |
NSError *error = nil; | |
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:preppedJSON options:kNilOptions error:&error]; | |
if (error) { | |
NSLog(error.localizedDescription); | |
} | |
NSMutableURLRequest *request = parseRequest(); | |
[request setHTTPBody:jsonData]; | |
error = nil; | |
NSURLResponse *response; | |
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; | |
if(error) { | |
NSLog(@"%@",error.localizedDescription); | |
exit(1); | |
} | |
if (responseData) { | |
NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil]; | |
if(responseJSON[@"error"]) { | |
NSLog(@"%@",responseJSON); | |
exit(1); | |
} | |
} | |
NSLog(@"Finished %i...",i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment