@@ -109,18 +109,24 @@ class GitHub {
109
109
/**
110
110
* Fetches the teams for the organization specified by [name] .
111
111
*/
112
- Future <List <Team >> teams (String name) {
112
+ Future <List <Team >> teams (String name, [ int limit] ) {
113
113
var group = new FutureGroup <Team >();
114
114
getJSON ("/orgs/${name }/teams" ).then ((teams) {
115
115
for (var team in teams) {
116
- group.add (getJSON (team['url' ], convert: Team .fromJSON, statusCode: 200 , fail: (error) {
117
- throw new TeamNotFound (this , team['id' ]);
116
+ group.add (getJSON (team['url' ], convert: Team .fromJSON, statusCode: 200 , fail: (http.Response response) {
117
+ if (response.statusCode == 404 ) {
118
+ throw new TeamNotFound (this , team['id' ]);
119
+ }
120
+ throw new UnknownError (this );
118
121
}));
119
122
}
120
123
});
121
124
return group.future;
122
125
}
123
126
127
+ /**
128
+ * Renders Markdown from the [input] .
129
+ */
124
130
Future <String > renderMarkdown (String input, {String mode: "markdown" , String context}) {
125
131
return request ("POST" , "/markdown" , body: JSON .encode ({
126
132
"text" : input,
@@ -131,10 +137,16 @@ class GitHub {
131
137
});
132
138
}
133
139
140
+ /**
141
+ * Gets .gitignore template names.
142
+ */
134
143
Future <List <String >> gitignoreTemplates () {
135
144
return getJSON ("/gitignore/templates" );
136
145
}
137
146
147
+ /**
148
+ * Gets a .gitignore template by [name] .
149
+ */
138
150
Future <GitignoreTemplate > gitignoreTemplate (String name) {
139
151
return getJSON ("/gitignore/templates/${name }" , convert: GitignoreTemplate .fromJSON);
140
152
}
@@ -148,28 +160,47 @@ class GitHub {
148
160
});
149
161
}
150
162
163
+ /**
164
+ * Gets a Repositories Releases
165
+ */
151
166
Future <List <Release >> releases (RepositorySlug slug, [int limit = 30 ]) {
152
167
return getJSON ("/repos/${slug .fullName }/releases" , params: { "per_page" : limit }).then ((releases) {
153
168
return copyOf (releases.map ((it) => Release .fromJSON (this , it)));
154
169
});
155
170
}
156
171
172
+ /**
173
+ * Fetches a GitHub Release.
174
+ */
157
175
Future <Release > release (RepositorySlug slug, int id) {
158
176
return getJSON ("/repos/${slug .fullName }/releases/${id }" , convert: Release .fromJSON);
159
177
}
160
178
179
+ /**
180
+ * Gets API Rate Limit Information
181
+ */
161
182
Future <RateLimit > rateLimit () {
162
183
return request ("GET" , "/" ).then ((response) {
163
184
return RateLimit .fromHeaders (response.headers);
164
185
});
165
186
}
166
187
188
+ /**
189
+ * Gets the Currently Authenticated User
190
+ *
191
+ * Throws [AccessForbidden] if we are not authenticated.
192
+ */
167
193
Future <CurrentUser > currentUser () {
168
- return getJSON ("/user" , statusCode: 200 , fail: (response) {
169
- throw "Not Authenticated" ;
194
+ return getJSON ("/user" , statusCode: 200 , fail: (http.Response response) {
195
+ if (response.statusCode == 403 ) {
196
+ throw new AccessForbidden (this );
197
+ }
170
198
}, convert: CurrentUser .fromJSON);
171
199
}
172
200
201
+ /**
202
+ * Handles Get Requests that respond with JSON
203
+ */
173
204
Future <dynamic > getJSON (String path, {int statusCode, void fail (http.Response response), Map <String , String > headers, Map <String , String > params, JSONConverter convert}) {
174
205
if (convert == null ) {
175
206
convert = (github, input) => input;
@@ -184,6 +215,9 @@ class GitHub {
184
215
});
185
216
}
186
217
218
+ /**
219
+ * Handles Post Requests that respond with JSON
220
+ */
187
221
Future <dynamic > postJSON (String path, {int statusCode, void fail (http.Response response), Map <String , String > headers, Map <String , String > params, JSONConverter convert, body}) {
188
222
if (convert == null ) {
189
223
convert = (github, input) => input;
@@ -198,6 +232,9 @@ class GitHub {
198
232
});
199
233
}
200
234
235
+ /**
236
+ * Handles Authenticated Requests
237
+ */
201
238
Future <http.Response > request (String method, String path, {Map <String , String > headers, Map <String , dynamic > params, String body}) {
202
239
if (headers == null ) {
203
240
headers = {};
0 commit comments