Skip to content

Commit

Permalink
Fix setRepositorySubscription to be a PUT instead of a POST
Browse files Browse the repository at this point in the history
  • Loading branch information
robbecker-wf committed Apr 11, 2020
1 parent 00cda1c commit 5b5d765
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/common/activity_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class ActivityService extends Service {
final map =
createNonNullMap({'subscribed': subscribed, 'ignored': ignored});

return github.postJSON(
return github.putJSON(
'/repos/${slug.fullName}/subscription',
statusCode: StatusCodes.OK,
convert: (i) => RepositorySubscription.fromJson(i),
Expand Down
42 changes: 42 additions & 0 deletions lib/src/common/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,48 @@ class GitHub {
preview: preview,
);

/// Handles PUT Requests that respond with JSON
///
/// [path] can either be a path like '/repos' or a full url.
/// [statusCode] is the expected status code. If it is null, it is ignored.
/// If the status code that the response returns is not the status code you provide
/// then the [fail] function will be called with the HTTP Response.
///
/// If you don't throw an error or break out somehow, it will go into some error checking
/// that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code
/// for errors, it throws an Unknown Error.
///
/// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added.
/// [params] are query string parameters.
/// [convert] is a simple function that is passed this [GitHub] instance and a JSON object.
///
/// The future will pass the object returned from this function to the then method.
/// The default [convert] function returns the input object.
/// [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
/// [S] represents the input type.
/// [T] represents the type return from this function after conversion
Future<T> putJSON<S, T>(
String path, {
int statusCode,
void Function(http.Response response) fail,
Map<String, String> headers,
Map<String, String> params,
JSONConverter<S, T> convert,
dynamic body,
String preview,
}) =>
_requestJson(
'PUT',
path,
statusCode: statusCode,
fail: fail,
headers: headers,
params: params,
convert: convert,
body: body,
preview: preview,
);

Future<T> _requestJson<S, T>(
String method,
String path, {
Expand Down

0 comments on commit 5b5d765

Please sign in to comment.