Skip to content

Instantly share code, notes, and snippets.

@natemartinsf
Created December 14, 2009 05:16
Show Gist options
  • Save natemartinsf/255804 to your computer and use it in GitHub Desktop.
Save natemartinsf/255804 to your computer and use it in GitHub Desktop.
@import <Foundation/CPObject.j>
@import "NMJobPosting.j"
@import "NMValidatedObjectContext.j"
@implementation NMJobListController : CPObject
{
//SNIP
NMValidatedObjectContext context;
}
- (id)init
{
if (self = [super init])
{
CPLogRegister(CPLogPopup);
CPLog.info(@"initing joblistcontroller");
context = [[NMValidatedObjectContext alloc] init];
[context setBaseURL:[CPURL URLWithString:@"http://0.0.0.0:3000/"]];
//[context setBaseURL:[CPURL URLWithString:@"http://ajax.googleapis.com/ajax/services/search/"]];
//[context addPath:@"images?v=1.0&rsz=large&q=testing" forClassName:@"NMJobPosting"];
[context addPath:@"job_postings" forClassName:@"NMJobPosting"];
[context allObjectsForClassName:@"NMJobPosting"];
//snip
}
return self;
}
//snip
@end
@implementation NMValidatedObjectContext : CPObject
{
CPURL baseURL @accessors;
CPDictionary managedClasses @accessors;
}
- (id)init
{
if(self = [super init])
{
managedClasses = [[CPDictionary alloc] init];
}
return self;
}
-(void)addPath:(CPString)pathName forClassName:(CPString)className
{
[managedClasses setObject:pathName forKey:className];
}
-(void)allObjectsForClassName:(CPString)className
{
CPLog.info(@"getting all test objects");
var path = [managedClasses objectForKey:className];
var fullPath = [CPURL URLWithString:[baseURL absoluteString] + path];
var request = [[CPURLRequest alloc] initWithURL:fullPath];
CPLog.info("fullPath: "+fullPath);
[request setHTTPMethod:@"GET"];
[request setValue:"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:"application/json" forHTTPHeaderField:@"Accept"];
var urlConnection = [CPURLConnection connectionWithRequest:request delegate:self];
}
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
{
CPLog.info(@"receiving");
CPLog.info(data);
}
- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)anError
{
CPLog.info(@"error!");
CPLog.info(anError);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment