5 // Created by Mike Mayo on 03/23/11.
6 // The OpenStack project is provided under the Apache 2.0 license.
9 #import "APICallback.h"
10 #import "NSObject+Conveniences.h"
12 @implementation APICallback
14 @synthesize uuid, url, verb, account, request;
16 - (id)initWithAccount:(OpenStackAccount *)anAccount url:(NSURL *)targetURL {
17 if ((self = [super init])) {
18 self.uuid = [APICallback stringWithUUID];
21 self.account = anAccount;
26 - (id)initWithAccount:(OpenStackAccount *)anAccount url:(NSURL *)targetURL verb:(NSString *)requestVerb {
27 if ((self = [super init])) {
28 self.uuid = [APICallback stringWithUUID];
30 self.verb = requestVerb;
31 self.account = anAccount;
36 - (id)initWithAccount:(OpenStackAccount *)anAccount request:(OpenStackRequest *)openStackRequest {
37 if ((self = [super init])) {
38 self.uuid = [APICallback stringWithUUID];
39 self.url = openStackRequest.url;
40 self.verb = openStackRequest.requestMethod;
41 self.account = anAccount;
42 self.request = openStackRequest;
47 - (void)success:(APIResponseBlock)successBlock failure:(APIResponseBlock)failureBlock {
49 NSString *successName = [NSString stringWithFormat:@"SUCCESS %@ %@%@", self.verb, [self.url description], (self.request ? [NSString stringWithFormat:@" %@", self.uuid] : @"")];
50 successObserver = [[NSNotificationCenter defaultCenter] addObserverForName:successName object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification)
52 successBlock([notification.userInfo objectForKey:@"response"]);
54 [[NSNotificationCenter defaultCenter] removeObserver:successObserver];
55 [[NSNotificationCenter defaultCenter] removeObserver:failureObserver];
59 NSString *failureName = [NSString stringWithFormat:@"FAILURE %@ %@%@", self.verb, [self.url description], (self.request ? [NSString stringWithFormat:@" %@", self.uuid] : @"")];
60 failureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:failureName object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification)
62 failureBlock([notification.userInfo objectForKey:@"response"]);
64 [[NSNotificationCenter defaultCenter] removeObserver:successObserver];
65 [[NSNotificationCenter defaultCenter] removeObserver:failureObserver];