-
Notifications
You must be signed in to change notification settings - Fork 39
/
Repository.m
91 lines (68 loc) · 2.6 KB
/
Repository.m
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Repository.m
// git-phone
//
// Created by Sam Schroeder on 1/19/09.
// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
//
#import "Repository.h"
#import "Connector.h"
#import "Commit.h"
#import "NSString+JSON.h"
@implementation Repository
@synthesize name;
@synthesize owner;
@synthesize privateRepo;
@synthesize commits;
+ (NSString *)indexURL {
return [NSString stringWithFormat:@"%@/%@",
[[Config instance] baseAPIURL],
[[Config instance] gitHubUserName]];
}
- (NSString *)commitsURL {
// http://github.com/api/v1/json/caged/gitnub/commits/master
return [NSString stringWithFormat:@"%@/%@/%@/commits/master",
[[Config instance] baseAPIURL],
[self owner],
[self name]];
}
+ (void)loadAll {
NSString *resultJSON = [Connector postToURL:[self indexURL]];
NSMutableArray *publicRepoArray = [[NSMutableArray alloc] init];
NSMutableArray *privateRepoArray = [[NSMutableArray alloc] init];
NSMutableArray *repositories = [[NSMutableArray alloc] init];
// GitHub JSON: {"user": {"repositories": [{repo1},{repo1}] }}
repositories = [[[resultJSON JSONValue] valueForKey:@"user"] valueForKey:@"repositories"];
for (NSDictionary *repository in repositories) {
Repository *tempRepo = [[Repository alloc] init];
[tempRepo setName:[repository valueForKey:@"name"]];
[tempRepo setOwner:[repository valueForKey:@"owner"]];
[tempRepo setPrivateRepo:[DataParser readInt:[repository valueForKey:@"private"]]];
DevLog2(@"Loaded Repo: %@", [tempRepo name]);
if ([tempRepo privateRepo] == [DataParser readInt:@"1"]) {
[privateRepoArray addObject:tempRepo];
} else {
[publicRepoArray addObject:tempRepo];
}
}
[[Config instance] setPublicRepositories:publicRepoArray];
[[Config instance] setPrivateRepositories:privateRepoArray];
}
- (void)loadCommits {
NSString *resultJSON = [Connector postToURL:[self commitsURL]];
NSMutableArray *commitsArray = [[NSMutableArray alloc] init];
NSMutableArray *repoCommits = [[NSMutableArray alloc] init];
repoCommits = [[resultJSON JSONValue] valueForKey:@"commits"];
for (NSDictionary *commit in repoCommits) {
Commit *tempCommit = [[Commit alloc] init];
[tempCommit setCommitID:[commit valueForKey:@"id"]];
[tempCommit setMessage:[commit valueForKey:@"message"]];
[tempCommit setUrl:[commit valueForKey:@"url"]];
[tempCommit setAuthorName:[[commit valueForKey:@"author"] valueForKey:@"name"]];
[tempCommit setAuthorEmail:[[commit valueForKey:@"author"] valueForKey:@"email"]];
DevLog2(@"Loaded Commit: %@", [tempCommit message]);
[commitsArray addObject:tempCommit];
}
[self setCommits:commitsArray];
}
@end