Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#290 implement Equatable #410

Merged
merged 7 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions chopper/lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import 'dart:async';

import 'package:chopper/src/extensions.dart';
import 'package:chopper/src/utils.dart';
import 'package:equatable/equatable.dart' show EquatableMixin;
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

/// This class represents an HTTP request that can be made with Chopper.
class Request extends http.BaseRequest {
class Request extends http.BaseRequest with EquatableMixin {
final Uri uri;
final Uri baseUri;
final dynamic body;
Expand Down Expand Up @@ -207,11 +208,25 @@ class Request extends http.BaseRequest {

return request;
}

@override
List<Object?> get props => [
method,
uri,
baseUri,
body,
parameters,
headers,
multipart,
parts,
useBrackets,
includeNullQueryVars,
];
}

/// Represents a part in a multipart request.
@immutable
class PartValue<T> {
class PartValue<T> with EquatableMixin {
final T value;
final String name;

Expand All @@ -227,6 +242,12 @@ class PartValue<T> {
name ?? this.name,
value ?? this.value as NewType,
);

@override
List<Object?> get props => [
name,
value,
];
}

/// Represents a file part in a multipart request.
Expand Down
10 changes: 9 additions & 1 deletion chopper/lib/src/response.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:typed_data';

import 'package:equatable/equatable.dart' show EquatableMixin;
import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

Expand All @@ -15,7 +16,7 @@ import 'package:meta/meta.dart';
/// Future<Response<Item>> fetchItem();
/// ```
@immutable
class Response<BodyType> {
class Response<BodyType> with EquatableMixin {
/// The [http.BaseResponse] from `package:http` that this [Response] wraps.
final http.BaseResponse base;

Expand Down Expand Up @@ -65,4 +66,11 @@ class Response<BodyType> {
/// call was successful, else this will be `null`.
String get bodyString =>
base is http.Response ? (base as http.Response).body : '';

@override
List<Object?> get props => [
base,
body,
error,
];
}
9 changes: 8 additions & 1 deletion chopper/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:collection';

import 'package:chopper/chopper.dart';
import 'package:equatable/equatable.dart' show EquatableMixin;
import 'package:logging/logging.dart';

/// Creates a new [Request] by copying [request] and adding a header with the
Expand Down Expand Up @@ -130,7 +131,7 @@ Iterable<_Pair<String, String>> _iterableToQuery(

String _normalizeValue(value) => Uri.encodeComponent(value?.toString() ?? '');

class _Pair<A, B> {
class _Pair<A, B> with EquatableMixin {
final A first;
final B second;
final bool useBrackets;
Expand All @@ -145,6 +146,12 @@ class _Pair<A, B> {
String toString() => useBrackets
? '$first${Uri.encodeQueryComponent('[]')}=$second'
: '$first=$second';

@override
List<Object?> get props => [
first,
second,
];
}

bool isTypeOf<ThisType, OfType>() => _Instance<ThisType>() is _Instance<OfType>;
Expand Down
5 changes: 4 additions & 1 deletion chopper/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ environment:
sdk: ">=2.17.0 <3.0.0"

dependencies:
equatable: ^2.0.5
http: ">=0.13.0 <1.0.0"
logging: ^1.0.0
meta: ^1.3.0
Expand All @@ -17,7 +18,9 @@ dev_dependencies:
build_test: ^2.0.0
collection: ^1.16.0
coverage: ^1.0.2
dart_code_metrics: ^4.8.1
dart_code_metrics: '>=4.8.1 <6.0.0'
data_fixture_dart: ^2.2.0
faker: ^2.1.0
http_parser: ^4.0.0
lints: ^2.0.0
test: ^1.16.4
Expand Down
Loading