Quickblox: analog of "push" method in the RESTful API - quickblox

In the Quickblox RESTful API there's a special update operator "push" that appends specified values to array.
Is there any analog in the Quickblox iOS SDK that doesn't require to send the whole array to the server to update one value?

Hope this help
QBCOCustomObject *object = [QBCOCustomObject customObject];
object.className = #"SuperSample";
object.ID = #"51d5a979efa357c7fa000006";
NSMutableDictionary *specialUpdateParams = [NSMutableDictionary dictionary];
[specialUpdateParams setObject:#"phone" forKey:#"push[interests]"];
[QBCustomObjects updateObject:object specialUpdateOperators:specialUpdateParams delegate:self];
Feel free to try Snippets https://github.com/QuickBlox/quickblox-ios-sdk/tree/master/snippets
This project contains lots of examples

Related

afnetworking request parameter sequence

I am trying to produce a request using afnetworking in objective c, however, it seems like the hardware that I am trying to connect to only applies requests when the parameters of the request are in a specific order. So I am wondering if there is a way to make the request so that the parameters are in a specific order. (As just doing it normally seems to jumble the sequence of the params up)
Here's my code:
NSDictionary *params = #{
#"param1" : #"bla",
#"param2" : #"bla2",
#"param3" : #"bla3"
};
[requestManager GET:#"somewhere" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
DLog(#"Success!");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
DLog(#"Fail: %#", error);
}];
It actually goes to success every time, its just that the request I had applied would be practically ignored.
The actual request body becomes something like "param3=bla3&param1=bla1&param2=bla2 etc which would be ignored as it seems.
You can't do that using the request manager in the way you currently are.
Instead, you would need to create the parameter list yourself, and then create a request from that. Then you could use AFN to handle the request transmission and response.
Note that the server shouldn't require a specific order and that this should be changed if possible. Note also that the dictionary of parameters has no order (even though you add the keys in a set order).
Keeping the order of the parameters have a great impact on server performance. This sounds silly at first, but just think about GET requests which contain the query string as part of the URL. Web servers can cache the response for the given URL. If you mess with the order of the parameters, the cache won't be as effective as it could be.
The case is even worse if you call an API from different platforms (iOS, Android, Web) and they all reorder the params, which means that the same content will be found on 3 different cache keys.
Keeping the order is a performance issue at the first place.

RestKit: confused as to how to setup a POST

I have managed to GET objects and to POST a new object to the server, but the POST generates an error on the iPhone.
Here is my setup:
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMappingFoo pathPattern:#"/foos" keyPath:#"foos" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; // Works well for GET
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[entityMappingFoo inverseMapping] objectClass:[Foo class] rootKeyPath:#"foo"]; // Client --> Server works
The problem is (I think) that:
when I GET, the back-end expects the JSON to have a plural key: {"foos":[...]} (which makes sense since there might be several objects)
when I POST one object, RestKit expects the answer from the back-end to be singular: {"foo":...}. Yet, since it uses the same responseDescriptor as for GET, it gets a plural and it is lost.
If I replace keyPath:#"foos" by keyPath:#"foo" in responseDescriptor my POST works... but not my GET.
How do I reconcile the two?
You're right. Basically you just need to create multiple response descriptors to cover the different cases. You can use the same mapping in each, but RestKit needs to know what to look for when processing a response and your 2 cases are different.

Get JSON from Snapchat/Snaphax API in objective C

I"m trying to post data to a server from objective C and I am trying to get a JSON returned in it.
I am looking at the Snaphax API for PHP and Snaphaxpy API and trying to rewrite it from PHP into Objective C.
The links for the code are:
https://github.com/tlack/snaphax
https://github.com/jasonanovak/snaphaxpy/blob/master/snaphaxpy.py
I'm also especially looking at: http://adamcaudill.com/2012/06/16/snapchat-api-and-security/
but apparently this is outdated
My code is:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"https://feelinsonice.appspot.com/ph/login"]];
[request setHTTPMethod:#"POST"];
[request addValue:#"******testusername******" forHTTPHeaderField:#"username"];
[request addValue:#"*********" forHTTPHeaderField:#"password"];
[request addValue:#"M02cnQ51Ji97vwT4" forHTTPHeaderField:#"blob_enc_key"];
[request addValue:#"false" forHTTPHeaderField:#"debug"];
[request addValue:#"iEk21fuwZApXlz93750dmW22pw389dPwOk" forHTTPHeaderField:#"secret"];
[request addValue:#"m198sOkJEn37DjqZ32lpRu76xmw288xSQ9" forHTTPHeaderField:#"static_token"];
[request addValue:#"Snaphax 4.0.1 (iPad; iPhone OS 6.0; en_US)" forHTTPHeaderField:#"user_agent"];
[request addValue:#"930cf95a6731dc986ef3bceef6abbaf420e94d8d197dca87b9b47314d8c51b3b" forHTTPHeaderField:#"req_token"];
[request addValue:#"1355776346532" forHTTPHeaderField:#"timestamp"];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(#"%#", dataString);
I haven't included a real username/password. How come, however, does this not work as I have literally copied everything I have found and implemented in a new language...
Am I not POSTing the data correctly? I tried using ASIHTTPRequest but I couldn't get that working either...
Any suggestions or ideas based on experience??
Check my answer here: how can I use NSURLConnection Asynchronously?
You can send a POST request by using
HTTPCachedController *ctrl = [[[HTTPCachedController alloc] initWithRequestType:1 andDelegate:self] autorelease];
[ctrl postRequestToURL:#"https://feelinsonice.appspot.com/ph/login" withData:#"username=user1&password=pass& ... "];
Source code of the HTTPCachedController can be found here: HTTPCachedController
If you are looking for updated endpoints and whatnot, I wrote a quick Python script that you should be able to read through for some endpoints and the parameters they require. Some of the endpoints are as follow:
Base URL https://feelinsonice-hrd.appspot.com/
Login https://feelinsonice.appspot.com/ph/login
Get Snap by ID https://feelinsonice.appspot.com/ph/blob?id={}
Shameless Plug: I'm hosting a wrapper for the Snapchat API right now so you don't have to implement encryption into your project and you can safe time and your project can be more efficient. Check it out here!
You will also notice a lot of strange abbreviations in the JSON (like Adam said, Snapchat's API wasn't really built for human consumption), so I've gone ahead and mapped that out for you:
ID: id
Snap ID: c_id
Media Type: m = 0 (pic), 1 (video)
Sent Timestamp: sts
Opened Timestamp: ts
Sender: sn
Recipient: rp
Status: st = 1 (sent to you), 2 (sent by you)
Time: t
Screenshot Count: c
Note: I will be updating that repo with some new code within the next month or so. Also, the most up-to-date endpoints often vary between /ph/ and /bq/ for different requests for some reason, so don't accidentally use one when you meant to use the other.

How to use JSON object as variable in objective c?

I'm developing an Server-Client application in Xcode 4.2
The application saves some user informations and sends them in a HTTP GET request to server via server url.
As response, I have text like this:
2011-12-30 15:44:02.120 smartHome[340:f803] {
button = 1;
key = 181abc88e57c37a42769;
message = (
{
ID = 1;
date = "2011-12-10 16:00:00";
message = asdf;
status = 1;
"user_id" = 2;
}
);
"wrong_user" = 0;
}
(2/Jan/2012)
Sorry for such confusing edits but i haven't overcome my deal yet. I need to parse this JSON text(i think it is called text:) and do some implemetations on the results.. I have to use, for example, the message object and its status value, if status equals to 1 i will trigger a Notification in my App. As like that, if the button comes me as a value with 1 i will send a POST to the server and request for the button id and title attributes..
There are a lot of tutorials about parsing but all i saw are about Twitter or flickr APIs, unfortunately i couldnt desing a clear way to solve my problem.. I tried ASIHTTPRequest but i faced some problems with setting up the Libraries. And if i'm not wrong, ASIHTTPRequest is not such a good idea in i-OS 5 (i m not sure about this).. Anyway, from this point can anyone please help me about how to parse the JSON above?
Finaly i figured out, i have done everything before, i just realized that..
for example when i tried:
NSString*key1=[ result objectForKey:#"key" ];
NSString *kAndVal=[result objectForKey:#"button"];
NSLog(#"\n%# : %#", key1, kAndVal);
i got the key and button values above.. I hope this answer will save lots of newbies like me out of trouble..
You should parse your JSON anwer using a JSON parser. iOS 5 has its own JSON parser. In case you want to support iOS 4 check out JSONKIT https://github.com/johnezang/JSONKit

How to add new row to a sharepoint list in objective c?

I tried using updatelistitems web service of the sharepoint. but could not find how to give the input data in the xml format along with the soap request.
Thanks in advance
Since it's an integration you are doing I'd recommend using an ADO.NET adapter for SharePoint and connect through a WCF service (soap/wsdl). It will save you a lot of time and if done correctly your integration wont be proprietary.
Check this ready-made wcf service, http://www.bendsoft.com/downloads/camelot-wcf-service/, installation instructions here http://blog.bendsoft.com/category/integrations/wcf-services/.
It's open source but ships with support for the Camelot XML format, which bundles the schema along with the content if you query for data, check the example schema here http://www.bendsoft.com/downloads/sharepoint-web-parts/xml-pusher/.
To insert data into SharePoint with the WCF service you can simply do something like this
$SharePointNonQuery = new SharePointNonQuery(array(
'sql' => "INSERT INTO contactform (title,email,company,message) VALUES ('John Doe','john.doe#example.com','Johns Company','A test message!')",
'method' => 'ExecuteNonQuery',
'connString' => 'sharepoint_connection',
'sharedKey' => constant("WSDL_SHARED_KEY")
));
The example is obviously made in PHP ( http://blog.bendsoft.com/2011/04/camelot-php-tools-1-1-for-sharepoint-released/ ) but it's equally easy to create a class in Objective-C and send your command as SQL via SOAP and execute the SQL command in the WCF service.
Hope this helps!
----------- Edits below this line -----------
Querying the suggested WCF service from Objective-C would result in something like this
WSMethodInvocationRef soapReq = createSOAPRequest(url, method, namespace, params, paramOrder, reqHeaders);
The Url is the location of the wcf service, ie. http://yourserver.com/wcf/camelot.wcf
The method is the method IN the wcf service you want to use. The Camelot WCF service have a few default methods. Suitable in this scenario would be the ExecuteNonQuery method which takes the following arguments; sql, connString and sharedKey.
bool ExecuteNonQuery(string sql, string connString, string sharedKey);
The params is the arguments listed above, they should be sent as an associative array (NSDictionary I assume).
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
#"INSERT INTO YourList (title,email,company,message) VALUES ('John Doe','john.doe#example.com','Johns Company','A test message!')", #"sql",
#"connString", #"SharePointConnectionString",
#"sharedKey", #"YourPreferredKey",
nil];
The ExecuteNonQuery is a bool method it will return true or false to the soapReq method in the Objective-C application.