Using SPiD API requests
Once the app can successfully logged on to SPiD we can start making requests. For example the following code gets the logged in user object.
// Try to fetch the "current user" object
[[SPiDClient sharedInstance] getUserRequestWithCurrentUserAndCompletionHandler:^(SPiDResponse *response) {
if ([response error]) {
// something went wrong and we need to check what error we received
} else {
NSLog(@"The raw response", [response rawJSON]);
}
}];The request returns a SPiDResponse object. Before trying to use the message or rawJSON property the client should check for errors using the error property.
There are some wrapper methods as the one above but the you can also write the requests yourself. For example the following code sends a GET request to /test?user_id=123. Since the SDK takes care of versions the actual path will be ´/api/2/test?user_id=123´
NSString *path = [NSString stringWithFormat:@"/user/%@", @"123"];
[SPiDRequest apiGetRequestWithPath:path andCompletionHandler:completionHandler];And a example to POST ´user_id=123´ to the endpoint ´/test´.
NSString *path = [NSString stringWithFormat:@"/test"];
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data setObject:@"123" forKey:@"user_id"];
[SPiDRequest apiPostRequestWithPath:path andBody:data andCompletionHandler:completionHandler];For more information see the API reference.