forked from kylebrowning/waterwheel.swift
-
Notifications
You must be signed in to change notification settings - Fork 0
drupal ios sdk 2.0
MineS Chan edited this page Aug 25, 2014
·
12 revisions
DIOSSession *session = [DIOSSession sharedSession];
//If you have logged in, this object is not nil
[session user];
//This can also be referenced as
[[DIOSSession sharedSession] user];
NSMutableDictionary *nodeData = [NSMutableDictionary new];
[nodeData setValue:@"testtitle" forKey:@"title"];
NSDictionary *bodyValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"a test body", nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *languageDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:bodyValues] forKey:@"und"];
[nodeData setObject:languageDict forKey:@"body"];
[nodeData setObject:@"article" forKey:@"type"];
[nodeData setObject:@"und" forKey:@"language"];
[DIOSNode nodeSave:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
//Successful node Creation
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//WE failed to upload the node
}];
NSMutableDictionary *nodeData = [NSMutableDictionary new];
[nodeData setObject:@"testtitle" forKey:@"title"];
NSDictionary *bodyValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"a test body", nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *languageDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:bodyValues] forKey:@"und"];
[nodeData setObject:languageDict forKey:@"body"];
[nodeData setObject:@"article" forKey:@"type"];
[nodeData setObject:@"und" forKey:@"language"];
[nodeData setObject:@"99" forKey:@"nid"];//specific id here
[DIOSNode nodeUpdate:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
//Successful node update
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//WE failed to update the node
}];
NSMutableDictionary *nodeData = [NSMutableDictionary new];
[nodeData setObject:@"12" forKey:@"nid"];
[DIOSNode nodeDelete:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
//Successful node delete
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//WE failed to delete the node
}];
NSMutableDictionary *nodeData = [NSMutableDictionary new];
[nodeData setObject:@"12" forKey:@"nid"];
[DIOSNode nodeGet:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
//Successful node get
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//WE failed to get the node
}];
[DIOSNode nodeIndexWithPage:@"0" fields:@"nid" parameters:[NSArray arrayWithObjects:@"status", nil] pageSize:@"20" success:^(AFHTTPRequestOperation *operation, id responseObject) {
//success
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//failure
}];
First, this wont work until this patch is commited
NSMutableDictionary *fileData = [NSMutableDictionary new];
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"bg.png"], 0.5);
[fileData setObject:@"temp" forKey:@"name"];
[fileData setObject:@"temp.jpg" forKey:@"fileName"];
[fileData setObject:imageData forKey:@"fileData"];
[fileData setObject:@"image/png" forKey:@"mimetype"];
[fileData setObject:@"field_image" forKey:@"field_name"];
[fileData setObject:@"4" forKey:@"nid"];
[node nodeAttachFile:fileData];
DIOSComment *comment = [[DIOSComment alloc] init];
NSMutableDictionary *commentData = [NSMutableDictionary new];
NSDictionary *bodyValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"commentbody", nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *languageDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:bodyValues] forKey:@"und"];
[commentData setObject:languageDict forKey:@"comment_body"];
[commentData setObject:@"subject yeahhhh" forKey:@"subject"];
[commentData setObject:@"und" forKey:@"language"];
[commentData setObject:@"2" forKey:@"cid"];
[comment commentSave:commentData];
DIOSComment *comment = [[DIOSComment alloc] init];
NSMutableDictionary *commentData = [NSMutableDictionary new];
NSDictionary *bodyValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@" a changed commentbody", nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *languageDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:bodyValues] forKey:@"und"];
[commentData setObject:languageDict forKey:@"comment_body"];
[commentData setObject:@"subjecte is changed" forKey:@"subject"];
[commentData setObject:@"und" forKey:@"language"];
[commentData setObject:@"2" forKey:@"cid"];
[comment commentUpdate:commentData];
DIOSComment *comment = [[DIOSComment alloc] init];
NSMutableDictionary *commentData = [NSMutableDictionary new];
[commentData setObject:@"2" forKey:@"cid"];
[comment commentDelete:commentData];
DIOSComment *comment = [[DIOSComment alloc] init];
NSMutableDictionary *commentData = [NSMutableDictionary new];
[commentData setObject:@"2" forKey:@"cid"];
[comment commentGet:commentData];
DIOSComment *comment = [[DIOSNode alloc] initWithDelegate:self];
[comment commentIndexWithPage:@"0" fields:nil parameters:nil pageSize:@"2"];
- (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;
NSMutableDictionary *userData = [NSMutableDictionary new];
[userData setObject:@"test" forKey:@"name"];
[userData setObject:@"[email protected]" forKey:@"mail"];
[userData setObject:@"test" forKey:@"pass"];
[DIOSUser
userRegister:userData
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
NSMutableDictionary *userData = [NSMutableDictionary new];
[userData setObject:@"test" forKey:@"name"];
[userData setObject:@"[email protected]" forKey:@"mail"];
[userData setObject:@"test" forKey:@"current_pass"];
[userData setObject:@"new_password" forKey:@"pass"];
[userData setObject:@"56" forKey:@"uid"];
[DIOSUser
userUpdate:userData
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
NSMutableDictionary *userData = [NSMutableDictionary new];
[userData setObject:@"56" forKey:@"uid"];
[DIOSUser
userDelete:userData
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
NSMutableDictionary *userData = [NSMutableDictionary new];
[userData setObject:@"56" forKey:@"uid"];
[DIOSUser
userGet:userIdDict
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
DIOSUser *user = [[DIOSUser alloc] initWithDelegate:self];
[user userIndexWithPage:@"0" fields:nil parameters:nil pageSize:@"2"];
[DIOSUser
userLoginWithUsername:@"username"
andPassword:@"password"
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
[DIOSUser
userMakeSureUserIsLoggedInWithUsername:@"username"
andPassword:@"password"
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
[DIOSUser
userLogoutWithSuccessBlock:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
[DIOSUser
userMakeSureUserIsLoggedOutWithSucess:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
NSError* nameError = nil;
if(![DIOSUser userValidateUserName:@"demo" error:&nameError]) { /* handle error */ }
NSError* emailError = nil;
if(![DIOSUser userValidateUserEmail:@"[email protected]" error:&emailError]) { /* handle error */ }
NSDictionary* entityData = [NSMutableDictionary new];
[entityData setObject:@"56" forKey:@"uid"];
[entityData setObject:@"12" forKey:@"entityParam"];
[DIOSEntity
entityUpdate:entityData
name:@"testEntity"
eid:@"uid"
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
NSDictionary* entityData = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"56"] forKey:@"uid"];
[DIOSEntity
entityDelete:entityData
name:@"testEntity"
eid:@"uid"
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];
NSDictionary* entityData = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"56"] forKey:@"uid"];
[DIOSEntity
entityGet:entityData
name:@"testEntity"
eid:@"uid"
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];