From 61c3e4ded222031b5bcdab55ba10f5cbaf60f7b9 Mon Sep 17 00:00:00 2001 From: jossef Date: Thu, 12 Mar 2020 00:34:22 +0200 Subject: [PATCH] docs: merging PRs + promoting version to 3.1.0 --- CHANGELOG.md | 12 +++++++---- README.md | 2 +- lib/src/requests.dart | 12 +++++++++-- pubspec.yaml | 3 ++- test/requests_test.dart | 47 +++++++++++++++++++++++------------------ 5 files changed, 48 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ec8838..763193d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,17 +10,21 @@ - fix: parse json only if requested -## 3.0.5 +## 3.0.4 - fix: added body in patch and delete methods +## 3.0.5 + +- fix: body in delete method + ## 3.1.0 -- BREAKING CHANGE: removed port from url. Added parameter port according to `Uri` best practices. -- feature: added queryParameter support in get requests +- feature: added optional parameter `port` (also supporting inline url representation e.g. "http://foo.bar:1337") +- feature: added queryParameters support in get requests - feature: created Github QA workflow to prevent pushes that breaks analyze or tests - enhancement: changed http method strings into enum to avoid errors - enhancement: improved type of arguments to prevent unexpected errors - enhancement: added more validations on tests - enhancement: executed flutter format to improve pub score -- enhancement: changed some anti patterns. +- fix: cookie matching incorrect variable + case insensitive diff --git a/README.md b/README.md index f4e1810..d99c6bb 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Add this to your package's pubspec.yaml file: ```yaml dependencies: - requests: ^3.0.5 + requests: ^3.1.0 ``` ## Usage diff --git a/lib/src/requests.dart b/lib/src/requests.dart index 50ff561..bc38bb1 100644 --- a/lib/src/requests.dart +++ b/lib/src/requests.dart @@ -164,6 +164,7 @@ class Requests { static Future head(String url, {Map headers, + Map queryParameters, int port, RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING, int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, @@ -171,6 +172,7 @@ class Requests { bool verify = true}) { return _httpRequest(HttpMethod.HEAD, url, bodyEncoding: bodyEncoding, + queryParameters: queryParameters, port: port, headers: headers, timeoutSeconds: timeoutSeconds, @@ -201,6 +203,7 @@ class Requests { int port, Map json, dynamic body, + Map queryParameters, RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING, int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, bool persistCookies = true, @@ -210,6 +213,7 @@ class Requests { port: port, json: json, body: body, + queryParameters: queryParameters, headers: headers, timeoutSeconds: timeoutSeconds, persistCookies: persistCookies, @@ -219,8 +223,8 @@ class Requests { static Future delete(String url, {Map headers, Map json, - Map queryParameters, dynamic body, + Map queryParameters, int port, RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING, int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, @@ -228,10 +232,10 @@ class Requests { bool verify = true}) { return _httpRequest(HttpMethod.DELETE, url, bodyEncoding: bodyEncoding, - queryParameters: queryParameters, port: port, json: json, body: body, + queryParameters: queryParameters, headers: headers, timeoutSeconds: timeoutSeconds, persistCookies: persistCookies, @@ -242,6 +246,7 @@ class Requests { {Map json, int port, dynamic body, + Map queryParameters, RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING, Map headers, int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, @@ -252,6 +257,7 @@ class Requests { json: json, port: port, body: body, + queryParameters: queryParameters, headers: headers, timeoutSeconds: timeoutSeconds, persistCookies: persistCookies, @@ -263,6 +269,7 @@ class Requests { int port, Map json, dynamic body, + Map queryParameters, RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING, Map headers, int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, @@ -276,6 +283,7 @@ class Requests { bodyEncoding: bodyEncoding, json: json, body: body, + queryParameters: queryParameters, headers: headers, timeoutSeconds: timeoutSeconds, persistCookies: persistCookies, diff --git a/pubspec.yaml b/pubspec.yaml index 12adf09..a2bc024 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,9 +5,10 @@ homepage: https://github.com/jossef/requests authors: - Jossef Harush - Rick Stanley -- Rafael Carvalho Monteiro - Martin - Frederik Pietzko +- Rafael Carvalho Monteiro +- eggate environment: sdk: ">=2.0.0 <3.0.0" dependencies: diff --git a/test/requests_test.dart b/test/requests_test.dart index 39198c5..a56db5d 100644 --- a/test/requests_test.dart +++ b/test/requests_test.dart @@ -2,11 +2,10 @@ import 'package:requests/requests.dart'; import 'package:shared_preferences/shared_preferences.dart'; import "package:test/test.dart"; -void _validateBasicWorkingRequest(Response r) { +void _validateResponse(Response r) { expect(r.statusCode, isA()); expect(r.hasError, isA()); expect(r.success, isA()); - r.raiseForStatus(); } void main() { @@ -19,36 +18,42 @@ void main() { test('plain http get', () async { var r = await Requests.get("https://google.com"); + r.raiseForStatus(); dynamic body = r.content(); expect(body, isNotNull); - _validateBasicWorkingRequest(r); + _validateResponse(r); }); test('plain http get with query parameters', () async { var r = await Requests.get("https://google.com", queryParameters: DEFAULT_QUERY_PARAMETER); + r.raiseForStatus(); dynamic body = r.content(); expect(body, isNotNull); expect(r.url.toString(), contains('?id=1')); - _validateBasicWorkingRequest(r); + _validateResponse(r); }); test('plain http get with port 80', () async { var r = await Requests.get("http://google.com", port: 80); + r.raiseForStatus(); + _validateResponse(r); dynamic body = r.content(); expect(body, isNotNull); - _validateBasicWorkingRequest(r); + }); + + test('plain http get with port 8080', () async { + var r = await Requests.get('http://portquiz.net:8080/'); + r.raiseForStatus(); }); test('json http get list of objects', () async { dynamic r = await Requests.get("$PLACEHOLDER_PROVIDER/api/users"); r.raiseForStatus(); - dynamic body = r.json(); - expect(body, isNotNull); expect(body['data'], isList); - _validateBasicWorkingRequest(r); + _validateResponse(r); }); test('FormURLEncoded http post', () async { @@ -61,10 +66,10 @@ void main() { "libero voluptate eveniet aperiam sed\nsunt placeat suscipit molestias\nsimilique fugit nam natus\nexpedita consequatur consequatur dolores quia eos et placeat", }, bodyEncoding: RequestBodyEncoding.FormURLEncoded); - + r.raiseForStatus(); dynamic body = r.json(); expect(body, isNotNull); - _validateBasicWorkingRequest(r); + _validateResponse(r); }); test('json http delete with request body', () async { @@ -72,7 +77,8 @@ void main() { "$PLACEHOLDER_PROVIDER/api/users/10", json: {"something": "something"}, ); - _validateBasicWorkingRequest(r); + r.raiseForStatus(); + _validateResponse(r); }); test('json http post', () async { @@ -83,15 +89,16 @@ void main() { "body": "libero voluptate eveniet aperiam sed\nsunt placeat suscipit molestias\nsimilique fugit nam natus\nexpedita consequatur consequatur dolores quia eos et placeat", }); - + r.raiseForStatus(); dynamic body = r.json(); expect(body, isNotNull); - _validateBasicWorkingRequest(r); + _validateResponse(r); }); test('json http delete', () async { var r = await Requests.delete("$PLACEHOLDER_PROVIDER/api/users/10"); - _validateBasicWorkingRequest(r); + r.raiseForStatus(); + _validateResponse(r); }); test('json http post as a form and as a JSON', () async { @@ -102,19 +109,19 @@ void main() { "body": "libero voluptate eveniet aperiam sed\nsunt placeat suscipit molestias\nsimilique fugit nam natus\nexpedita consequatur consequatur dolores quia eos et placeat", }); - + r.raiseForStatus(); dynamic body = r.json(); expect(body["userId"], 10); - _validateBasicWorkingRequest(r); + _validateResponse(r); }); test('json http get object', () async { var r = await Requests.get("$PLACEHOLDER_PROVIDER/api/users/2"); - + r.raiseForStatus(); dynamic body = r.json(); expect(body, isNotNull); expect(body, isMap); - _validateBasicWorkingRequest(r); + _validateResponse(r); }); test('remove cookies', () async { @@ -133,12 +140,12 @@ void main() { test('response as Response object', () async { var r = await Requests.post('$PLACEHOLDER_PROVIDER/api/users', body: {"name": "morpheus"}); + r.raiseForStatus(); var content = r.content(); var json = r.json(); - - _validateBasicWorkingRequest(r); expect(content, isNotNull); expect(json, isNotNull); + _validateResponse(r); }); test('throw error', () async {