1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#if !defined(__has_feature) || !__has_feature(objc_arc) 6#error "This file requires ARC support." 7#endif 8 9#import "remoting/ios/host.h" 10 11@implementation Host 12 13@synthesize createdTime = _createdTime; 14@synthesize hostId = _hostId; 15@synthesize hostName = _hostName; 16@synthesize hostVersion = _hostVersion; 17@synthesize jabberId = _jabberId; 18@synthesize kind = _kind; 19@synthesize publicKey = _publicKey; 20@synthesize status = _status; 21@synthesize updatedTime = _updatedTime; 22 23// Parse jsonData into Host list 24+ (NSMutableArray*)parseListFromJSON:(NSMutableData*)data { 25 NSError* error; 26 27 NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data 28 options:kNilOptions 29 error:&error]; 30 31 NSDictionary* dataDict = [json objectForKey:@"data"]; 32 33 NSArray* availableServers = [dataDict objectForKey:@"items"]; 34 35 NSMutableArray* serverList = [[NSMutableArray alloc] init]; 36 37 NSUInteger idx = 0; 38 NSDictionary* svr; 39 NSUInteger count = [availableServers count]; 40 41 while (idx < count) { 42 svr = [availableServers objectAtIndex:idx++]; 43 Host* host = [[Host alloc] init]; 44 host.createdTime = [svr objectForKey:@"createdTime"]; 45 host.hostId = [svr objectForKey:@"hostId"]; 46 host.hostName = [svr objectForKey:@"hostName"]; 47 host.hostVersion = [svr objectForKey:@"hostVersion"]; 48 host.jabberId = [svr objectForKey:@"jabberId"]; 49 host.kind = [svr objectForKey:@"kind"]; 50 host.publicKey = [svr objectForKey:@"publicKey"]; 51 host.status = [svr objectForKey:@"status"]; 52 host.updatedTime = [svr objectForKey:@"updatedTime"]; 53 [serverList addObject:host]; 54 } 55 56 return serverList; 57} 58 59@end 60