|
Shotgun ObjC Api 0.1b
Objective C API to talk to a Shotgun Instance
|
This is an objective c port of the python shotgun api.
For complete documentation of how the Python Shotgun API works along with tutorials, examples, and other details see:
https://github.com/shotgunsoftware/python-api/wiki
Note, it is also possible to compile this as a library and link that into your project as a sub-project. This is cleaner, but more difficult to setup. See the example project under Examples to see what this setup would look like.
NSString *url = @"http://mysite.shotgunsoftware.com"; NSString *script = @"example_script"; NSString *key = @"abcdefghijklmnopqrstuvwxyz"; Shotgun *shotgun = [[[Shotgun alloc] initWithUrl:url scriptName:script andKey:key] autorelease];
ShotgunRequest *request = [shotgun findEntitiesOfType:@"Version" withFilters:@"[[\"code\", \"starts_with\", \"100\"]]" andFields:@"[\"code\", \"image\"]"]; [request startSynchronous]; NSArray *results = [request response];
ShotgunEntity *shot = [[shotgun createEntityOfType:@"Shot" withData:@"{\"code\": \"s10\", \"description\": \"Shot 10\"}"] startSynchronous];
ShotgunRequest *request = [shotgun updateEntityOfType:@"Shot" withId:[NSNumber numberWithInt:23] withData:@"{\"description\": \"Shot 20 - More Info\"}"]; ShotgunEntity *shot = [request startSynchronous];
ShotgunRequest *request = [shotgun deleteEntityOfType:@"Shot" withId:[NSNumber numberWithInt:23]]; [request startSynchronous]; BOOL success = [[request response] boolValue];
ShotgunRequest *request = [shotgun reviveEntityOfType:@"Shot" withId:[NSNumber numberWithInt:23]]; [request startSynchronous]; BOOL success = [[request response] boolValue];
ShotgunRequest *request = [shotgun batch:@"[" \ "{ " \ " \"request_type\": \"create\", " \ " \"entity_type\": \"Shot\", " \ " \"data\": { " \ " \"code\": \"s10\", " \ " \"description\": \"Shot 10\" " \ " } " \ "}, " \ "{\"request_type\": \"delete\", \"entity_type\": \"Shot\", \"entity_id\": 23}" \ ]"]; [request startSynchronous]; NSArray *results = [request response];
ShotgunRequest *request = [shotgun schemaEntityRead]; [request startSynchronous]; NSDictionary *schemaInfo = [request response];
ShotgunRequest *request = [shotgun schemaRead]; [request startSynchronous]; NSDictionary *schema = [request response];
ShotgunRequest *request = [shotgun schemaFieldReadForEntityOfType:@"Shot" forField:@"sg_status_list"]; [request startSynchronous]; NSDictionary *entitySchema = [request response];
NSNumber *attachmentId = [shotgun uploadThumbnailForEntityOfType:@"Shot" withId:[NSNumber numberWithInt:23] fromPath:@"/path/to/the/file.jpg"];
NSData *imageData = downloadAttachmentWithId:[NSNumber numberWithInt:201];
ShotgunEntity *entity = [[shotgun findEntityOfType:@"Version" withFilters:filters andFields:fields] startSynchronous]; [shotgun thumbnailForEntity:entity withBlock:^(UIImage *thumbnail) { NSString *aURL = [shot objectForKey:@"image"]; NSLog(@"URL: %@ is %dx%d", aURL, thumbnail.size.width, thumbnail.size.height); }];
ShotgunRequests can be run either synchronously or asynchronously.
To run a request syncronously simply call startSyncronously:
[request startSyncronous];
The request will block the current thread until it is finished and its response is ready.
To run a request asynchronously call startAsynchronous:
[request startAsynchronous];
Control will return to the current thread right away. To process the response to the request, register callback blocks with request before starting it:
[request setCompletionBlock:^{
id response = [request response];
// Do Stuff with the response
}];
The currently supported callbacks are:
The postProcessBlock is used internally to the API and should not be overridden.
Any dictionary returned by a create, update, or find call is a ShotgunEntity object which adds some shotgun specific logic on top of an NSMutableDictionary.
ShotgunEntity *entity = [request response]; NSLog(@"My entity type is %@ , my entity id is %@", entity.entityType, entity.entityId);
All dates handled by the API are UTC dates (the default timezone for NSDate objects).
date_time fields in shotgun are returned as ShotgunDateTime objects. date fields in shotgun are returned as strings ("YYYY-MM-DD") like in the Python API.
When passing dates into the API, NSDate objects are not allowed, you must use ShotgunDate or ShotgunDateTime objects.
Rob Blau <rblau@laika.com>
1.7.4