Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Created October 15, 2013 22:59
Show Gist options
  • Select an option

  • Save gregtemp/6999967 to your computer and use it in GitHub Desktop.

Select an option

Save gregtemp/6999967 to your computer and use it in GitHub Desktop.
tumblr test 1 - getting images from tumblr needs - cocoapods import of tumblrsdk
//
// C4WorkSpace.m
// PodTest2
//
// Created by Gregory Debicki on 2013-10-09.
//
#import "C4Workspace.h"
#import "TMAPIClient.h"
@implementation C4WorkSpace {
C4ScrollView *viewer;
C4Shape *border;
NSMutableDictionary *myArray;
NSMutableArray *pictures;
}
-(void)setup {
viewer = [C4ScrollView scrollView:CGRectMake(50, 100, self.canvas.width - 100, self.canvas.height - 200)];
viewer.contentSize = CGSizeMake(viewer.width, 0);
border = [C4Shape rect:viewer.frame];
border.fillColor = [UIColor clearColor];
border.strokeColor = C4GREY;
border.userInteractionEnabled = NO;
[self.canvas addObjects:@[viewer, border]];
[TMAPIClient sharedInstance].OAuthConsumerKey = @"sNUjbu3uXKvSleBLBlOTfD3wysGV8inthwujz7d3xsQNO0MBRJ";
[TMAPIClient sharedInstance].OAuthConsumerSecret = @"WXcwOPoN1SaaRfwjF48zUIw8GoM6maNRTRE0oaVVpR4YSEkdYO";
[TMAPIClient sharedInstance].OAuthToken = @"yffc905h8cUpyHsfVwGJoAXWMwwV2aSUmrtaukSHYc4YAWYKwV";
[TMAPIClient sharedInstance].OAuthTokenSecret = @"Oj9LOa9fkxcE1vVF0P4wo78ai8xXQc4aghjmlhAVRyjw2aXdgY";
[[TMAPIClient sharedInstance] posts:@"alonglistofthings.tumblr.com" type:@"photo" parameters:@{@"limit" : @5}
callback:^(id response, NSError *error) {
if (error)
NSLog(@"Error");
else {
myArray = response[@"posts"];
[self drawPics];
}
}];
}
-(void) drawPics {
if ([myArray valueForKey:@"image_permalink"] != nil) {
CGPoint imgOrigin = CGPointMake(0, 0);
for (int i = 0; i < 5; i++) {
NSString *imgUrl = [[[[[myArray valueForKey:@"photos"] valueForKey:@"original_size"] valueForKey:@"url"] objectAtIndex:i] objectAtIndex:0];
if(imgUrl) {
C4Image *img = [C4Image imageWithURL:imgUrl];
img.width = viewer.width;
img.origin = imgOrigin;
imgOrigin.y += img.height;
viewer.contentSize = CGSizeMake(viewer.contentSize.width, viewer.contentSize.height + img.height);
CGPoint points[2] = {CGPointMake(0, img.origin.y + img.height), CGPointMake(viewer.width, img.origin.y + img.height)};
C4Shape *line = [C4Shape line:points];
line.strokeColor = C4GREY;
[viewer addObjects:@[img, line]];
}
}
}
else
NSLog(@"nope");
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment