Skip to content

Commit

Permalink
chore: refactor AliceChopperAdapter (#191)
Browse files Browse the repository at this point in the history
* chore: refactor `AliceChopperAdapter`

* fix: use fold instead of map + reduce

* fix: AliceChopperAdapter

* chore: log Alice error on HTTP errors

* chore: update alice_chopper example

* chore: remove unused import

* chore: add more example calls

* chore: add more error logging

* chore: remove unused import

* chore: update alice_chopper example

* chore: add content-type and accept interceptors to example

* chore: add more example HTTP calls

* refactor: rename Post to Article to avoid name clash with Chopper's Post class

* refactor: add const constructors where possible

* refactor: extract ArticlesService out of the caller method

* chore: add more example models

* chore: use flutter_lints for linting

* chore: add more Chopper services

* chore: add more Chopper service routes

* chore: add more test calls

* chore: better error handling in AliceChopperAdapter

* chore: rename lat / lng to latitude / longitude

* chore: better error handling

* fix: add alice_token back

* chore: add broken model examples to trigger error handling

* chore: use Uuid v4 as the alice_token to make it completely unique
  • Loading branch information
techouse authored Jun 9, 2024
1 parent 928357e commit 0f3174b
Show file tree
Hide file tree
Showing 44 changed files with 2,341 additions and 196 deletions.
23 changes: 10 additions & 13 deletions examples/alice_chopper/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
1include: package:very_good_analysis/analysis_options.yaml
analyzer:
exclude:
- "lib/generated_plugin_registrant.dart"
- "**.g.dart"
- "**.chopper.dart"
- "**.mocks.dart"
- "**.gen.dart"

include: package:flutter_lints/flutter.yaml

linter:
rules:
public_member_api_docs: false
flutter_style_todos: false
avoid_final_parameters: false
sort_constructors_first: false
avoid_function_literals_in_foreach_calls: false
avoid_positional_boolean_parameters: false
use_if_null_to_convert_nulls_to_bools: false
use_build_context_synchronously: false
prefer_constructors_over_static_methods: false
use_setters_to_change_properties: false
avoid_print: false
sort_pub_dependencies: false
#library_annotations: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'dart:async' show FutureOr;
import 'dart:io' show ContentType, HttpHeaders;

import 'package:chopper/chopper.dart';

class JsonContentTypeInterceptor implements Interceptor {
@override
FutureOr<Response<BodyType>> intercept<BodyType>(Chain<BodyType> chain) =>
switch (chain.request.method) {
HttpMethod.Post || HttpMethod.Put || HttpMethod.Patch => chain.proceed(
applyHeader(
chain.request,
HttpHeaders.contentTypeHeader,
ContentType.json.mimeType,
),
),
_ => chain.proceed(chain.request),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:async' show FutureOr;
import 'dart:io' show ContentType, HttpHeaders;

import 'package:chopper/chopper.dart';

class JsonHeadersInterceptor implements Interceptor {
@override
FutureOr<Response<BodyType>> intercept<BodyType>(Chain<BodyType> chain) =>
chain.proceed(
applyHeader(
chain.request,
HttpHeaders.acceptHeader,
ContentType.json.mimeType,
),
);
}
Loading

0 comments on commit 0f3174b

Please sign in to comment.