Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Drupal iOS SDK 2.0, Initial commit attaching to ticket #20 as well

  • Loading branch information...
commit 65b5c03c56d31a1dc24fe75d42c7c7244d064085 1 parent 0b4b9e6
@kylebrowning authored
View
30 DIOSComment.h
@@ -35,16 +35,26 @@
//
// ***** END LICENSE BLOCK *****
-#import <Foundation/Foundation.h>
-#import "DIOSConnect.h"
+#import "AFHTTPRequestOperation.h"
+#import "DIOSSession.h"
+@protocol DIOSCommentDelegate;
+@protocol DIOSCommentDelegate <NSObject>
+- (void)commentGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)commentSaveDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)commentUpdateDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)commentDeleteDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)commentIndexDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+@end
-@interface DIOSComment : DIOSConnect {
+@interface DIOSComment : NSObject <DIOSCommentDelegate>{
+ id <DIOSCommentDelegate> delegate;
}
-
-- (id) init;
-- (NSDictionary *) getComments:(NSString*)nid andStart:(NSString *)start andCount:(NSString *)count;
-- (void) addComment:(NSString*)nid subject:(NSString*)aSubject body:(NSString*)aBody;
-- (NSDictionary *) getCommentCountNewForNid:(NSString*)nid;
-- (NSDictionary *) getCommentCountForNid:(NSString*)nid;
-- (NSDictionary *) getComment:(NSString*)cid;
+@property (weak, nonatomic) id <DIOSCommentDelegate> delegate;
+- (id) initWithDelegate:(id<DIOSCommentDelegate>)aDelegate;
+- (void)commentGet:(NSDictionary *)comment;
+- (void)commentSave:(NSDictionary *)comment;
+- (void)commentUpdate:(NSDictionary *)comment;
+- (void)commentDelete:(NSDictionary *)comment;
+- (void)commentIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize;
+- (void)commentIndex:(NSDictionary *)params;
@end
View
198 DIOSComment.m
@@ -37,100 +37,134 @@
#import "DIOSComment.h"
-#import "DIOSConfig.h"
@implementation DIOSComment
+@synthesize delegate = _delegate;
- (id) init {
- [super init];
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:self];
+ return self;
+}
+- (id) initWithDelegate:(id<DIOSCommentDelegate>)aDelegate {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:aDelegate];
return self;
}
-- (NSDictionary *) getComments:(NSString*)nid andStart:(NSString *)start andCount:(NSString *)count {
- [self setMethod:@"comment.loadNodeComments"];
- [self setRequestMethod:@"GET"];
- NSString *url = [NSString stringWithFormat:@"node/%@/comments", nid];
- [self setMethodUrl:url];
- [self addParam:nid forKey:@"nid"];
- [self addParam:start forKey:@"start"];
- [self addParam:count forKey:@"count"];
- [self runMethod];
- return [self connResult];
+#pragma mark CommentGets
+- (void)commentGet:(NSDictionary *)comment {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]] parameters:nil success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(commentGetDidFinish:operation:response:error:)]) {
+ [_delegate commentGetDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(commentGetDidFinish:operation:response:error:)]) {
+ [_delegate commentGetDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ }];
}
-- (NSDictionary *) getComment:(NSString*)cid {
- [self setMethod:@"comment.load"];
- [self setRequestMethod:@"GET"];
- [self setMethodUrl:[NSString stringWithFormat:@"comment/%@", cid]];
- [self addParam:cid forKey:@"cid"];
- [self runMethod];
- return [self connResult];
+- (void)commentGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ DIOSSession *session = [DIOSSession sharedSession];
+ [[session delegate] callDidFinish:status operation:operation response:response error:error];
}
-- (NSDictionary *) getCommentCountForNid:(NSString*)nid {
- [self setMethod:@"comment.countAll"];
- [self setRequestMethod:@"POST"];
- [self setMethodUrl:@"comment/countAll"];
- [self addParam:nid forKey:@"nid"];
- [self runMethod];
- return [self connResult];
+#pragma mark commentSaves
+- (void)commentSave:(NSDictionary *)comment {
+ [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseComment] parameters:comment success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(commentSaveDidFinish:operation:response:error:)]) {
+ [_delegate commentSaveDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(commentSaveDidFinish:operation:response:error:)]) {
+ [_delegate commentSaveDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
+ }
+ }];
}
-- (NSDictionary *) getCommentCountNewForNid:(NSString*)nid {
- [self setMethod:@"comment.countNew"];
- [self setRequestMethod:@"POST"];
- [self setMethodUrl:@"comment/countNew"];
- [self addParam:nid forKey:@"nid"];
- [self runMethod];
- return [self connResult];
+- (void)commentSaveDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
}
-- (void) addComment:(NSString*)nid subject:(NSString*)aSubject body:(NSString*)aBody {
- [self setMethod:@"comment.save"];
- [self setMethodUrl:@"comment"];
- if(![nid isEqualToString:@""])
- [self addParam:nid forKey:@"nid"];
- if(aSubject != nil)
- [self addParam:aSubject forKey:@"subject"];
- if(aBody != nil) {
- NSDictionary *bodyValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:aBody, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
- NSDictionary *languageDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:bodyValues] forKey:DRUPAL_LANGUAGE];
- [self addParam:languageDict forKey:@"comment_body"];
- [self addParam:DRUPAL_LANGUAGE forKey:@"language"];
- }
- if([[self userInfo] objectForKey:@"uid"] != nil) {
- id temp = [[self userInfo] objectForKey:@"uid"];
- [self addParam:[temp stringValue] forKey:@"uid"];
- }
- if([[self userInfo] objectForKey:@"name"] != nil) {
- id temp = [[self userInfo] objectForKey:@"name"];
- [self addParam:temp forKey:@"name"];
- }
- [self addParam:@"en" forKey:@"language"];
- [self runMethod];
- return;
+
+#pragma mark commentUpdate
+- (void)commentUpdate:(NSDictionary *)comment {
+ [[DIOSSession sharedSession] putPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]] parameters:comment success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(commentUpdateDidFinish:operation:response:error:)]) {
+ [_delegate commentUpdateDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this put so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(commentUpdateDidFinish:operation:response:error:)]) {
+ [_delegate commentUpdateDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this put so my response will never be used.", _delegate);
+ }
+ }];
}
-- (void) updateComment:(NSString*)cid subject:(NSString*)aSubject body:(NSString*)aBody {
- [self setMethod:@"comment.save"];
- [self setMethodUrl:[NSString stringWithFormat:@"comment/%@", cid]];
- [self setRequestMethod:@"PUT"];
- NSMutableDictionary *comment = [[NSMutableDictionary alloc] init];
- if(![cid isEqualToString:@""])
- [comment setObject:cid forKey:@"cid"];
- if(aSubject != nil)
- [comment setObject:aSubject forKey:@"subject"];
- if(aBody != nil) {
- NSDictionary *bodyValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:aBody, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
- NSDictionary *languageDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:bodyValues] forKey:DRUPAL_LANGUAGE];
- [comment setObject:languageDict forKey:@"comment_body"];
- [comment setObject:DRUPAL_LANGUAGE forKey:@"language"];
- }
- if([[self userInfo] objectForKey:@"uid"] != nil) {
- id temp = [[self userInfo] objectForKey:@"uid"];
- [comment setObject:[temp stringValue] forKey:@"uid"];
- }
- if([[self userInfo] objectForKey:@"name"] != nil) {
- id temp = [[self userInfo] objectForKey:@"name"];
- [comment setObject:temp forKey:@"name"];
- }
- [self runMethod];
- return;
+- (void)commentUpdateDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark CommentDelete
+- (void)commentDelete:(NSDictionary *)comment {
+ [[DIOSSession sharedSession] deletePath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseComment, [comment objectForKey:@"cid"]] parameters:comment success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(commentDeleteDidFinish:operation:response:error:)]) {
+ [_delegate commentDeleteDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(commentDeleteDidFinish:operation:response:error:)]) {
+ [_delegate commentDeleteDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)commentDeleteDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
}
+#pragma mark commentIndex
+//Simpler method if you didnt want to build the params :)
+- (void)commentIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize {
+ NSMutableDictionary *commentIndexDict = [NSMutableDictionary new];
+ [commentIndexDict setValue:page forKey:@"page"];
+ [commentIndexDict setValue:fields forKey:@"fields"];
+ [commentIndexDict setValue:parameteres forKey:@"parameters"];
+ [commentIndexDict setValue:pageSize forKey:@"pagesize"];
+ [self commentIndex:commentIndexDict];
+}
+
+- (void)commentIndex:(NSDictionary *)params {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseComment] parameters:params success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(commentIndexDidFinish:operation:response:error:)]) {
+ [_delegate commentIndexDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(commentIndexDidFinish:operation:response:error:)]) {
+ [_delegate commentIndexDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)commentIndexDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
@end
View
67 DIOSConfig.h
@@ -1,67 +0,0 @@
-//
-// DIOSConfig.h
-//
-// ***** BEGIN LICENSE BLOCK *****
-// Version: MPL 1.1/GPL 2.0
-//
-// The contents of this file are subject to the Mozilla Public License Version
-// 1.1 (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-// http://www.mozilla.org/MPL/
-//
-// Software distributed under the License is distributed on an "AS IS" basis,
-// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-// for the specific language governing rights and limitations under the
-// License.
-//
-// The Original Code is Kyle Browning, released June 27, 2010.
-//
-// The Initial Developer of the Original Code is
-// Kyle Browning
-// Portions created by the Initial Developer are Copyright (C) 2010
-// the Initial Developer. All Rights Reserved.
-//
-// Contributor(s):
-//
-// Alternatively, the contents of this file may be used under the terms of
-// the GNU General Public License Version 2 or later (the "GPL"), in which
-// case the provisions of the GPL are applicable instead of those above. If
-// you wish to allow use of your version of this file only under the terms of
-// the GPL and not to allow others to use your version of this file under the
-// MPL, indicate your decision by deleting the provisions above and replacing
-// them with the notice and other provisions required by the GPL. If you do
-// not delete the provisions above, a recipient may use your version of this
-// file under either the MPL or the GPL.
-//
-// ***** END LICENSE BLOCK *****
-
-//#define STAGE
-#define DEV
-
-
-#ifdef STAGE
-
-#define DRUPAL_API_KEY @""
-#define DRUPAL_SERVICES_URL @"http://stage.example.com/services/plist"
-#define DRUPAL_URL @"http://stage.example.com"
-#define DRUPAL_DOMAIN @"stage.example.com"
-
-#endif
-
-#ifdef DEV
-
-#define DRUPAL_API_KEY @"4b2d7ef98d720386e0d2022842847404"
-#define DRUPAL_SERVICES_URL @"http://publisherios.workhabit.com/api"
-#define DRUPAL_URL @"http://publisherios.workhabit.com/"
-#define DRUPAL_DOMAIN @"publisherios.workhabit.com"
-#endif
-//THis is the constant for none in Drupal7 http://api.drupal.org/api/constant/LANGUAGE_NONE/7
-#define DRUPAL_LANGUAGE @"und"
-#define DRUPAL_CELL_DEFAULT_IMAGE @"http://demo.kylebrowning.com/sites/default/files/imagecache/iphone/4986607783_45b49e2493_o.jpg"
-#define DRUPAL_IMAGECACHE_URL @"sites/default/files/"
-#define DRUPAL_NC_SYSTEM @"DRUPALNCSYSTEM"
-#define DRUPAL_METHOD_DONE @"DRUPALMETHODDONE"
-#define DRUPAL_NODE_METHOD_DONE @"DRUPALNODEMETHODDONE"
-#define DRUPAL_CATEGORY_VID @"1"
-#define DRUPAL_VIEWS_IMAGE_FIELD @"files_node_data_field_image_filepath"
-#define DRUPAL_NODE_IMAGE_FIELD @"field_image"
View
81 DIOSConnect.h
@@ -1,81 +0,0 @@
-//
-// DIOSConnect.h
-//
-// ***** BEGIN LICENSE BLOCK *****
-// Version: MPL 1.1/GPL 2.0
-//
-// The contents of this file are subject to the Mozilla Public License Version
-// 1.1 (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-// http://www.mozilla.org/MPL/
-//
-// Software distributed under the License is distributed on an "AS IS" basis,
-// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-// for the specific language governing rights and limitations under the
-// License.
-//
-// The Original Code is Kyle Browning, released June 27, 2010.
-//
-// The Initial Developer of the Original Code is
-// Kyle Browning
-// Portions created by the Initial Developer are Copyright (C) 2010
-// the Initial Developer. All Rights Reserved.
-//
-// Contributor(s):
-//
-// Alternatively, the contents of this file may be used under the terms of
-// the GNU General Public License Version 2 or later (the "GPL"), in which
-// case the provisions of the GPL are applicable instead of those above. If
-// you wish to allow use of your version of this file only under the terms of
-// the GPL and not to allow others to use your version of this file under the
-// MPL, indicate your decision by deleting the provisions above and replacing
-// them with the notice and other provisions required by the GPL. If you do
-// not delete the provisions above, a recipient may use your version of this
-// file under either the MPL or the GPL.
-//
-// ***** END LICENSE BLOCK *****
-#import <Foundation/Foundation.h>
-
-@interface DIOSConnect : NSObject {
- NSDictionary *connResult;
- NSMutableDictionary *params;
- NSDictionary *myDict;
- NSString *sessid;
- NSString *method;
- NSDictionary *userInfo;
- BOOL isRunning;
- NSTimer *mainTimer;
- NSString *methodUrl;
- NSString *responseStatusMessage;
- NSString *requestMethod;
- NSError *error;
- id progressDelegate;
-}
-@property (nonatomic, retain) NSDictionary *connResult;
-@property (nonatomic, retain) id progressDelegate;
-@property (nonatomic, retain) NSString *sessid;
-@property (nonatomic, retain) NSString *method;
-@property (nonatomic, retain) NSMutableDictionary *params;
-@property (nonatomic, retain) NSDictionary *userInfo;
-@property (nonatomic, retain) NSString *methodUrl;
-@property (nonatomic, retain) NSString *responseStatusMessage;
-@property (nonatomic, retain) NSString *requestMethod;
-@property (nonatomic, readonly) NSError *error;
-
-- (id) init;
-- (void) initWithSessId:(NSString*)aSessId;
-- (void) initWithUserInfo:(NSDictionary*)someUserInfo andSessId:(NSString*)sessId;
-- (void) runMethod;
-- (void) addParam:(id)value forKey:(NSString *)key;
-- (void) removeParam:(NSString *)key;
-- (void) connect;
-- (NSDictionary *) loginWithUsername:(NSString*)userName andPassword:(NSString*)password;
-- (NSDictionary *) logout;
-- (void) connect;
-- (NSString *) buildParams;
-- (NSString *) genRandStringLength;
-- (NSString *)generateHash:(NSString *)inputString;
-- (void)serializedObject:(NSMutableDictionary *)object;
-- (void)serializedArray:(NSArray *)array;
-- (id) initWithSession:(DIOSConnect*)aSession;
-@end
View
313 DIOSConnect.m
@@ -1,313 +0,0 @@
-//
-// DIOSConnect.m
-//
-// ***** BEGIN LICENSE BLOCK *****
-// Version: MPL 1.1/GPL 2.0
-//
-// The contents of this file are subject to the Mozilla Public License Version
-// 1.1 (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-// http://www.mozilla.org/MPL/
-//
-// Software distributed under the License is distributed on an "AS IS" basis,
-// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-// for the specific language governing rights and limitations under the
-// License.
-//
-// The Original Code is Kyle Browning, released June 27, 2010.
-//
-// The Initial Developer of the Original Code is
-// Kyle Browning
-// Portions created by the Initial Developer are Copyright (C) 2010
-// the Initial Developer. All Rights Reserved.
-//
-// Contributor(s):
-//
-// Alternatively, the contents of this file may be used under the terms of
-// the GNU General Public License Version 2 or later (the "GPL"), in which
-// case the provisions of the GPL are applicable instead of those above. If
-// you wish to allow use of your version of this file only under the terms of
-// the GPL and not to allow others to use your version of this file under the
-// MPL, indicate your decision by deleting the provisions above and replacing
-// them with the notice and other provisions required by the GPL. If you do
-// not delete the provisions above, a recipient may use your version of this
-// file under either the MPL or the GPL.
-//
-// ***** END LICENSE BLOCK *****
-#import <CommonCrypto/CommonHMAC.h> //for kCCHmacAlgSHA256
-#import <CommonCrypto/CommonDigest.h> //for CC_SHA256_DIGEST_LENGTH
-#import "DIOSConnect.h"
-#import "ASIHTTPRequest.h"
-#import "ASIFormDataRequest.h"
-#import "NSData+Base64.h"
-#import "DIOSConfig.h"
-@implementation DIOSConnect
-@synthesize connResult, sessid, method, params, userInfo, methodUrl, responseStatusMessage, requestMethod, error, progressDelegate;
-
-/*
- * This init function will automatically connect and setup the session for communicaiton with drupal
- */
-- (id) init {
- [super init];
- error = nil;
- isRunning = NO;
- mainTimer = nil;
- if(params == nil) {
- NSMutableDictionary *newParams = [[NSMutableDictionary alloc] init];
- params = newParams;
- }
- [self setRequestMethod:@"POST"];
- [self connect];
- return self;
-}
-
-//Use this, if you have already connected to Drupal, for example, if the user is logged in, you should
-//Store that session id somewhere and use it anytime you need to make a new drupal call.
-//DIOSConnect should handle there rest.
-- (id) initWithSession:(DIOSConnect*)aSession {
- [super init];
- if ([aSession respondsToSelector:@selector(userInfo)] && [aSession respondsToSelector:@selector(sessid)]) {
- [self setUserInfo:[aSession userInfo]];
- [self setSessid:[aSession sessid]];
- }
- error = nil;
- isRunning = NO;
- mainTimer = nil;
- if(params == nil) {
- NSMutableDictionary *newParams = [[NSMutableDictionary alloc] init];
- params = newParams;
- }
- [self setRequestMethod:@"POST"];
- return self;
-}
-- (void) connect {
- [self setMethod:@"system.connect"];
- [self setMethodUrl:@"system/connect"];
- [self runMethod];
-}
-
-- (NSString*)stringWithHexBytes:(NSData *)theData {
- NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:([theData length] * 2)];
- const unsigned char *dataBuffer = [theData bytes];
- int i;
-
- for (i = 0; i < [theData length]; ++i)
- [stringBuffer appendFormat:@"%02X", (unsigned long)dataBuffer[ i ]];
-
- return [[stringBuffer copy] autorelease];
-}
-
-- (NSString *)generateHash:(NSString *)inputString {
- NSData *key = [DRUPAL_API_KEY dataUsingEncoding:NSUTF8StringEncoding];
- NSData *clearTextData = [inputString dataUsingEncoding:NSUTF8StringEncoding];
- uint8_t digest[CC_SHA256_DIGEST_LENGTH] = {0};
- CCHmacContext hmacContext;
- CCHmacInit(&hmacContext, kCCHmacAlgSHA256, key.bytes, key.length);
- CCHmacUpdate(&hmacContext, clearTextData.bytes, clearTextData.length);
- CCHmacFinal(&hmacContext, digest);
- NSData *hashedData = [NSData dataWithBytes:digest length:32];
- NSString *hashedString = [self stringWithHexBytes:hashedData];
- //NSLog(@"hash string: %@ length: %d",[hashedString lowercaseString],[hashedString length]);
- return [hashedString lowercaseString];
-}
--(NSString *) genRandStringLength {
- NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- NSMutableString *randomString = [NSMutableString stringWithCapacity: 10];
- for (int i=0; i<10; i++) {
- [randomString appendFormat: @"%c", [letters characterAtIndex: arc4random()%[letters length]]];
- }
- return randomString;
-}
-- (void)setError:(NSError *)e
-{
- if (e != error) {
- [error release];
- error = [e retain];
- }
-}
-
-//This runs our method and actually gets a response from drupal
--(void) runMethod {
- //Key Auth doesnt work in REST services
- // NSString *timestamp = [NSString stringWithFormat:@"%d", (long)[[NSDate date] timeIntervalSince1970]];
- // NSString *nonce = [self genRandStringLength];
- // //removed because we have to regen this every call
- // [self removeParam:@"hash"];
- // [self addParam:DRUPAL_DOMAIN forKey:@"domain_name"];
- // [self removeParam:@"domain_name"];
- // [self removeParam:@"domain_time_stamp"];
- // [self removeParam:@"nonce"];
-
- // NSString *hashParams = [NSString stringWithFormat:@"%@;%@;%@;%@",timestamp,DRUPAL_DOMAIN,nonce,[self method]];
- // [self addParam:[self generateHash:hashParams] forKey:@"hash"];
- // [self addParam:DRUPAL_DOMAIN forKey:@"domain_name"];
- // [self addParam:timestamp forKey:@"domain_time_stamp"];
- // [self addParam:nonce forKey:@"nonce"];
-
- [self setError:nil];
- [self removeParam:@"sessid"];
- [self addParam:[self sessid] forKey:@"sessid"];
-
- NSString *url = [NSString stringWithFormat:@"%@/%@", DRUPAL_SERVICES_URL, [self methodUrl]];
-
- ASIHTTPRequest *requestBinary = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
-
- NSString *errorStr;
- NSData *dataRep = [NSPropertyListSerialization dataFromPropertyList: [self params]
- format: NSPropertyListBinaryFormat_v1_0
- errorDescription: &errorStr];
- if([[self requestMethod] isEqualToString:@"POST"] || [[self requestMethod] isEqualToString:@"PUT"]) {
- [requestBinary appendPostData:dataRep];
- }
- [requestBinary setRequestMethod:requestMethod];
- [requestBinary addRequestHeader:@"Content-Type" value:@"application/plist"];
- [requestBinary addRequestHeader:@"Accept" value:@"application/plist"];
- [requestBinary setTimeOutSeconds:300];
- [requestBinary setShouldRedirect:NO];
- [requestBinary setUploadProgressDelegate:progressDelegate];
- [requestBinary startSynchronous];
- responseStatusMessage = [requestBinary responseStatusMessage];
-
- [self setError:[requestBinary error]];
-
-
- if (!error) {
- NSData *response = [requestBinary responseData];
-
- NSPropertyListFormat format;
- id plist = nil;
-
- [self setResponseStatusMessage:[requestBinary responseStatusMessage]];
-
- if(response != nil) {
- plist = [NSPropertyListSerialization propertyListFromData:response
- mutabilityOption:NSPropertyListMutableContainersAndLeaves
- format:&format
- errorDescription:&errorStr];
- if (errorStr) {
- NSError *e = [NSError errorWithDomain:@"DIOS-Error"
- code:1
- userInfo:[NSDictionary dictionaryWithObject:errorStr forKey:NSLocalizedDescriptionKey]];
- [self setError:e];
- [errorStr release];
- NSLog(@"error-response: %@", [requestBinary responseString]);
- }
- } else {
- NSError *e = [NSError errorWithDomain:@"DIOS-Error"
- code:1
- userInfo:[NSDictionary dictionaryWithObject:@"I couldnt get a response, is the site down?" forKey:NSLocalizedDescriptionKey]];
- [self setError:e];
- }
-
- if([requestBinary responseStatusCode] != 200) {
- NSMutableDictionary *errorDetail = [NSMutableDictionary dictionary];
- [errorDetail setValue:[requestBinary responseStatusMessage] forKey:NSLocalizedDescriptionKey];
- [self setError:[NSError errorWithDomain:@"DIOSConnect" code:[requestBinary responseStatusCode] userInfo:errorDetail]];
- }
- if (plist && !error) {
- [self setConnResult:plist];
- if([[self method] isEqualToString:@"system.connect"]) {
- if(plist != nil) {
- [self setSessid:[plist objectForKey:@"sessid"]];
- [self setUserInfo:[plist objectForKey:@"user"]];
- }
- }
- if([[self method] isEqualToString:@"user.login"]) {
- if(plist != nil) {
- [self setSessid:[plist objectForKey:@"sessid"]];
- [self setUserInfo:[plist objectForKey:@"user"]];
- }
- }
- if([[self method] isEqualToString:@"user.logout"]) {
- if(plist != nil) {
- [self setSessid:nil];
- [self setUserInfo:nil];
- }
- }
- }
- }
-
- if(error) {
- NSLog(@"%@", [error localizedDescription]);
- }
- //Bug in ASIHTTPRequest, put here to stop activity indicator
- UIApplication* app = [UIApplication sharedApplication];
- app.networkActivityIndicatorVisible = NO;
-}
-
-- (void) setMethod:(NSString *)aMethod {
- method = aMethod;
- if([params objectForKey:@"method"] == nil) {
- [self addParam:aMethod forKey:@"method"];
- } else {
- [self removeParam:@"method"];
- [self addParam:aMethod forKey:@"method"];
- }
-}
-- (NSString *) buildParams {
- NSString *finalParams;
- NSMutableArray *arrayofParams = nil;
- NSEnumerator *enumerator = [params keyEnumerator];
- NSString *aKey = nil;
- NSString *value = nil;
- while ( (aKey = [enumerator nextObject]) != nil) {
- value = [params objectForKey:aKey];
- [arrayofParams addObject:[NSString stringWithFormat:@"&%@=%@", aKey, value]];
- }
- finalParams = [arrayofParams componentsJoinedByString:@""];
- NSString *finalParamsString = @"";
- for (NSString *string in arrayofParams) {
- finalParamsString = [finalParamsString stringByAppendingString:string];
- }
- return finalParams;
-}
-
-- (void) addParam:(id)value forKey:(NSString *)key {
- if(value != nil) {
- [params setObject:value forKey:key];
- }
-}
-- (void) removeParam:(NSString *)key {
- [params removeObjectForKey:key];
-}
-- (NSString *)description {
- return [NSString stringWithFormat:@"connresult = %@, userInfo = %@, params = %@, sessionid = %@, isRunning = %@", connResult, userInfo, params, sessid, (isRunning ? @"YES" : @"NO")];
-}
-- (void) dealloc {
- [error release];
- [connResult release];
- [sessid release];
- [method release];
- [params release];
- [userInfo release];
- [super dealloc];
-}
-
-#pragma mark
-#pragma mark DEPRECATED METHODS
-// DEPRECATED
-- (void) initWithSessId:(NSString*)aSessId {
- NSAssert(NO, @"DIOSConnect initWithSessID is deprecated, use initWithSession");
-}
-// DEPRECATED
-- (void) initWithUserInfo:(NSDictionary*)someUserInfo andSessId:(NSString*)sessId {
- NSAssert(NO, @"DIOSConnect initWithUserInfo is deprecated, use initWithSession");
-}
-//DEPRECATED -- use DIOSUser
-- (NSDictionary *) loginWithUsername:(NSString*)userName andPassword:(NSString*)password {
- NSAssert(NO, @"DIOSConnect loginWithUsername is deprecated, use DIOSUser");
- return nil;
-}
-//DEPRECATED -- use DIOSUser
-- (NSDictionary *) logout {
- NSAssert(NO, @"DIOSConnect logout is deprecated, use DIOSUser");
- return nil;
-}
-
-- (void)serializedObject:(NSMutableDictionary *)object {
- NSAssert(NO, @"serializedObject NO LONGER NEEDED");
-}
-- (void)serializedArray:(NSArray *)array {
- NSAssert(NO, @"serializedArray NO LONGER NEEDED");
-}
-@end
View
20 DIOSFile.h
@@ -37,10 +37,20 @@
#import <Foundation/Foundation.h>
#import "DIOSConnect.h"
-@interface DIOSFile : DIOSConnect {
+#import "AFHTTPRequestOperation.h"
+#import "DIOSSession.h"
+@protocol DIOSFileDelegate;
-}
-- (NSDictionary *) fileSave:(NSMutableDictionary *)fileDict;
-- (NSDictionary *) fileGet:(NSString *)fid;
-- (NSDictionary *) fileGetNodeFiles:(NSString *)nid;
+@protocol DIOSFileDelegate <NSObject>;
+- (void)fileGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
@end
+
+@interface DIOSFile : NSObject <DIOSFileDelegate> {
+ id <DIOSFileDelegate> delegate;
+}
+@property (weak, nonatomic) id <DIOSFileDelegate> delegate;
+- (id) init;
+- (id) initWithDelegate:(id<DIOSFileDelegate>)aDelegate;
+- (void) fileGet:(NSDictionary *)params;
+- (UIImageView *) getImageViewForFileImage:(NSDictionary *) file;
+@end
View
67 DIOSFile.m
@@ -36,37 +36,50 @@
// ***** END LICENSE BLOCK *****
#import "DIOSFile.h"
-
-
+#import "UIImageView+AFNetworking.h"
@implementation DIOSFile
-
--(id) init {
- [super init];
+@synthesize delegate = _delegate;
+- (id) init {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:self];
return self;
}
-- (NSDictionary *) fileSave:(NSMutableDictionary *)fileDict {
- [self setMethod:@"file.save"];
- [self setParams:fileDict];
- [self setMethodUrl:@"file"];
- [self runMethod];
- return [self connResult];
+- (id) initWithDelegate:(id<DIOSFileDelegate>)aDelegate {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:aDelegate];
+ return self;
+}
+- (void) fileGet:(NSDictionary *)params {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseFile, [params objectForKey:@"fid"]] parameters:params success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(fileGetDidFinish:operation:response:error:)]) {
+ [_delegate fileGetDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(fileGetDidFinish:operation:response:error:)]) {
+ [_delegate fileGetDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void) fileGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
}
-- (NSDictionary *) fileGet:(NSString *)fid {
- [self setMethod:@"file.get"];
- [self setRequestMethod:@"GET"];
- [self setMethodUrl:[NSString stringWithFormat:@"file/%@", fid]];
- [self addParam:fid forKey:@"fid"];
- [self addParam:@"1" forKey:@"file_contents"];
- [self runMethod];
- return [self connResult];
+- (void) fileSave:(NSDictionary *)params {
+ //currently doesnt work :(
}
-- (NSDictionary *) fileGetNodeFiles:(NSString *)nid {
- [self setMethod:@"file.getNodeFiles"];
- [self setRequestMethod:@"POST"];
- [self setMethodUrl:@"file/nodeFiles"];
- [self addParam:nid forKey:@"nid"];
- [self addParam:[NSNumber numberWithInt:1] forKey:@"file_contents"];
- [self runMethod];
- return [self connResult];
+- (UIImageView *) getImageViewForFileImageField:(NSDictionary *) file {
+ NSURL *url = [NSURL URLWithString:[file objectForKey:@"uri_full"]];
+ UIImageView *remoteImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
+ [remoteImage setImageWithURL:url];
+ return remoteImage;
}
@end
View
31 DIOSNode.h
@@ -35,14 +35,29 @@
//
// ***** END LICENSE BLOCK *****
-#import <Foundation/Foundation.h>
-#import "DIOSConnect.h"
+#import "AFHTTPRequestOperation.h"
+#import "DIOSSession.h"
+@protocol DIOSNodeDelegate;
+@protocol DIOSNodeDelegate <NSObject>
+- (void)nodeGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)nodeSaveDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)nodeUpdateDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)nodeDeleteDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)nodeIndexDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)nodeAttachFileDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
-@interface DIOSNode : DIOSConnect {
-}
+@end
--(NSDictionary *) nodeGet:(NSString *)anNid;
--(NSDictionary *) nodeSave:(NSMutableDictionary *)node;
--(NSDictionary *) nodeDelete:(NSString *)nid;
--(NSDictionary *) nodeGetIndex;
+@interface DIOSNode : NSObject <DIOSNodeDelegate>{
+ id <DIOSNodeDelegate> delegate;
+}
+@property (weak, nonatomic) id <DIOSNodeDelegate> delegate;
+- (id) initWithDelegate:(id<DIOSNodeDelegate>)aDelegate;
+- (void)nodeGet:(NSDictionary *)node;
+- (void)nodeSave:(NSDictionary *)node;
+- (void)nodeUpdate:(NSDictionary *)node;
+- (void)nodeDelete:(NSDictionary *)node;
+- (void)nodeIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize;
+- (void)nodeIndex:(NSDictionary *)params;
+- (void)nodeAttachFile:(NSDictionary *)params;
@end
View
201 DIOSNode.m
@@ -33,55 +33,174 @@
// file under either the MPL or the GPL.
//
// ***** END LICENSE BLOCK *****
+
#import "DIOSNode.h"
+#import "AFJSONUtilities.h"
+@implementation DIOSNode
+@synthesize delegate = _delegate;
+- (id) init {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:self];
+ return self;
+}
+- (id) initWithDelegate:(id<DIOSNodeDelegate>)aDelegate {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:aDelegate];
+ return self;
+}
-@implementation DIOSNode
--(id) init {
- [super init];
- return self;
+#pragma mark nodeGets
+- (void)nodeGet:(NSDictionary *)node {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"nid"]] parameters:nil success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(nodeGetDidFinish:operation:response:error:)]) {
+ [_delegate nodeGetDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(nodeGetDidFinish:operation:response:error:)]) {
+ [_delegate nodeGetDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ }];
}
--(NSDictionary *) nodeDelete:(NSString *)nid {
- [self setMethod:@"node.delete"];
- [self setRequestMethod:@"DELETE"];
- [self setMethodUrl:[NSString stringWithFormat:@"node/%@", nid]];
- [self runMethod];
- return [self connResult];
+- (void)nodeGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
}
--(NSDictionary *) nodeGet:(NSString *)nid {
- [self setMethod:@"node.get"];
- [self setRequestMethod:@"GET"];
- [self setMethodUrl:[NSString stringWithFormat:@"node/%@", nid]];
- [self runMethod];
- return [self connResult];
+
+#pragma mark nodeUpdates
+- (void)nodeSave:(NSDictionary *)node {
+ [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseNode] parameters:node success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(nodeUpdateDidFinish:operation:response:error:)]) {
+ [_delegate nodeUpdateDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(nodeUpdateDidFinish:operation:response:error:)]) {
+ [_delegate nodeUpdateDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
+ }
+ }];
}
--(NSDictionary *) nodeSave:(NSMutableDictionary *)node {
- [self setMethod:@"node.save"];
- [self setMethodUrl:@"node"];
- if ([[[self userInfo] objectForKey:@"uid"] isEqualToNumber:[NSNumber numberWithInt:0]]) {
- [node setObject:@"" forKey:@"name"];
- } else if([self userInfo] == nil){
- [node setObject:@"" forKey:@"name"];
- } else {
- [node setObject:[[self userInfo] objectForKey:@"name"] forKey:@"name"];
- }
- if ([node objectForKey:@"nid"] != nil && ![[node objectForKey:@"nid"] isEqualToString:@""]) {
- [self setMethodUrl:[NSString stringWithFormat:@"node/%@", [node objectForKey:@"nid"]]];
- [self setRequestMethod:@"PUT"];
- }
- [self setParams:node];
- [self runMethod];
- return [self connResult];
+- (void)nodeSaveDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
}
--(NSDictionary *) nodeGetIndex {
- [self setMethod:@"node.get"];
- [self setRequestMethod:@"GET"];
- [self setMethodUrl:[NSString stringWithFormat:@"node"]];
- [self runMethod];
- return [self connResult];
+
+#pragma mark nodeUpdate
+- (void)nodeUpdate:(NSDictionary *)node {
+ [[DIOSSession sharedSession] putPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"cid"]] parameters:node success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(nodeUpdateDidFinish:operation:response:error:)]) {
+ [_delegate nodeUpdateDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this put so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(nodeUpdateDidFinish:operation:response:error:)]) {
+ [_delegate nodeUpdateDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this put so my response will never be used.", _delegate);
+ }
+ }];
}
-- (void) dealloc {
- [super dealloc];
+- (void)nodeUpdateDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark nodeDelete
+- (void)nodeDelete:(NSDictionary *)node {
+ [[DIOSSession sharedSession] deletePath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseNode, [node objectForKey:@"cid"]] parameters:node success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(nodeDeleteDidFinish:operation:response:error:)]) {
+ [_delegate nodeDeleteDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(nodeDeleteDidFinish:operation:response:error:)]) {
+ [_delegate nodeDeleteDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)nodeDeleteDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+#pragma mark nodeIndex
+//Simpler method if you didnt want to build the params :)
+- (void)nodeIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize {
+ NSMutableDictionary *nodeIndexDict = [NSMutableDictionary new];
+ [nodeIndexDict setValue:page forKey:@"page"];
+ [nodeIndexDict setValue:fields forKey:@"fields"];
+ [nodeIndexDict setValue:parameteres forKey:@"parameters"];
+ [nodeIndexDict setValue:pageSize forKey:@"pagesize"];
+ [self nodeIndex:nodeIndexDict];
+}
+
+- (void)nodeIndex:(NSDictionary *)params {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseNode] parameters:params success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(nodeIndexDidFinish:operation:response:error:)]) {
+ [_delegate nodeIndexDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(nodeIndexDidFinish:operation:response:error:)]) {
+ [_delegate nodeIndexDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)nodeIndexDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark nodeAttachFile
+- (void)nodeAttachFile:(NSDictionary *)params {
+ NSMutableURLRequest *request = [[DIOSSession sharedSession] multipartFormRequestWithMethod:@"POST" path:[NSString stringWithFormat:@"%@/%@/%@/attach_file?field_name=%@", kDiosEndpoint, kDiosBaseNode, [params objectForKey:@"nid"], [params objectForKey:@"field_name"]] parameters:params constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
+ [formData appendPartWithFileData:[params objectForKey:@"fileData"] name:[params objectForKey:@"name"] fileName:[params objectForKey:@"fileName"] mimeType:[params objectForKey:@"mimetype"]];
+ }];
+ AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
+ [operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
+ NSLog(@"Sent %d of %d bytes", totalBytesWritten, totalBytesExpectedToWrite);
+ }];
+ [operation setCompletionBlockWithSuccess:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ NSError *error = nil;
+ JSON = AFJSONDecode(JSON, &error);
+ if(!error) {
+ if ([_delegate respondsToSelector:@selector(nodeAttachFileDidFinish:operation:response:error:)]) {
+ [_delegate nodeAttachFileDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } else {
+ if ([_delegate respondsToSelector:@selector(nodeAttachFileDidFinish:operation:response:error:)]) {
+ [_delegate nodeAttachFileDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(nodeAttachFileDidFinish:operation:response:error:)]) {
+ [_delegate nodeAttachFileDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+ [operation start];
+}
+- (void)nodeAttachFileDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
}
@end
View
21 DIOSViews.h → DIOSSession.h
@@ -1,5 +1,5 @@
//
-// DIOSViews.h
+// DIOSNode.h
@kylebrowning Owner

whoops

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
//
// ***** BEGIN LICENSE BLOCK *****
// Version: MPL 1.1/GPL 2.0
@@ -34,13 +34,22 @@
// file under either the MPL or the GPL.
//
// ***** END LICENSE BLOCK *****
+
#import <Foundation/Foundation.h>
-#import "DIOSConnect.h"
+#import "AFHTTPClient.h"
+#import "Settings.h"
+@protocol DIOSSessionDelegate;
-@interface DIOSViews : DIOSConnect {
+@protocol DIOSSessionDelegate <NSObject>
+- (void)callDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+@end
+@interface DIOSSession : AFHTTPClient <DIOSSessionDelegate>{
+ id <DIOSSessionDelegate> delegate;
+ NSDictionary *user;
}
-- (id) init;
-- (void) initViews;
--(NSDictionary *) viewsGet:(NSString *)viewName;
+@property (strong, nonatomic) id <DIOSSessionDelegate> delegate;
+@property (strong, nonatomic) NSDictionary *user;
++ (DIOSSession *)sharedSession;
@end
+
View
80 DIOSSession.m
@@ -0,0 +1,80 @@
+//
+// DIOSNode.h
+//
+// ***** BEGIN LICENSE BLOCK *****
+// Version: MPL 1.1/GPL 2.0
+//
+// The contents of this file are subject to the Mozilla Public License Version
+// 1.1 (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+// http://www.mozilla.org/MPL/
+//
+// Software distributed under the License is distributed on an "AS IS" basis,
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+// for the specific language governing rights and limitations under the
+// License.
+//
+// The Original Code is Kyle Browning, released June 27, 2010.
+//
+// The Initial Developer of the Original Code is
+// Kyle Browning
+// Portions created by the Initial Developer are Copyright (C) 2010
+// the Initial Developer. All Rights Reserved.
+//
+// Contributor(s):
+//
+// Alternatively, the contents of this file may be used under the terms of
+// the GNU General Public License Version 2 or later (the "GPL"), in which
+// case the provisions of the GPL are applicable instead of those above. If
+// you wish to allow use of your version of this file only under the terms of
+// the GPL and not to allow others to use your version of this file under the
+// MPL, indicate your decision by deleting the provisions above and replacing
+// them with the notice and other provisions required by the GPL. If you do
+// not delete the provisions above, a recipient may use your version of this
+// file under either the MPL or the GPL.
+//
+// ***** END LICENSE BLOCK *****
+
+#import "DIOSSession.h"
+#import "AFJSONRequestOperation.h"
+#import "AFPropertyListRequestOperation.h"
+
+@implementation DIOSSession
+@synthesize delegate, user;
++ (DIOSSession *)sharedSession {
+ static dispatch_once_t once;
+ static DIOSSession *sharedSession;
+ dispatch_once(&once, ^ {
+ sharedSession = [[self alloc] initWithBaseURL:[NSURL URLWithString:kDiosBaseUrl]];
+ [sharedSession setParameterEncoding:AFJSONParameterEncoding];
+ });
+ return sharedSession;
+}
+
+- (id)initWithBaseURL:(NSURL *)url {
+ self = [super initWithBaseURL:url];
+ if (!self) {
+ return nil;
+ }
+
+ [self registerHTTPOperationClass:[AFJSONRequestOperation class]];
+ [self setDelegate:self];
+ // Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
+ [self setDefaultHeader:@"Accept" value:@"application/json"];
+ [self setDefaultHeader:@"Content-Type" value:@"application/json"];
+
+ return self;
+}
+- (void)callDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ if(status) {
+ //success!
+ NSString *localizedStatusCodeString = [NSHTTPURLResponse localizedStringForStatusCode:[[operation response] statusCode]];
+ DLog(@"SUCCESS: %d %@ %@, %@", [[operation response] statusCode], localizedStatusCodeString, [operation responseString], response);
+ } else {
+ //something happened im sorry!
+ // DLog(@"%@", [[operation response] allHeaderFields]);
+ NSString *localizedStatusCodeString = [NSHTTPURLResponse localizedStringForStatusCode:[[operation response] statusCode]];
+ DLog(@"FAILED: %d %@ %@ %@ %@", [[operation response] statusCode], localizedStatusCodeString, [operation responseString], response, operation);
+ }
+}
+@end
View
28 DIOSTaxonomy.h
@@ -35,15 +35,25 @@
//
// ***** END LICENSE BLOCK *****
-#import <Foundation/Foundation.h>
-#import "DIOSConnect.h"
+#import "AFHTTPRequestOperation.h"
+#import "DIOSSession.h"
+@protocol DIOSTaxonomyDelegate;
-@interface DIOSTaxonomy : DIOSConnect {
+@protocol DIOSTaxonomyDelegate <NSObject>;
+- (void)getTreeDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)selectNodesDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)getTermDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+@end
+@interface DIOSTaxonomy : NSObject <DIOSTaxonomyDelegate> {
+ id <DIOSTaxonomyDelegate> delegate;
}
-- (NSDictionary *)getTree:(NSString*)vid;
-- (NSDictionary *)getTree:(NSString*)vid withParent:(NSString*)parent andMaxDepth:(NSString*)maxDepth;
-- (NSDictionary *)selectNodes:(NSString*)tid;
-- (NSDictionary *)selectNodes:(NSString*)tid andLimit:(NSString*)depth pager:(BOOL)pager andOrder:(NSString*)anOrder;
-- (NSDictionary *)getTerm:(NSString*)tid;
-@end
+@property (weak, nonatomic) id <DIOSTaxonomyDelegate> delegate;
+- (id) init;
+- (id) initWithDelegate:(id<DIOSTaxonomyDelegate>)aDelegate;
+- (void)getTreeWithParams:(NSDictionary *)params;
+- (void)getTreeWithVid:(NSString *)vid withParent:(NSString *)parent andMaxDepth:(NSString *)maxDepth;
+- (void)selectNodesWithParams:(NSDictionary *)params;
+- (void)selectNodesWithTid:(NSString *)tid andLimit:(NSString *)limit andPager:(NSString *)pager andOrder:(NSString *)order;
+- (void)getTermWithTid:(NSString *)tid;
+@end
View
135 DIOSTaxonomy.m
@@ -37,81 +37,92 @@
#import "DIOSTaxonomy.h"
-
@implementation DIOSTaxonomy
+@synthesize delegate = _delegate;
- (id) init {
- [super init];
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:self];
+ return self;
+}
+- (id) initWithDelegate:(id<DIOSTaxonomyDelegate>)aDelegate {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:aDelegate];
return self;
}
-- (NSDictionary *)getTree:(NSString*)vid {
- return [self getTree:vid withParent:nil andMaxDepth:nil];
+
+- (void)getTreeWithVid:(NSString *)vid withParent:(NSString *)parent andMaxDepth:(NSString *)maxDepth {
+ NSMutableDictionary *params = [NSMutableDictionary new];
+ [params setValue:vid forKey:@"vid"];
+ [params setValue:parent forKey:@"parent"];
+ [params setValue:maxDepth forKey:@"max_depth"];
+ [self getTreeWithParams:params];
}
-- (NSDictionary *)getTree:(NSString*)vid withParent:(NSString*)parent andMaxDepth:(NSString*)maxDepth {
- [self setMethod:@"taxonomy.getTree"];
- [self setRequestMethod:@"POST"];
- [self setMethodUrl:@"taxonomy_vocabulary/getTree"];
- if (vid != nil) {
- [self addParam:vid forKey:@"vid"];
-
- if (parent != nil) {
- [self addParam:parent forKey:@"parent"];
+- (void)getTreeWithParams:(NSDictionary *)params {
+ [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@/getTree", kDiosEndpoint, kDiosBaseTaxonmyVocabulary] parameters:params success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(getTreeDidFinish:operation:response:error:)]) {
+ [_delegate getTreeDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
}
- if (maxDepth != nil) {
- [self addParam:maxDepth forKey:@"max_depth"];
- }
-
- [self runMethod];
-
- return [self connResult];
- }
- //vid is required
- return nil;
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(getTreeDidFinish:operation:response:error:)]) {
+ [_delegate getTreeDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
+ }
+ }];
}
-- (NSArray *)selectNodes:(NSString*)tid {
- return [self selectNodes:tid andLimit:nil pager:FALSE andOrder:nil];
+- (void)selectNodesWithTid:(NSString *)tid andLimit:(NSString *)limit andPager:(NSString *)pager andOrder:(NSString *)order {
+ NSMutableDictionary *params = [NSMutableDictionary new];
+ [params setValue:tid forKey:@"tid"];
+ [params setValue:limit forKey:@"limit"];
+ [params setValue:pager forKey:@"pager"];
+ [params setValue:order forKey:@"prder"];
+ [self selectNodesWithParams:params];
}
-/*
- * selectNodes
- * see admin/build/services/browse/taxonomy.selectNodes
- * tids and fields should be comma seperated
- */
-- (NSArray *)selectNodes:(NSString*)tid andLimit:(NSString*)limit pager:(BOOL)pager andOrder:(NSString*)anOrder {
- [self setMethod:@"taxonomy.selectNodes"];
- [self setRequestMethod:@"POST"];
- [self setMethodUrl:@"taxonomy_term/selectNodes"];
- if (tid != nil) {
- [self addParam:tid forKey:@"tid"];
-
- if (limit != nil) {
- [self addParam:limit forKey:@"depth"];
+- (void)selectNodesWithParams:(NSDictionary *)params {
+ [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@/selectNodes", kDiosEndpoint, kDiosBaseTaxonmyTerm] parameters:params success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(selectNodesDidFinish:operation:response:error:)]) {
+ [_delegate selectNodesDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
}
- if (anOrder != nil) {
- [self addParam:limit forKey:@"order"];
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(selectNodesDidFinish:operation:response:error:)]) {
+ [_delegate selectNodesDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
}
- if (pager == NO) {
- [self addParam:[NSNumber numberWithInt:0] forKey:@"pager"];
+ }];
+}
+- (void)getTermWithTid:(NSString *)tid {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseTaxonmyTerm, tid] parameters:nil success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(getTreeDidFinish:operation:response:error:)]) {
+ [_delegate getTreeDidFinish:YES operation:operation response:JSON error:nil];
} else {
- if (pager == YES) {
- [self addParam:[NSNumber numberWithInt:1] forKey:@"pager"];
- }
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
}
- [self runMethod];
- if([[self connResult] isKindOfClass:[NSString class]]) {
- if([(NSString *)[self connResult] isEqualToString:@""]) {
- return nil;
- }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(getTreeDidFinish:operation:response:error:)]) {
+ [_delegate getTreeDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
}
- return (NSArray *)[self connResult];
- }
- //tid is required
- return nil;
+ }];
}
-
-- (NSDictionary *)getTerm:(NSString*)tid {
- [self setMethod:@"taxonomy_term.get"];
- [self setRequestMethod:@"GET"];
- [self setMethodUrl:[NSString stringWithFormat:@"taxonomy_term/%@", tid]];
- [self runMethod];
- return [self connResult];
+- (void)getTreeDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+- (void)selectNodesDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+- (void)getTermDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
}
@end
View
33 DIOSUser.h
@@ -34,15 +34,32 @@
// file under either the MPL or the GPL.
//
// ***** END LICENSE BLOCK *****
-#import <Foundation/Foundation.h>
-#import "DIOSConnect.h"
-@interface DIOSUser : DIOSConnect {
+#import "AFHTTPRequestOperation.h"
+#import "DIOSSession.h"
+@protocol DIOSUserDelegate;
+@protocol DIOSUserDelegate <NSObject>
+- (void)userGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)userSaveDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)userUpdateDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)userDeleteDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)userIndexDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)userLoginDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+- (void)userLogoutDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error;
+@end
+@interface DIOSUser : NSObject <DIOSUserDelegate>{
+ id <DIOSUserDelegate> delegate;
}
-- (NSDictionary *) loginWithUsername:(NSString*)userName andPassword:(NSString*)password;
-- (NSDictionary *) logout;
-- (NSDictionary *) userSave:(NSMutableDictionary *)userDict;
-- (NSDictionary *) userDelete:(NSString*)uid;
-- (NSDictionary *) userGet:(NSString*)uid;
+@property (weak, nonatomic) id <DIOSUserDelegate> delegate;
+- (id) initWithDelegate:(id<DIOSUserDelegate>)aDelegate;
+- (void)userGet:(NSDictionary *)user;
+- (void)userSave:(NSDictionary *)user;
+- (void)userUpdate:(NSDictionary *)user;
+- (void)userDelete:(NSDictionary *)user;
+- (void)userIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize;
+- (void)userIndex:(NSDictionary *)params;
+- (void)userLogin:(NSDictionary *)user;
+- (void)userLoginWithUsername:(NSString *)username andPassword:(NSString *)password;
+- (void)userLogout;
@end
View
218 DIOSUser.m
@@ -34,57 +34,181 @@
// file under either the MPL or the GPL.
//
// ***** END LICENSE BLOCK *****
-#import "DIOSUser.h"
+#import "DIOSUser.h"
@implementation DIOSUser
--(id) init {
- [super init];
+@synthesize delegate = _delegate;
+- (id) init {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:self];
return self;
}
-- (NSDictionary *) loginWithUsername:(NSString*)userName andPassword:(NSString*)password {
- [self setMethod:@"user.login"];
- [self setMethodUrl:@"user/login"];
- [self addParam:userName forKey:@"username"];
- [self addParam:password forKey:@"password"];
- [self runMethod];
- return [self connResult];
+- (id) initWithDelegate:(id<DIOSUserDelegate>)aDelegate {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+ [self setDelegate:aDelegate];
+ return self;
}
-- (NSDictionary *) logout {
- [self setMethod:@"user.logout"];
- [self setMethodUrl:@"user/logout"];
- [self runMethod];
- return [self connResult];
-}
-- (NSDictionary *) userSave:(NSMutableDictionary *)userDict {
- [self setMethod:@"user.save"];
- [self setMethodUrl:@"user"];
- if ([userDict objectForKey:@"uid"] != nil && ![[userDict objectForKey:@"uid"] isEqualToString:@""]) {
- [self setMethodUrl:[NSString stringWithFormat:@"user/%@", [userDict objectForKey:@"uid"]]];
- [self setRequestMethod:@"PUT"];
- [self addParam:userDict forKey:@"data"];
- [self addParam:[userDict objectForKey:@"uid"] forKey:@"uid"];
- } else {
- [self addParam:userDict forKey:@"account"];
- }
-
- [self runMethod];
- return [self connResult];
-}
-- (NSDictionary *) userGet:(NSString*)uid {
- [self setMethod:@"user.get"];
- [self setRequestMethod:@"GET"];
- [self setMethodUrl:[NSString stringWithFormat:@"user/%@", uid]];
- [self runMethod];
-
- return [self connResult];
-}
-- (NSDictionary *) userDelete:(NSString*)uid {
- [self setMethod:@"user.delete"];
- [self setRequestMethod:@"DELETE"];
- [self setMethodUrl:[NSString stringWithFormat:@"user/%@", uid]];
- [self runMethod];
- return [self connResult];
-}
-@end
+#pragma mark UserGets
+- (void)userGet:(NSDictionary *)user {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseUser, [user objectForKey:@"uid"]] parameters:nil success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(userGetDidFinish:operation:response:error:)]) {
+ [_delegate userGetDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(userGetDidFinish:operation:response:error:)]) {
+ [_delegate userGetDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this get so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)userGetDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ DIOSSession *session = [DIOSSession sharedSession];
+ [[session delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark userSaves
+- (void)userSave:(NSDictionary *)user {
+ [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseUser] parameters:user success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(userSaveDidFinish:operation:response:error:)]) {
+ [_delegate userSaveDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(userSaveDidFinish:operation:response:error:)]) {
+ [_delegate userSaveDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this post so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)userSaveDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark userUpdate
+- (void)userUpdate:(NSDictionary *)user {
+ [[DIOSSession sharedSession] putPath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseUser, [user objectForKey:@"uid"]] parameters:user success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(userUpdateDidFinish:operation:response:error:)]) {
+ [_delegate userUpdateDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this put so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(userUpdateDidFinish:operation:response:error:)]) {
+ [_delegate userUpdateDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this put so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)userUpdateDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark UserDelete
+- (void)userDelete:(NSDictionary *)user {
+ [[DIOSSession sharedSession] deletePath:[NSString stringWithFormat:@"%@/%@/%@", kDiosEndpoint, kDiosBaseUser, [user objectForKey:@"uid"]] parameters:user success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(userDeleteDidFinish:operation:response:error:)]) {
+ [_delegate userDeleteDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(userDeleteDidFinish:operation:response:error:)]) {
+ [_delegate userDeleteDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)userDeleteDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark userIndex
+//Simpler method if you didnt want to build the params :)
+- (void)userIndexWithPage:(NSString *)page fields:(NSString *)fields parameters:(NSArray *)parameteres pageSize:(NSString *)pageSize {
+ NSMutableDictionary *userIndexDict = [NSMutableDictionary new];
+ [userIndexDict setValue:page forKey:@"page"];
+ [userIndexDict setValue:fields forKey:@"fields"];
+ [userIndexDict setValue:parameteres forKey:@"parameters"];
+ [userIndexDict setValue:pageSize forKey:@"pagesize"];
+ [self userIndex:userIndexDict];
+}
+
+- (void)userIndex:(NSDictionary *)params {
+ [[DIOSSession sharedSession] getPath:[NSString stringWithFormat:@"%@/%@", kDiosEndpoint, kDiosBaseUser] parameters:params success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(userIndexDidFinish:operation:response:error:)]) {
+ [_delegate userIndexDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(userIndexDidFinish:operation:response:error:)]) {
+ [_delegate userIndexDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)userIndexDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+
+#pragma mark userLogin
+- (void)userLoginWithUsername:(NSString *)username andPassword:(NSString *)password {
+ NSDictionary *params = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:username, password, nil] forKeys:[NSArray arrayWithObjects:@"username", @"password", nil]];
+ [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@/login", kDiosEndpoint, kDiosBaseUser] parameters:params success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(userLoginDidFinish:operation:response:error:)]) {
+ [[DIOSSession sharedSession] setUser:JSON];
+ [_delegate userLoginDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(userLoginDidFinish:operation:response:error:)]) {
+ [_delegate userLoginDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)userLogin:(NSDictionary *)user {
+ [self userLoginWithUsername:[user objectForKey:@"name"] andPassword:[user objectForKey:@"pass"]];
+}
+- (void)userLoginDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+#pragma mark userLogout
+- (void)userLogout {
+ [[DIOSSession sharedSession] postPath:[NSString stringWithFormat:@"%@/%@/logout", kDiosEndpoint, kDiosBaseUser] parameters:nil success:^(__unused AFHTTPRequestOperation *operation, id JSON) {
+ if ([_delegate respondsToSelector:@selector(userLogoutDidFinish:operation:response:error:)]) {
+ [[DIOSSession sharedSession] setUser:nil];
+ [_delegate userLogoutDidFinish:YES operation:operation response:JSON error:nil];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ } failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
+ if ([_delegate respondsToSelector:@selector(userLogoutDidFinish:operation:response:error:)]) {
+ [_delegate userLogoutDidFinish:NO operation:operation response:nil error:error];
+ } else {
+ DLog(@"I couldnt find the delegate and one was set %@ for this delete so my response will never be used.", _delegate);
+ }
+ }];
+}
+- (void)userLogoutDidFinish:(BOOL)status operation:(AFHTTPRequestOperation *)operation response:(id)response error:(NSError*)error {
+ [[[DIOSSession sharedSession] delegate] callDidFinish:status operation:operation response:response error:error];
+}
+@end
View
59 DIOSViews.m
@@ -1,59 +0,0 @@
-//
-// DIOSViews.h
-//
-// ***** BEGIN LICENSE BLOCK *****
-// Version: MPL 1.1/GPL 2.0
-//
-// The contents of this file are subject to the Mozilla Public License Version
-// 1.1 (the "License"); you may not use this file except in compliance with
-// the License. You may obtain a copy of the License at
-// http://www.mozilla.org/MPL/
-//
-// Software distributed under the License is distributed on an "AS IS" basis,
-// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-// for the specific language governing rights and limitations under the
-// License.
-//
-// The Original Code is Kyle Browning, released June 27, 2010.
-//
-// The Initial Developer of the Original Code is
-// Kyle Browning
-// Portions created by the Initial Developer are Copyright (C) 2010
-// the Initial Developer. All Rights Reserved.
-//
-// Contributor(s):
-//
-// Alternatively, the contents of this file may be used under the terms of
-// the GNU General Public License Version 2 or later (the "GPL"), in which
-// case the provisions of the GPL are applicable instead of those above. If
-// you wish to allow use of your version of this file only under the terms of
-// the GPL and not to allow others to use your version of this file under the
-// MPL, indicate your decision by deleting the provisions above and replacing
-// them with the notice and other provisions required by the GPL. If you do
-// not delete the provisions above, a recipient may use your version of this
-// file under either the MPL or the GPL.
-//
-// ***** END LICENSE BLOCK *****
-
-
-#import "DIOSViews.h"
-
-
-@implementation DIOSViews
-- (id) init {
- [super init];
- [self setMethod:@"views.get"];
- return self;
-}
-- (void) initViews {
- [self setMethod:@"views.get"];
- [self setMethodUrl:@"views"];
-}
--(NSDictionary *) viewsGet:(NSString *)viewName {
- [self setMethod:@"views.get"];
- [self setRequestMethod:@"GET"];
- [self setMethodUrl:[NSString stringWithFormat:@"views/%@", viewName]];
- [self runMethod];
- return [self connResult];
-}
-@end
View
33 LICENSE
@@ -1,5 +1,5 @@
//
-// ***** BEGIN LICENSE BLOCK *****
+// ***** BEGIN drupal-ios-sdk BLOCK *****
// Version: MPL 1.1/GPL 2.0
//
// The contents of this file are subject to the Mozilla Public License Version
@@ -20,7 +20,8 @@
// the Initial Developer. All Rights Reserved.
//
// Contributor(s):
-//
+// Mark Dorison
+// Jeff Linwood
// Alternatively, the contents of this file may be used under the terms of
// the GNU General Public License Version 2 or later (the "GPL"), in which
// case the provisions of the GPL are applicable instead of those above. If
@@ -30,5 +31,29 @@
// them with the notice and other provisions required by the GPL. If you do
// not delete the provisions above, a recipient may use your version of this
// file under either the MPL or the GPL.
-//
-// ***** END LICENSE BLOCK *****
+// ***** END drupal-ios-sdk BLOCK *****
+
+// ***** BEGIN AFNETWORK LICENSE BLOCK *****
+Copyright (c) 2011 Gowalla (http://gowalla.com/)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+// **** END AFNETWORK LICENSE ****
+
+
View
33 NSData_Base64/NSData+Base64.h
@@ -1,33 +0,0 @@
-//
-// NSData+Base64.h
-// base64
-//
-// Created by Matt Gallagher on 2009/06/03.
-// Copyright 2009 Matt Gallagher. All rights reserved.
-//
-// Permission is given to use this source code file, free of charge, in any
-// project, commercial or otherwise, entirely at your risk, with the condition
-// that any redistribution (in part or whole) of source code must retain
-// this copyright and permission notice. Attribution in compiled projects is
-// appreciated but not required.
-//
-
-#import <Foundation/Foundation.h>
-
-void *NewBase64Decode(
- const char *inputBuffer,
- size_t length,
- size_t *outputLength);
-
-char *NewBase64Encode(
- const void *inputBuffer,
- size_t length,
- bool separateLines,
- size_t *outputLength);
-
-@interface NSData (Base64)
-
-+ (NSData *)dataFromBase64String:(NSString *)aString;
-- (NSString *)base64EncodedString;
-
-@end
View
299 NSData_Base64/NSData+Base64.m
@@ -1,299 +0,0 @@
-//
-// NSData+Base64.m
-// base64
-//
-// Created by Matt Gallagher on 2009/06/03.
-// Copyright 2009 Matt Gallagher. All rights reserved.
-//
-// Permission is given to use this source code file, free of charge, in any
-// project, commercial or otherwise, entirely at your risk, with the condition
-// that any redistribution (in part or whole) of source code must retain
-// this copyright and permission notice. Attribution in compiled projects is
-// appreciated but not required.
-//
-
-#import "NSData+Base64.h"
-
-//
-// Mapping from 6 bit pattern to ASCII character.
-//
-static unsigned char base64EncodeLookup[65] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
-//
-// Definition for "masked-out" areas of the base64DecodeLookup mapping
-//
-#define xx 65
-
-//
-// Mapping from ASCII character to 6 bit pattern.
-//
-static unsigned char base64DecodeLookup[256] =
-{
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 62, xx, xx, xx, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, xx, xx, xx, xx, xx, xx,
- xx, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, xx, xx, xx, xx, xx,
- xx, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
- xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
-};
-
-//
-// Fundamental sizes of the binary and base64 encode/decode units in bytes
-//
-#define BINARY_UNIT_SIZE 3
-#define BASE64_UNIT_SIZE 4
-
-//
-// NewBase64Decode
-//
-// Decodes the base64 ASCII string in the inputBuffer to a newly malloced
-// output buffer.
-//
-// inputBuffer - the source ASCII string for the decode
-// length - the length of the string or -1 (to specify strlen should be used)
-// outputLength - if not-NULL, on output will contain the decoded length
-//
-// returns the decoded buffer. Must be free'd by caller. Length is given by
-// outputLength.
-//
-void *NewBase64Decode(
- const char *inputBuffer,
- size_t length,
- size_t *outputLength)
-{
- if (length == -1)
- {
- length = strlen(inputBuffer);
- }
-
- size_t outputBufferSize =
- ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE;
- unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize);
-
- size_t i = 0;
- size_t j = 0;
- while (i < length)
- {
- //
- // Accumulate 4 valid characters (ignore everything else)
- //
- unsigned char accumulated[BASE64_UNIT_SIZE];
- size_t accumulateIndex = 0;
- while (i < length)
- {
- unsigned char decode = base64DecodeLookup[inputBuffer[i++]];
- if (decode != xx)
- {
- accumulated[accumulateIndex] = decode;
- accumulateIndex++;
-
- if (accumulateIndex == BASE64_UNIT_SIZE)
- {
- break;
- }
- }
- }
-
- //
- // Store the 6 bits from each of the 4 characters as 3 bytes
- //
- outputBuffer[j] = (accumulated[0] << 2) | (accumulated[1] >> 4);
- outputBuffer[j + 1] = (accumulated[1] << 4) | (accumulated[2] >> 2);
- outputBuffer[j + 2] = (accumulated[2] << 6) | accumulated[3];
- j += accumulateIndex - 1;
- }
-
- if (outputLength)
- {
- *outputLength = j;
- }
- return outputBuffer;
-}
-
-//
-// NewBase64Decode
-//
-// Encodes the arbitrary data in the inputBuffer as base64 into a newly malloced
-// output buffer.
-//
-// inputBuffer - the source data for the encode
-// length - the length of the input in bytes
-// separateLines - if zero, no CR/LF characters will be added. Otherwise
-// a CR/LF pair will be added every 64 encoded chars.
-// outputLength - if not-NULL, on output will contain the encoded length
-// (not including terminating 0 char)
-//
-// returns the encoded buffer. Must be free'd by caller. Length is given by
-// outputLength.
-//
-char *NewBase64Encode(
- const void *buffer,
- size_t length,
- bool separateLines,
- size_t *outputLength)
-{
- const unsigned char *inputBuffer = (const unsigned char *)buffer;
-
- #define MAX_NUM_PADDING_CHARS 2
- #define OUTPUT_LINE_LENGTH 64
- #define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE)
- #define CR_LF_SIZE 2
-
- //
- // Byte accurate calculation of final buffer size
- //
- size_t outputBufferSize =
- ((length / BINARY_UNIT_SIZE)
- + ((length % BINARY_UNIT_SIZE) ? 1 : 0))
- * BASE64_UNIT_SIZE;
- if (separateLines)
- {
- outputBufferSize +=
- (outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE;
- }
-
- //
- // Include space for a terminating zero
- //
- outputBufferSize += 1;
-
- //
- // Allocate the output buffer
- //
- char *outputBuffer = (char *)malloc(outputBufferSize);
- if (!outputBuffer)
- {
- return NULL;
- }
-
- size_t i = 0;
- size_t j = 0;
- const size_t lineLength = separateLines ? INPUT_LINE_LENGTH : length;
- size_t lineEnd = lineLength;
-
- while (true)
- {
- if (lineEnd > length)
- {
- lineEnd = length;
- }
-
- for (; i + BINARY_UNIT_SIZE - 1 < lineEnd; i += BINARY_UNIT_SIZE)
- {
- //
- // Inner loop: turn 48 bytes into 64 base64 characters
- //
- outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2];
- outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4)
- | ((inputBuffer[i + 1] & 0xF0) >> 4)];
- outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i + 1] & 0x0F) << 2)
- | ((inputBuffer[i + 2] & 0xC0) >> 6)];
- outputBuffer[j++] = base64EncodeLookup[inputBuffer[i + 2] & 0x3F];
- }
-
- if (lineEnd == length)
- {
- break;
- }
-
- //
- // Add the newline
- //
- outputBuffer[j++] = '\r';
- outputBuffer[j++] = '\n';
- lineEnd += lineLength;
- }
-
- if (i + 1 < length)
- {
- //
- // Handle the single '=' case
- //
- outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2];
- outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4)
- | ((inputBuffer[i + 1] & 0xF0) >> 4)];
- outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i + 1] & 0x0F) << 2];
- outputBuffer[j++] = '=';
- }
- else if (i < length)