Revision ef74c42f Classes/OpenStackRequest.m

b/Classes/OpenStackRequest.m
20 20

  
21 21
@implementation OpenStackRequest
22 22

  
23
@synthesize account, callback, errorAlerter;
23
@synthesize account, callback, errorAlerter, retryWithUpdatedURL, followUpSelectorString, notificationURL;
24 24

  
25 25
#pragma mark - Constructors
26 26
#pragma mark Generic
......
33 33
    request.timeOutSeconds = 60;
34 34
    request.numberOfTimesToRetryOnTimeout = 5;
35 35
    request.validatesSecureCertificate = !account.ignoreSSLErrors;
36
    request.retryWithUpdatedURL = (account.provider.manual ? NO : YES);
36 37
	return request;
37 38
}
38 39

  
......
56 57
    return [self request:account method:method url:url];
57 58
}
58 59

  
60
#pragma mark NSCopying
61

  
62
- (id)copyWithZone:(NSZone *)zone {
63
    OpenStackRequest *newRequest = [super copyWithZone:zone];
64
    newRequest.account = self.account;
65
    newRequest.callback = self.callback;
66
    newRequest.errorAlerter = self.errorAlerter;
67
    newRequest.retryWithUpdatedURL = self.retryWithUpdatedURL;
68
    newRequest.followUpSelectorString = self.followUpSelectorString;
69
    newRequest.notificationURL = self.notificationURL;
70
    return newRequest;
71
}
72

  
59 73
#pragma mark Service Catalog
60 74
+ (id)serviceCatalogRequest:(OpenStackAccount *)account {
61 75
    OpenStackRequest *request = [self requestWithoutToken:account method:@"POST" url:account.provider.tokensURL];
......
131 145
    request.timeOutSeconds = 60;
132 146
    request.numberOfTimesToRetryOnTimeout = 5;
133 147
    request.validatesSecureCertificate = !account.ignoreSSLErrors;
148
    request.retryWithUpdatedURL = (account.provider.manual ? NO : YES);
134 149
	return request;
135 150
}
136 151

  
152
+ (id)getSharingAccountsRequest:(OpenStackAccount *)account
153
                         marker:(NSString *)marker sharingAccountsBuffer:(NSMutableDictionary *)sharingAccountsBuffer {
154
    OpenStackRequest *request = [self request:account method:@"GET"
155
                                          url:[NSURL URLWithString:[NSString stringWithFormat:@"%@?format=json",
156
                                                                    account.provider.authEndpointURL]]];
157
    if (marker)
158
        request.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@&marker=%@", request.url.description, [NSString encodeToPercentEscape:marker]]];
159
    if (!sharingAccountsBuffer)
160
        sharingAccountsBuffer = [NSMutableDictionary dictionary];
161
    request.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
162
                        sharingAccountsBuffer, @"sharingAccountsBuffer",
163
                        nil];
164
    return request;
165
}
166

  
137 167
+ (id)getSharingAccountsRequest:(OpenStackAccount *)account {
138
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?format=json", account.provider.authEndpointURL]];
139
    return [self request:account method:@"GET" url:url];
168
    return [self getSharingAccountsRequest:account marker:nil sharingAccountsBuffer:nil];
140 169
}
141 170

  
142
- (NSArray *)sharingAccounts {
143
    SBJSON *parser = [[[SBJSON alloc] init] autorelease];
144
    NSArray *sharingAccounts = [parser objectWithString:[self responseString]];
145
    return sharingAccounts;
171
- (NSArray *)jsonSharingAccounts {
172
    return [[[[SBJSON alloc] init] autorelease] objectWithString:[self responseString]];
146 173
}
147 174

  
148 175
#pragma mark Account
......
151 178
    return [self filesRequest:account method:@"HEAD" path:@""];
152 179
}
153 180

  
181
+ (id)getContainersRequest:(OpenStackAccount *)account
182
                    marker:(NSString *)marker containersBuffer:(NSMutableDictionary *)containersBuffer {
183
    OpenStackRequest *request = [self filesRequest:account method:@"GET" path:@""];
184
    if (marker)
185
        request.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@&marker=%@", request.url.description, [NSString encodeToPercentEscape:marker]]];
186
    if (!containersBuffer)
187
        containersBuffer = [NSMutableDictionary dictionary];
188
    request.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
189
                        containersBuffer, @"containersBuffer",
190
                        nil];
191
    return request;
192
}
193

  
154 194
+ (id)getContainersRequest:(OpenStackAccount *)account {
155
    return [self filesRequest:account method:@"GET" path:@""];
195
    return [self getContainersRequest:account marker:nil containersBuffer:nil];
156 196
}
157 197

  
158
- (NSMutableDictionary *)containers {
159
    SBJSON *parser = [[[SBJSON alloc] init] autorelease];
160
    NSArray *jsonObjects = [parser objectWithString:[self responseString]];
161
    NSMutableDictionary *containers = [NSMutableDictionary dictionaryWithCapacity:[jsonObjects count]];
162
    for (NSDictionary *dict in jsonObjects) {
163
        Container *container = [Container fromJSON:dict];
164
        [containers setObject:container forKey:container.name];
165
    }
166
    return containers;
198
- (NSArray *)jsonContainers {
199
    return [[[[SBJSON alloc] init] autorelease] objectWithString:[self responseString]];
167 200
}
168 201

  
169 202
+ (id)writeAccountMetadataRequest:(OpenStackAccount *)account withAccountInfo:(NSDictionary *)accountInfo {
......
202 235
    return [self filesRequest:account method:@"DELETE" path:[NSString stringWithFormat:@"/%@", [NSString encodeToPercentEscape:container.name]]];
203 236
}
204 237

  
238
+ (id)getObjectsRequest:(OpenStackAccount *)account container:(Container *)container
239
                 marker:(NSString *)marker objectsBuffer:(NSMutableDictionary *)objectsBuffer {
240
    OpenStackRequest *request = [self filesRequest:account method:@"GET" path:[NSString stringWithFormat:@"/%@", [NSString encodeToPercentEscape:container.name]]];
241
    if (marker)
242
        request.url = [NSURL URLWithString:[NSString stringWithFormat:@"%@&marker=%@", request.url.description, [NSString encodeToPercentEscape:marker]]];
243
    if (!objectsBuffer)
244
        objectsBuffer = [NSMutableDictionary dictionary];
245
    request.userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
246
                        container, @"container",
247
                        objectsBuffer, @"objectsBuffer",
248
                        nil];
249
    return request;
250
}
251

  
205 252
+ (id)getObjectsRequest:(OpenStackAccount *)account container:(Container *)container {
206
    return [self filesRequest:account method:@"GET" path:[NSString stringWithFormat:@"/%@", [NSString encodeToPercentEscape:container.name]]];
253
    return [self getObjectsRequest:account container:container marker:nil objectsBuffer:nil];
207 254
}
208 255

  
209
- (NSMutableDictionary *)objects {
210
    SBJSON *parser = [[[SBJSON alloc] init] autorelease];
211
    NSArray *jsonObjects = [parser objectWithString:[self responseString]];
212
    NSMutableDictionary *objects = [NSMutableDictionary dictionaryWithCapacity:[jsonObjects count]];
213
    for (NSDictionary *dict in jsonObjects) {
214
        StorageObject *object = [StorageObject fromJSON:dict];
215
        [objects setObject:object forKey:object.name];
216
    }
217
    return objects;
256
- (NSArray *)jsonObjects {
257
    return [[[[SBJSON alloc] init] autorelease] objectWithString:[self responseString]];
218 258
}
219 259

  
220 260
+ (id)writeContainerPolicyRequest:(OpenStackAccount *)account container:(Container *)container {
......
378 418
}
379 419

  
380 420
- (void)notify {
381
    NSString *observeName = [NSString stringWithFormat:@"%@ %@ %@", [self isSuccess] ? @"SUCCESS" : @"FAILURE", self.requestMethod, [self.url description]];
382
    NSString *callbackName = [NSString stringWithFormat:@"%@ %@ %@ %@", [self isSuccess] ? @"SUCCESS" : @"FAILURE", self.requestMethod, [self.url description], self.callback.uuid];
421
    NSString *observeName = [NSString stringWithFormat:@"%@ %@ %@", [self isSuccess] ? @"SUCCESS" : @"FAILURE", self.requestMethod, (self.notificationURL ? self.notificationURL.description : self.url.description)];
422
    NSString *callbackName = [NSString stringWithFormat:@"%@ %@ %@ %@", [self isSuccess] ? @"SUCCESS" : @"FAILURE", self.requestMethod, (self.notificationURL ? self.notificationURL.description : self.url.description), self.callback.uuid];
383 423

  
384 424
    NSDictionary *callbackUserInfo = [NSDictionary dictionaryWithObject:self forKey:@"response"];
385 425

  
......
416 456
- (void)dealloc {
417 457
    [account release];
418 458
    [errorAlerter release];
459
    [followUpSelectorString release];
460
    [notificationURL release];
419 461
    [self releaseBackupBlocksOnMainThread];
420 462
    [super dealloc];
421 463
}

Also available in: Unified diff