forked from jonmarimba/CocoaREST
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GithubDelegate.m
124 lines (96 loc) · 3.94 KB
/
GithubDelegate.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// GithubDelegate.m
// CocoaREST
//
// Created by Clint Shryock on 3/6/10.
// Copyright 2010. All rights reserved.
//
#import "GithubDelegate.h"
@implementation GithubDelegate
@synthesize isWaiting;
@synthesize repositories;
@synthesize forks;
@synthesize user;
@synthesize issues;
- (void) awakeFromNib
{
manager = [[SDGithubTaskManager manager] retain];
manager.delegate = self;
manager.successSelector = @selector(githubManager:resultsReadyForTask:);
manager.failSelector = @selector(githubManager:failedForTask:);
manager.maxConcurrentTasks = 3;
}
- (IBAction) runTask:(id)sender {
SDGithubTask *basicTask = [SDGithubTask taskWithManager:manager];
manager.username = [userField stringValue];
manager.password = [apiTokenField stringValue];
basicTask.type = [[taskTypeButton selectedItem] tag];
basicTask.user = [userField stringValue];
[basicTask run];
self.isWaiting = YES;
}
- (void) githubManager:(SDGithubTaskManager*)manager resultsReadyForTask:(SDGithubTask*)task {
self.repositories = [task.results valueForKey:@"repositories"];
self.user = [task.results objectForKey:@"user"];
self.isWaiting = NO;
}
- (void) githubManager:(SDGithubTaskManager*)manager failedForTask:(SDGithubTask*)task {
self.isWaiting = NO;
self.repositories = nil;
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Error"];
[alert setInformativeText:[task.error localizedDescription]];
[alert runModal];
}
- (void) tableViewSelectionDidChange:(NSNotification *)notification {
NSUInteger index = [repositoriesView selectedRow];
if (self.repositories) {
SDGithubTaskManager *forkManager = [[SDGithubTaskManager manager] retain];
forkManager.delegate = self;
forkManager.successSelector = @selector(githubForkManager:resultsReadyForTask:);
forkManager.failSelector = @selector(githubForkManager:failedForTask:);
forkManager.maxConcurrentTasks = 3;
SDGithubTask *networkTask = [SDGithubTask taskWithManager:forkManager];
networkTask.type = SDGithubTaskGetRepoNetwork;
networkTask.user = [userField stringValue];
networkTask.repo = [[self.repositories objectAtIndex:index] valueForKey:@"name"];
[networkTask run];
SDGithubTaskManager *issuesManager = [[SDGithubTaskManager manager] retain];
issuesManager.delegate = self;
issuesManager.successSelector = @selector(githubIssuesManager:resultsReadyForTask:);
issuesManager.failSelector = @selector(githubIssuesManager:failedForTask:);
issuesManager.maxConcurrentTasks = 3;
SDGithubTask *issuesTask = [SDGithubTask taskWithManager:issuesManager];
issuesTask.type = SDGithubTaskIssuesList;
issuesTask.user = [userField stringValue];
issuesTask.repo = [[self.repositories objectAtIndex:index] valueForKey:@"name"];
issuesTask.issueState = @"open";
[issuesTask run];
self.isWaiting = YES;
}
}
- (void) githubForkManager:(SDGithubTaskManager*)manager resultsReadyForTask:(SDGithubTask*)task {
self.isWaiting = NO;
self.forks = [task.results valueForKey:@"network"];
}
- (void) githubForkManager:(SDGithubTaskManager*)manager failedForTask:(SDGithubTask*)task {
self.isWaiting = NO;
self.forks = nil;
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Error"];
[alert setInformativeText:[task.error localizedDescription]];
[alert runModal];
}
- (void) githubIssuesManager:(SDGithubTaskManager*)manager resultsReadyForTask:(SDGithubTask*)task {
self.isWaiting = NO;
self.issues = [task.results valueForKey:@"issues"];
}
- (void) githubIssuesManager:(SDGithubTaskManager*)manager failedForTask:(SDGithubTask*)task {
self.isWaiting = NO;
self.issues = nil;
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:@"Error"];
[alert setInformativeText:[task.error localizedDescription]];
[alert runModal];
}
@end