├── README.md ├── SJInstagramSignIn.h ├── SJInstagramSignIn.m ├── SJInstagramTimeline.h └── SJInstagramTimeline.m /README.md: -------------------------------------------------------------------------------- 1 | SJInstagramEngine is a Cocoa wrapper around the [Instagram](http://instagr.am) API. 2 | 3 | SJInstagramEngine is in its formative stage right now. I'm fleshing it out as I go along. 4 | -------------------------------------------------------------------------------- /SJInstagramSignIn.h: -------------------------------------------------------------------------------- 1 | // 2 | // SJInstagramSignIn.h 3 | // instagallery 4 | // 5 | // Created by Scott Jackson on 11/02/11. 6 | // Copyright 2011 SJSoftware. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface SJInstagramSignIn : NSObject { 13 | NSMutableData *receivedData; 14 | } 15 | 16 | @property(readwrite, retain) NSMutableData *receivedData; 17 | 18 | /* 19 | Create an SJInstagramSignIn object and call signInWith:username andPassword: 20 | 21 | Then, use NSNotification Center to listen for a "signInSuccess" notification. 22 | */ 23 | - (void)signInWithUsername:(NSString *)username andPassword:(NSString *)password; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /SJInstagramSignIn.m: -------------------------------------------------------------------------------- 1 | // 2 | // SJInstagramSignIn.m 3 | // instagallery 4 | // 5 | // Created by Scott Jackson on 11/02/11. 6 | // Copyright 2011 SJSoftware. All rights reserved. 7 | // 8 | 9 | #import "SJInstagramSignIn.h" 10 | #import "JSON.h" 11 | 12 | 13 | @implementation SJInstagramSignIn 14 | 15 | @synthesize receivedData; 16 | 17 | - (void)signInWithUsername:(NSString *)username andPassword:(NSString *)password { 18 | NSString *urlString = @"https://instagr.am/api/v1/accounts/login/"; 19 | 20 | NSString *post = [NSString stringWithFormat:@"username=%@&password=%@&device_id=%@", username, password, @"0000"]; 21 | NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding]; 22 | NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 23 | 24 | NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]]; 25 | [req setHTTPMethod:@"POST"]; 26 | [req setValue:postLength forHTTPHeaderField:@"Content-Length"]; 27 | [req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 28 | [req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"User-Agent"]; 29 | [req setHTTPBody:postData]; 30 | 31 | NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 32 | 33 | if (conn) { 34 | self.receivedData = [[NSMutableData data] retain]; 35 | } else { 36 | NSLog(@"Sign-in connection failed."); 37 | } 38 | } 39 | 40 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 41 | NSLog(@"sign-in connection received"); 42 | } 43 | 44 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 45 | { 46 | [self.receivedData appendData:data]; 47 | } 48 | 49 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection { 50 | NSLog(@"sign-in connection succeeded. received %d bytes", [self.receivedData length]); 51 | SBJSON *jsonParser = [[SBJSON alloc] init]; 52 | 53 | NSString *jsonString = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding]; 54 | NSDictionary *jsonResponse = [jsonParser objectWithString:jsonString]; 55 | NSLog(@"here's the data: %@", jsonResponse); 56 | [[NSNotificationCenter defaultCenter] 57 | postNotificationName:@"signInSuccess" object:jsonResponse]; 58 | 59 | } 60 | 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /SJInstagramTimeline.h: -------------------------------------------------------------------------------- 1 | // 2 | // SJInstagramTimeline.h 3 | // instagallery 4 | // 5 | // Created by Scott Jackson on 11/02/11. 6 | // Copyright 2011 SJSoftware. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface SJInstagramTimeline : NSObject { 13 | NSMutableData *receivedData; 14 | } 15 | 16 | @property(readwrite, retain) NSMutableData *receivedData; 17 | 18 | /* 19 | Create an SJInstagramSignIn object and call signInWith:username andPassword: 20 | 21 | Then, use NSNotification Center to listen for a "getTimeline" notification. 22 | The notification's object is an array of photos (which are dictionaries). 23 | */ 24 | - (void)getTimeline; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /SJInstagramTimeline.m: -------------------------------------------------------------------------------- 1 | // 2 | // SJInstagramTimeline.m 3 | // instagallery 4 | // 5 | // Created by Scott Jackson on 11/02/11. 6 | // Copyright 2011 SJSoftware. All rights reserved. 7 | // 8 | 9 | #import "SJInstagramTimeline.h" 10 | #import "SBJSON.h" 11 | 12 | 13 | @implementation SJInstagramTimeline 14 | 15 | @synthesize receivedData; 16 | 17 | - (void)getTimeline { 18 | NSString *urlString = @"http://instagr.am/api/v1/feed/timeline/"; 19 | 20 | NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]]; 21 | [req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 22 | [req setValue:@"Instagram" forHTTPHeaderField:@"User-Agent"]; 23 | [req setHTTPShouldHandleCookies:YES]; 24 | 25 | NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 26 | 27 | if (conn) { 28 | self.receivedData = [[NSMutableData data] retain]; 29 | } else { 30 | NSLog(@"Timeline connection failed."); 31 | } 32 | } 33 | 34 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 35 | NSLog(@"timeline connection received"); 36 | } 37 | 38 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 39 | { 40 | [self.receivedData appendData:data]; 41 | } 42 | 43 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection { 44 | NSLog(@"timeline connection succeeded. received %d bytes", [self.receivedData length]); 45 | SBJSON *jsonParser = [[SBJSON alloc] init]; 46 | 47 | NSString *jsonString = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding]; 48 | NSDictionary *jsonResponse = [jsonParser objectWithString:jsonString]; 49 | //NSLog(@"here's the data: %@", jsonResponse); 50 | 51 | NSArray *photos = [jsonResponse objectForKey:@"items"]; 52 | 53 | 54 | [[NSNotificationCenter defaultCenter] 55 | postNotificationName:@"getTimeline" object:photos]; 56 | 57 | } 58 | @end 59 | --------------------------------------------------------------------------------