Git Product home page Git Product logo

drupal-ios-sdk's Introduction

Drupal iOS SDK - Connect your iOS/OS X app to Drupal

What you need to know

The Drupal iOS SDK is a standard set of libraries for communicating to Drupal from any iOS device. Its extremely simple. This GETs you a Drupal node and stores it in an NSDictionary, myNode.

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
NSDictionary *myNode = [node nodeGet:1];
[node release];

What you need to get started

####XCode

  • This library
  • the following frameworks
    • UIKit.Framework
    • CoreGraphics.framework
    • CFNetwork.framework
    • libz.1.2.3.dylib
    • SystemConfiguration.framework
    • MobileCoreServices.framework
    • ASIHTTPRequest which can be found here
  • Update DIOSConfig.h with the correct API_KEYS SERVICES_URL and DOMAIN (make sure you checkout the drupal-ios-sdk branch for your version of drupal eg. 6.x-2.x, 6.x-3.x or 7.x-3.x)

####Drupal 6.x-2.x (NOT RECOMMENDED, Services 2.x is running 5 year old code. I would suggest using 3.x now that it is in RC stage.

####Drupal 6.x-3.x and 7.x-3.x (RECOMMENDED)

####Note, Services 3.x does not have an API key, it doesn't use them, IT HAS BEEN REMOVED. Use oAuth if you need extra Security.

Demo Setup (Services 3.x) http://vimeo.com/22635252

Session

DIOSConnect *session = [[DIOSConnect alloc] init];

Views

DIOSViews *views = [[DIOSViews alloc] initWithSession:session];
[views initViews];
[views addParam:[viewNameField text] forKey:@"view_name"];
[views addParam:[NSArray arrayWithObjects:[argsField text], nil] forKey:@"args"];
[views addParam:[displayNameField text] forKey:@"display_id"];
[views runMethod];
[views release];

Node

Add

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
NSMutableDictionary *nodeData = [[NSMutableDictionary alloc] init];
[nodeData setObject:[bodySaveField text] forKey:@"body"];
[nodeData setObject:[typeSaveField text] forKey:@"type"];
[nodeData setObject:[titleSaveField text] forKey:@"title"];
[nodeData setObject:[nidSaveField text] forKey:@"nid"];
[nodeData setObject:@"now" forKey:@"date"];
[nodeData setObject:@"1" forKey:@"status"];
[nodeData setObject:[[session userInfo] objectForKey:@"name"] forKey:@"name"];
[node nodeSave:nodeData];
[node release];

Delete

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
[node nodeDelete:[nidDeleteField text]];
[node release];

Get

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
[node nodeGet:[nidGetField text]];
[node release]; 

Comment

Add

DIOSComment *comment = [[DIOSComment alloc] initWithSession:session];
[comment addComment:[nidCommentAddField text] subject:[subjectCommentAddField text] body:[bodyCommentAddField text]];
[comment release]; 

Get

DIOSComment *comment = [[DIOSComment alloc] initWithSession:session];
[comment getComment:[nidCommentGetField text]];
[comment release]; 

User

Login

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user loginWithUsername:[usernameLoginField text] andPassword:[passwordLoginField text]];
[user release];

Logout

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user logout];
[user release];

Save

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
NSMutableDictionary *userData = [[NSMutableDictionary alloc] init];
[userData setObject:[usernameSaveField text] forKey:@"name"];
[userData setObject:[passwordSaveField text] forKey:@"pass"];
[userData setObject:[emailSaveField text] forKey:@"mail"];
[userData setObject:[uidSaveField text] forKey:@"uid"];
[user userSave:userData];
[user release];

Get

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user userGet:[uidGetField text]];
[user release];

Delete

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user userDelete:[uidDeleteField text]];
[user release];

Taxonomy

- (NSMutableArray *) getTreeForVid:(NSString*)vid {
  DIOSTaxonomy *taxonomy = [[DIOSTaxonomy alloc] initWithSession:session];
  return [[taxonomy getTree:vid] objectForKey:@"#data"];
}

- (NSMutableArray *) getNodesForTid:(NSString*)tid {
  DIOSTaxonomy *taxonomy = [[DIOSTaxonomy alloc] initWithSession:session];
  
  return [[taxonomy selectNodes:tid] objectForKey:@"#data"];
}

Troubleshooting

If you are getting Access denied, or API Key not valid, double check that your key settings are setup correctly at admin/build/services/keys and double check that permissions are correct for your user and anonymous.

X service doesnt exist in Drupal iOS SDK

Thats ok, just subclass DIOSConnect and follow the model of tthe other DIOS classes. If its a core services Class and I have not added it in, please help us all out and contribute it by by doing a pull request. Thanks!

Questions

Email [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.