Skip to content

Commit 5b5d765

Browse files
committed
Fix setRepositorySubscription to be a PUT instead of a POST
1 parent 00cda1c commit 5b5d765

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/src/common/activity_service.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class ActivityService extends Service {
307307
final map =
308308
createNonNullMap({'subscribed': subscribed, 'ignored': ignored});
309309

310-
return github.postJSON(
310+
return github.putJSON(
311311
'/repos/${slug.fullName}/subscription',
312312
statusCode: StatusCodes.OK,
313313
convert: (i) => RepositorySubscription.fromJson(i),

lib/src/common/github.dart

+42
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,48 @@ class GitHub {
211211
preview: preview,
212212
);
213213

214+
/// Handles PUT Requests that respond with JSON
215+
///
216+
/// [path] can either be a path like '/repos' or a full url.
217+
/// [statusCode] is the expected status code. If it is null, it is ignored.
218+
/// If the status code that the response returns is not the status code you provide
219+
/// then the [fail] function will be called with the HTTP Response.
220+
///
221+
/// If you don't throw an error or break out somehow, it will go into some error checking
222+
/// that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
223+
/// for errors, it throws an Unknown Error.
224+
///
225+
/// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
226+
/// [params] are query string parameters.
227+
/// [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
228+
///
229+
/// The future will pass the object returned from this function to the then method.
230+
/// The default [convert] function returns the input object.
231+
/// [body] is the data to send to the server. Pass in a List<int> if you want to post binary body data. Everything else will have .toString() called on it and set as text content
232+
/// [S] represents the input type.
233+
/// [T] represents the type return from this function after conversion
234+
Future<T> putJSON<S, T>(
235+
String path, {
236+
int statusCode,
237+
void Function(http.Response response) fail,
238+
Map<String, String> headers,
239+
Map<String, String> params,
240+
JSONConverter<S, T> convert,
241+
dynamic body,
242+
String preview,
243+
}) =>
244+
_requestJson(
245+
'PUT',
246+
path,
247+
statusCode: statusCode,
248+
fail: fail,
249+
headers: headers,
250+
params: params,
251+
convert: convert,
252+
body: body,
253+
preview: preview,
254+
);
255+
214256
Future<T> _requestJson<S, T>(
215257
String method,
216258
String path, {

0 commit comments

Comments
 (0)