Skip to content

Instantly share code, notes, and snippets.

@shadda
Last active October 18, 2022 07:52
Show Gist options
  • Save shadda/907268 to your computer and use it in GitHub Desktop.
Save shadda/907268 to your computer and use it in GitHub Desktop.
#import "SLServiceCaller.h"
#import "SLServiceRequest.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[[NSGarbageCollector defaultCollector] collectIfNeeded];
@try
{
NSString *URI = @"http://services/tits/Campaign.test.json?param1=value1&param2=value2";
SLServiceRequest *request = [SLServiceRequest serviceRequestWithURI: URI];
[request addParameterWithKey: @"KEY" AndValue: @"XOOM"];
SLServiceResponse *response = [SLServiceCaller call: request];
NSMutableDictionary *headers = [response get: @"headers"];
NSMutableDictionary *foo = [response get: @"data::foo"];
NSMutableArray *bar = [response get: @"data::foo::bar"];
int someId = [[response get: @"data::foo::bar[0]"] intValue];
int runTime = [[response get: @"headers::runtime"] intValue];
NSLog(@"Headers: %@\nFoo: %@\nBar: %@\nsomeId: %d\nRun Time: %d", headers, foo, bar, someId, runTime);
}
@catch (NSException *e)
{
NSLog(@"Error: %@\nMessage: %@\nInfo: %@",
[e name],
[e reason],
[e userInfo]
);
}
@finally
{
[pool drain];
return 0;
}
}
/*
RAW RESPONSE:
{"headers":{"time":1302163160.4783,"params":{"param2":"value2","do":"test","svc":"Campaign","param1":"value1","KEY":"XOOM","_limit":null,"_offset":null,"_order_by":null,"_direction":null},"runtime":"1.7138619423"},"data":{"foo":{"bar":[1,2,3,4,5]}}}
OUTPUT:
2011-04-07 02:59:23.081 CDTest[90748:903] Headers: {
params = {
KEY = XOOM;
"_direction" = "<null>";
"_limit" = "<null>";
"_offset" = "<null>";
"_order_by" = "<null>";
do = test;
param1 = value1;
param2 = value2;
svc = Campaign;
};
runtime = "1.7138619423";
time = "1302163160.4783";
}
Foo: {
bar = (
1,
2,
3,
4,
5
);
}
Bar: (
1,
2,
3,
4,
5
)
someId: 1
Run Time: 1
Program ended with exit code: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment