Skip to content
MineS Chan edited this page Aug 25, 2014 · 12 revisions

#THIS IS A WORK IN PROGRESS #This is in in relation to the dev branch only

Session

    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];

Node

Add

  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
  }];

Update

      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
  }];

Delete

    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
    }];

Get

    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
    }];

Index

  [DIOSNode nodeIndexWithPage:@"0" fields:@"nid" parameters:[NSArray arrayWithObjects:@"status", nil] pageSize:@"20" success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //success
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //failure
  }];

Node Attach File

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];

Comment

Add

    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];

Update

    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];

Delete

    DIOSComment *comment = [[DIOSComment alloc] init];
    NSMutableDictionary *commentData = [NSMutableDictionary new];
    [commentData setObject:@"2" forKey:@"cid"];
    [comment commentDelete:commentData];

Get

    DIOSComment *comment = [[DIOSComment alloc] init];
    NSMutableDictionary *commentData = [NSMutableDictionary new];
    [commentData setObject:@"2" forKey:@"cid"];
    [comment commentGet:commentData];

Index

    DIOSComment *comment = [[DIOSNode alloc] initWithDelegate:self];
    [comment commentIndexWithPage:@"0" fields:nil parameters:nil pageSize:@"2"];

Delegate methods

    - (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;

User

Add

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 */ }
];

Update

  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 */ }
  ];

Delete

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 */ }
];

Get

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 */ }
]; 

Index

DIOSUser *user = [[DIOSUser alloc] initWithDelegate:self];
[user userIndexWithPage:@"0" fields:nil parameters:nil pageSize:@"2"];

Login

[DIOSUser
  userLoginWithUsername:@"username" 
  andPassword:@"password"
  success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
  failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];

Proved Login

[DIOSUser
  userMakeSureUserIsLoggedInWithUsername:@"username"
  andPassword:@"password"
  success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
  failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];

Logout

[DIOSUser
  userLogoutWithSuccessBlock:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
  failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];

Proved Logout

[DIOSUser
  userMakeSureUserIsLoggedOutWithSucess:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */ }
  failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */ }
];

Registration input validation

    NSError* nameError = nil;
    if(![DIOSUser userValidateUserName:@"demo" error:&nameError]) { /* handle error */ }

    NSError* emailError = nil;
    if(![DIOSUser userValidateUserEmail:@"[email protected]" error:&emailError]) { /* handle error */ }

Entity

Update

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 */ }
];

Delete

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 */ }
];

Get

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 */ }
];