Skip to content

Commit

Permalink
docs: merging PRs + promoting version to 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jossef committed Mar 11, 2020
1 parent 8e1be62 commit 61c3e4d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Add this to your package's pubspec.yaml file:

```yaml
dependencies:
requests: ^3.0.5
requests: ^3.1.0
```
## Usage
Expand Down
12 changes: 10 additions & 2 deletions lib/src/requests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ class Requests {

static Future<Response> head(String url,
{Map<String, String> headers,
Map<String, dynamic> queryParameters,
int port,
RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING,
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
bool persistCookies = true,
bool verify = true}) {
return _httpRequest(HttpMethod.HEAD, url,
bodyEncoding: bodyEncoding,
queryParameters: queryParameters,
port: port,
headers: headers,
timeoutSeconds: timeoutSeconds,
Expand Down Expand Up @@ -201,6 +203,7 @@ class Requests {
int port,
Map<String, dynamic> json,
dynamic body,
Map<String, dynamic> queryParameters,
RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING,
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
bool persistCookies = true,
Expand All @@ -210,6 +213,7 @@ class Requests {
port: port,
json: json,
body: body,
queryParameters: queryParameters,
headers: headers,
timeoutSeconds: timeoutSeconds,
persistCookies: persistCookies,
Expand All @@ -219,19 +223,19 @@ class Requests {
static Future<Response> delete(String url,
{Map<String, String> headers,
Map<String, dynamic> json,
Map<String, dynamic> queryParameters,
dynamic body,
Map<String, dynamic> queryParameters,
int port,
RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING,
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
bool persistCookies = true,
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,
Expand All @@ -242,6 +246,7 @@ class Requests {
{Map<String, dynamic> json,
int port,
dynamic body,
Map<String, dynamic> queryParameters,
RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING,
Map<String, String> headers,
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
Expand All @@ -252,6 +257,7 @@ class Requests {
json: json,
port: port,
body: body,
queryParameters: queryParameters,
headers: headers,
timeoutSeconds: timeoutSeconds,
persistCookies: persistCookies,
Expand All @@ -263,6 +269,7 @@ class Requests {
int port,
Map<String, dynamic> json,
dynamic body,
Map<String, dynamic> queryParameters,
RequestBodyEncoding bodyEncoding = DEFAULT_BODY_ENCODING,
Map<String, String> headers,
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
Expand All @@ -276,6 +283,7 @@ class Requests {
bodyEncoding: bodyEncoding,
json: json,
body: body,
queryParameters: queryParameters,
headers: headers,
timeoutSeconds: timeoutSeconds,
persistCookies: persistCookies,
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ homepage: https://github.com/jossef/requests
authors:
- Jossef Harush <[email protected]>
- Rick Stanley <[email protected]>
- Rafael Carvalho Monteiro <[email protected]>
- Martin <https://github.com/genesiscz>
- Frederik Pietzko <[email protected]>
- Rafael Carvalho Monteiro <[email protected]>
- eggate <https://github.com/eggate>
environment:
sdk: ">=2.0.0 <3.0.0"
dependencies:
Expand Down
47 changes: 27 additions & 20 deletions test/requests_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>());
expect(r.hasError, isA<bool>());
expect(r.success, isA<bool>());
r.raiseForStatus();
}

void main() {
Expand All @@ -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 {
Expand All @@ -61,18 +66,19 @@ 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 {
var r = await Requests.delete(
"$PLACEHOLDER_PROVIDER/api/users/10",
json: {"something": "something"},
);
_validateBasicWorkingRequest(r);
r.raiseForStatus();
_validateResponse(r);
});

test('json http post', () async {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 61c3e4d

Please sign in to comment.