Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

Commit

Permalink
Remove seemingly-deprecated API usage throughout app
Browse files Browse the repository at this point in the history
closes #7
  • Loading branch information
cdzombak committed Oct 27, 2013
1 parent bb764b8 commit c080c45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 72 deletions.
14 changes: 0 additions & 14 deletions buyvmmanager/BVMServerInfo.h
Expand Up @@ -26,20 +26,6 @@ typedef NS_ENUM(NSUInteger, BVMServerStatus) {
+ (void)requestInfoForServerId:(NSString *)serverId
withBlock:(void (^)(BVMServerInfo * info, NSError *error))resultBlock;

/**
* Provides an asynchronous interface to query status of a server
*
* @param serverName
* name assigned to the server by the user. Used to identify
* the server in user defaults.
*
* @param resultBlock
* block called with results of the query. No error occurred
* if `error` is nil.
*/
+ (void)requestStatusForServerId:(NSString *)serverId
withBlock:(void (^)(BVMServerStatus status, NSString *hostname, NSString *ip, NSError *error))resultBlock;

#pragma mark Server Info

/**
Expand Down
38 changes: 0 additions & 38 deletions buyvmmanager/BVMServerInfo.m
Expand Up @@ -70,44 +70,6 @@ + (void)requestInfoForServerId:(NSString *)serverId
}];
}

+ (void)requestStatusForServerId:(NSString *)serverId
withBlock:(void (^)(BVMServerStatus, NSString *hostname, NSString *ip, NSError *))resultBlock
{
NSDictionary *credentials = [BVMServersManager credentialsForServerId:serverId];
NSDictionary *params = @{
@"key": credentials[kBVMServerKeyAPIKey] != nil ? credentials[kBVMServerKeyAPIKey] : @"",
@"hash": credentials[kBVMServerKeyAPIHash] != nil ? credentials[kBVMServerKeyAPIHash] : @"",
@"action": @"status"
};

void (^ failureBlock)(NSError *) = ^(NSError *error) {
if (!error) error = [NSError bvm_indeterminateAPIError];
if (resultBlock) resultBlock(BVMServerStatusIndeterminate, nil, nil, error);
};

[[BVMAPIClient sharedClient] getPath:kBuyVMAPIPath
parameters:params
timeoutInterval:kBVMInfoTimeoutInterval
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError __autoreleasing *error = nil;
BVMAPIResponseParser *parser = [[BVMAPIResponseParser alloc] initWithAPIResponse:responseObject error:&error];
if (!parser) {
failureBlock(error); return;
}
error = [parser apiError];
if (error) {
failureBlock(error); return;
}

BVMServerStatus status = [BVMAPIResponseParser serverStatusFromApiString:[parser stringForNode:@"vmstat"]];
NSString *hostname = [parser stringForNode:@"hostname"];
NSString *ip = [parser stringForNode:@"ipaddress"];
if (resultBlock) resultBlock(status, hostname, ip, nil);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failureBlock(error);
}];
}

+ (BVMServerInfo *)infoFromParser:(BVMAPIResponseParser *)parser
{
BVMServerInfo *info = [[BVMServerInfo alloc] init];
Expand Down
40 changes: 20 additions & 20 deletions buyvmmanager/BVMServersListViewController.m
Expand Up @@ -207,26 +207,26 @@ - (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexP
cell.textLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.text = @"";

[BVMServerInfo requestStatusForServerId:serverId
withBlock:^(BVMServerStatus status, NSString *hostname, NSString *ip, NSError *error) {
if (status == BVMServerStatusOffline) {
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%@ [offline]", nil), cell.textLabel.text];
} else if (status == BVMServerStatusIndeterminate) {
cell.textLabel.textColor = [UIColor blueColor];
cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%@ [unknown]", nil), cell.textLabel.text];
}
if (ip && hostname) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (%@)", ip, hostname];
} else if (ip) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", ip];
} else if (hostname) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"(%@)", hostname];
}
[cell setNeedsLayout];

[self.refreshControl endRefreshing];
}];
[BVMServerInfo requestInfoForServerId:serverId withBlock:^(BVMServerInfo *info, NSError *error) {
BVMServerStatus status = info.status;
if (status == BVMServerStatusOffline) {
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%@ [offline]", nil), cell.textLabel.text];
} else if (status == BVMServerStatusIndeterminate) {
cell.textLabel.textColor = [UIColor blueColor];
cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%@ [unknown]", nil), cell.textLabel.text];
}
if (info.mainIpAddress && info.hostname) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ (%@)", info.mainIpAddress, info.hostname];
} else if (info.mainIpAddress) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", info.mainIpAddress];
} else if (info.hostname) {
cell.detailTextLabel.text = [NSString stringWithFormat:@"(%@)", info.hostname];
}
[cell setNeedsLayout];

[self.refreshControl endRefreshing];
}];
}

- (void)reloadData
Expand Down

0 comments on commit c080c45

Please sign in to comment.