|
1 | 1 | import 'dart:async';
|
2 | 2 | import 'dart:convert';
|
| 3 | + |
3 | 4 | import 'package:github/src/common.dart';
|
4 | 5 | import 'package:github/src/common/util/utils.dart';
|
5 | 6 | import 'package:http/http.dart' as http;
|
@@ -245,6 +246,48 @@ class GitHub {
|
245 | 246 | preview: preview,
|
246 | 247 | );
|
247 | 248 |
|
| 249 | + /// Handles PATCH Requests that respond with JSON |
| 250 | + /// |
| 251 | + /// [path] can either be a path like '/repos' or a full url. |
| 252 | + /// [statusCode] is the expected status code. If it is null, it is ignored. |
| 253 | + /// If the status code that the response returns is not the status code you provide |
| 254 | + /// then the [fail] function will be called with the HTTP Response. |
| 255 | + /// |
| 256 | + /// If you don't throw an error or break out somehow, it will go into some error checking |
| 257 | + /// that throws exceptions when it finds a 404 or 401. If it doesn't find a general HTTP Status Code |
| 258 | + /// for errors, it throws an Unknown Error. |
| 259 | + /// |
| 260 | + /// [headers] are HTTP Headers. If it doesn't exist, the 'Accept' and 'Authorization' headers are added. |
| 261 | + /// [params] are query string parameters. |
| 262 | + /// [convert] is a simple function that is passed this [GitHub] instance and a JSON object. |
| 263 | + /// |
| 264 | + /// The future will pass the object returned from this function to the then method. |
| 265 | + /// The default [convert] function returns the input object. |
| 266 | + /// [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 |
| 267 | + /// [S] represents the input type. |
| 268 | + /// [T] represents the type return from this function after conversion |
| 269 | + Future<T> patchJSON<S, T>( |
| 270 | + String path, { |
| 271 | + int? statusCode, |
| 272 | + void Function(http.Response response)? fail, |
| 273 | + Map<String, String>? headers, |
| 274 | + Map<String, dynamic>? params, |
| 275 | + JSONConverter<S, T>? convert, |
| 276 | + dynamic body, |
| 277 | + String? preview, |
| 278 | + }) => |
| 279 | + requestJson( |
| 280 | + 'PATCH', |
| 281 | + path, |
| 282 | + statusCode: statusCode, |
| 283 | + fail: fail, |
| 284 | + headers: headers, |
| 285 | + params: params, |
| 286 | + convert: convert, |
| 287 | + body: body, |
| 288 | + preview: preview, |
| 289 | + ); |
| 290 | + |
248 | 291 | Future<T> requestJson<S, T>(
|
249 | 292 | String method,
|
250 | 293 | String path, {
|
|
0 commit comments