summaryrefslogtreecommitdiffstats
path: root/remoting/ios/host.mm
blob: 592be879146f97d932b2cdf5116225f63ccfb90f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif

#import "remoting/ios/host.h"

@implementation Host

@synthesize createdTime = _createdTime;
@synthesize hostId = _hostId;
@synthesize hostName = _hostName;
@synthesize hostVersion = _hostVersion;
@synthesize jabberId = _jabberId;
@synthesize kind = _kind;
@synthesize publicKey = _publicKey;
@synthesize status = _status;
@synthesize updatedTime = _updatedTime;

// Parse jsonData into Host list
+ (NSMutableArray*)parseListFromJSON:(NSMutableData*)data {
  NSError* error;

  NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
                                                       options:kNilOptions
                                                         error:&error];

  NSDictionary* dataDict = [json objectForKey:@"data"];

  NSArray* availableServers = [dataDict objectForKey:@"items"];

  NSMutableArray* serverList = [[NSMutableArray alloc] init];

  NSUInteger idx = 0;
  NSDictionary* svr;
  NSUInteger count = [availableServers count];

  while (idx < count) {
    svr = [availableServers objectAtIndex:idx++];
    Host* host = [[Host alloc] init];
    host.createdTime = [svr objectForKey:@"createdTime"];
    host.hostId = [svr objectForKey:@"hostId"];
    host.hostName = [svr objectForKey:@"hostName"];
    host.hostVersion = [svr objectForKey:@"hostVersion"];
    host.jabberId = [svr objectForKey:@"jabberId"];
    host.kind = [svr objectForKey:@"kind"];
    host.publicKey = [svr objectForKey:@"publicKey"];
    host.status = [svr objectForKey:@"status"];
    host.updatedTime = [svr objectForKey:@"updatedTime"];
    [serverList addObject:host];
  }

  return serverList;
}

@end