Skip to content

Instantly share code, notes, and snippets.

@jimrollenhagen
Created July 15, 2012 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimrollenhagen/3118522 to your computer and use it in GitHub Desktop.
Save jimrollenhagen/3118522 to your computer and use it in GitHub Desktop.
//
// WhatAPI.m
// iWhat
//
// Created by James Rollenhagen on 7/14/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "WhatAPI.h"
#import <RestKit/RestKit.h>
@interface WhatAPI()
@property (nonatomic, strong) RKClient *client;
@property (nonatomic, strong) RKObjectManager *manager;
@end
@implementation WhatAPI
@synthesize client = _client;
@synthesize manager = _manager;
- (RKClient *)client {
return self.manager.client;
}
- (RKObjectManager *)manager {
if (!_manager) {
_manager = [RKObjectManager managerWithBaseURLString:@"https://ssl.what.cd"];
}
return _manager;
}
- (void)testRequest {
// make initial get request
RKRequest *req = [self.client requestWithResourcePath:@"/login.php"];
RKResponse *res = [req sendSynchronously];
NSLog(@"Cookies (1)! count is %d, array is %@", res.cookies.count, res.cookies);
// make login request
req = [self.client requestWithResourcePath:@"/login.php"];
req.method = RKRequestMethodPOST;
NSDictionary *loginParams = [NSDictionary dictionaryWithKeysAndObjects:@"username", @"ridejkcl", @"password", @"rF2Pj2PD466vE29x", @"keeplogged", @"1", @"login", @"Login", nil];
req.params = loginParams;
req.followRedirect = YES;
res = [req sendSynchronously];
NSLog(@"Cookies (2)! count is %d, array is %@", res.cookies.count, res.cookies);
// TODO do something here to check if properly logged in
// finally, get authkey and whatnot
req = [self.client requestWithResourcePath:@"/ajax.php?action=index"];
res = [req sendSynchronously];
NSString *body = [[NSString alloc]initWithData:res.body encoding:NSUTF8StringEncoding];
NSLog(@"%@", body);
NSLog(@"Cookies (3)! count is %d, array is %@", res.cookies.count, res.cookies);
}
- (void)testRequest2 {
RKRequest *req = [self.client requestWithResourcePath:@"/ajax.php?action=inbox"];
RKResponse *res = [req sendSynchronously];
NSString *body = [[NSString alloc]initWithData:res.body encoding:NSUTF8StringEncoding];
NSLog(@"%@", body);
NSLog(@"Cookies (3)! count is %d, array is %@", res.cookies.count, res.cookies);
}
@end
//
// iWhatFirstViewController.m
// iWhat
//
// Created by James Rollenhagen on 7/14/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "iWhatFirstViewController.h"
#import "WhatAPI.h"
@interface iWhatFirstViewController ()
@property (nonatomic, strong) WhatAPI *api;
@end
@implementation iWhatFirstViewController
@synthesize api = _api;
- (WhatAPI *)api {
if (!_api) {
_api = [[WhatAPI alloc] init];
}
return _api;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
- (IBAction)loginToSite {
NSLog(@"Logging in to What.CD");
[self.api testRequest];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment