Skip to content

Instantly share code, notes, and snippets.

@greenisus
Created October 10, 2011 16:05
Show Gist options
  • Save greenisus/1275693 to your computer and use it in GitHub Desktop.
Save greenisus/1275693 to your computer and use it in GitHub Desktop.
- (CKRequest *)actionRequest {
// TODO: self.id needs to be a string instead of an int
CKRequest *request = [CKRequest requestWithRemotePath:$S(@"/servers/%@/action", self.id)];
NSLog(@"request url: %@", request.remoteURL);
request.method = CKRequestMethodPOST;
[request addHeaders:[NSDictionary dictionaryWithObject:[[RSAccount activeAccount] api_auth_token] forKey:@"X-Auth-Token"]];
return request;
}
- (BOOL)reboot:(RSServerRebootType)rebootType result:(CKResult **)returnResult {
CKRequest *request = [self actionRequest];
NSString *type = rebootType == RSServerRebootTypeSoft ? @"SOFT" : @"HARD";
NSDictionary *dict = $D($D(type, @"type"), @"reboot");
[request setBody:[NSJSONSerialization dataWithJSONObject:dict options:0 error:nil]];
RSNSURLConnection *connection = [[RSNSURLConnection alloc] init];
__autoreleasing CKResult *result = [connection sendSyncronously:request];
returnResult = &result;
return [result isSuccess];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment