-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
366 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,12 @@ import 'package:alice/alice.dart'; | |
import 'package:alice_chopper/alice_chopper_adapter.dart'; | ||
import 'package:example/interceptors/json_content_type_inerceptor.dart'; | ||
import 'package:example/interceptors/json_headers_interceptor.dart'; | ||
import 'package:example/models/address.dart'; | ||
import 'package:example/models/album.dart'; | ||
import 'package:example/models/article.dart'; | ||
import 'package:example/models/comment.dart'; | ||
import 'package:example/models/company.dart'; | ||
import 'package:example/models/geo_location.dart'; | ||
import 'package:example/models/photo.dart'; | ||
import 'package:example/models/todo.dart'; | ||
import 'package:example/models/user.dart'; | ||
|
@@ -61,29 +64,365 @@ class _MyAppState extends State<MyApp> { | |
}), | ||
); | ||
|
||
late final AlbumsService albumsService = _chopper.getService<AlbumsService>(); | ||
late final ArticlesService articlesService = | ||
_chopper.getService<ArticlesService>(); | ||
late final CommentsService commentsService = | ||
_chopper.getService<CommentsService>(); | ||
late final PhotosService photosService = _chopper.getService<PhotosService>(); | ||
late final TodosService todosService = _chopper.getService<TodosService>(); | ||
late final UsersService usersService = _chopper.getService<UsersService>(); | ||
|
||
Future<void> _runChopperHttpRequests() async { | ||
const Article article = Article( | ||
title: 'foo', | ||
body: 'bar', | ||
userId: 1, | ||
/// Albums HTTP requests | ||
Future<void> _albumsRequests() async { | ||
albumsService.getAll(); | ||
albumsService.getAll(userId: 1); | ||
albumsService.get(1); | ||
albumsService.getPhotos(1); | ||
albumsService.post( | ||
const Album( | ||
title: 'foo', | ||
userId: 1, | ||
), | ||
); | ||
albumsService.put( | ||
1, | ||
const Album( | ||
id: 1, | ||
title: 'bar', | ||
userId: 1, | ||
), | ||
); | ||
albumsService.patch( | ||
1, | ||
const Album( | ||
id: 1, | ||
title: 'baz', | ||
userId: 1, | ||
), | ||
); | ||
albumsService.delete(1); | ||
albumsService.put( | ||
123456, | ||
const Album( | ||
id: 123456, | ||
title: 'qux', | ||
userId: 1, | ||
), | ||
); | ||
albumsService.patch( | ||
123456, | ||
const Album( | ||
id: 123456, | ||
title: 'quux', | ||
userId: 1, | ||
), | ||
); | ||
albumsService.get(123456); | ||
albumsService.delete(123456); | ||
} | ||
|
||
/// Articles (Posts) HTTP requests | ||
Future<void> _articlesRequests() async { | ||
articlesService.getAll(); | ||
articlesService.getAll(userId: 2); | ||
articlesService.post(article); | ||
articlesService.post( | ||
const Article( | ||
title: 'foo', | ||
body: 'bar', | ||
userId: 1, | ||
), | ||
); | ||
articlesService.get(1); | ||
articlesService.put(1, article.copyWith(id: 1)); | ||
articlesService.patch(1, article.copyWith(id: 1)); | ||
articlesService.getComments(1); | ||
articlesService.put( | ||
1, | ||
const Article( | ||
id: 1, | ||
title: 'baz', | ||
body: 'qux', | ||
userId: 1, | ||
), | ||
); | ||
articlesService.patch( | ||
1, | ||
const Article( | ||
id: 1, | ||
title: 'lorem', | ||
body: 'ipsum', | ||
userId: 1, | ||
), | ||
); | ||
articlesService.delete(1); | ||
articlesService.put(123456, article.copyWith(id: 123456)); | ||
articlesService.patch(123456, article.copyWith(id: 123456)); | ||
articlesService.put( | ||
123456, | ||
const Article( | ||
id: 123456, | ||
title: 'dolor', | ||
body: 'sit', | ||
userId: 1, | ||
), | ||
); | ||
articlesService.patch( | ||
123456, | ||
const Article( | ||
id: 123456, | ||
title: 'amet', | ||
body: 'consectetur', | ||
userId: 1, | ||
), | ||
); | ||
articlesService.get(123456); | ||
articlesService.delete(123456); | ||
} | ||
|
||
/// Comments HTTP requests | ||
Future<void> _commentsRequests() async { | ||
commentsService.getAll(); | ||
commentsService.getAll(articleId: 1); | ||
commentsService.getAll(email: '[email protected]'); | ||
} | ||
|
||
/// Photos HTTP requests | ||
Future<void> _photosRequests() async { | ||
photosService.getAll(); | ||
photosService.getAll(albumId: 1); | ||
photosService.get(1); | ||
photosService.post( | ||
Photo( | ||
title: 'foo', | ||
url: Uri.parse('https://via.placeholder.com/600/92c952'), | ||
thumbnailUrl: Uri.parse('https://via.placeholder.com/150/92c952'), | ||
albumId: 1, | ||
), | ||
); | ||
photosService.put( | ||
1, | ||
Photo( | ||
id: 1, | ||
title: 'bar', | ||
url: Uri.parse('https://via.placeholder.com/600/92c952'), | ||
thumbnailUrl: Uri.parse('https://via.placeholder.com/150/92c952'), | ||
albumId: 1, | ||
), | ||
); | ||
photosService.patch( | ||
1, | ||
Photo( | ||
id: 1, | ||
title: 'baz', | ||
url: Uri.parse('https://via.placeholder.com/600/92c952'), | ||
thumbnailUrl: Uri.parse('https://via.placeholder.com/150/92c952'), | ||
albumId: 1, | ||
), | ||
); | ||
photosService.delete(1); | ||
photosService.put( | ||
123456, | ||
Photo( | ||
id: 123456, | ||
title: 'qux', | ||
url: Uri.parse('https://via.placeholder.com/600/92c952'), | ||
thumbnailUrl: Uri.parse('https://via.placeholder.com/150/92c952'), | ||
albumId: 1, | ||
), | ||
); | ||
photosService.patch( | ||
123456, | ||
Photo( | ||
id: 123456, | ||
title: 'quux', | ||
url: Uri.parse('https://via.placeholder.com/600/92c952'), | ||
thumbnailUrl: Uri.parse('https://via.placeholder.com/150/92c952'), | ||
albumId: 1, | ||
), | ||
); | ||
photosService.get(123456); | ||
photosService.delete(123456); | ||
} | ||
|
||
/// Todos HTTP requests | ||
Future<void> _todosRequests() async { | ||
todosService.getAll(); | ||
todosService.getAll(userId: 1); | ||
todosService.get(1); | ||
todosService.post( | ||
const Todo( | ||
title: 'foo', | ||
completed: false, | ||
userId: 1, | ||
), | ||
); | ||
todosService.put( | ||
1, | ||
const Todo( | ||
id: 1, | ||
title: 'bar', | ||
completed: false, | ||
userId: 1, | ||
), | ||
); | ||
todosService.patch( | ||
1, | ||
const Todo( | ||
id: 1, | ||
title: 'baz', | ||
completed: false, | ||
userId: 1, | ||
), | ||
); | ||
todosService.delete(1); | ||
todosService.put( | ||
123456, | ||
const Todo( | ||
id: 123456, | ||
title: 'qux', | ||
completed: false, | ||
userId: 1, | ||
), | ||
); | ||
todosService.patch( | ||
123456, | ||
const Todo( | ||
id: 123456, | ||
title: 'quux', | ||
completed: false, | ||
userId: 1, | ||
), | ||
); | ||
todosService.get(123456); | ||
todosService.delete(123456); | ||
} | ||
|
||
/// Users HTTP requests | ||
Future<void> _usersRequests() async { | ||
const User johnDoe = User( | ||
name: 'John Doe', | ||
username: 'johndoe', | ||
email: '[email protected]', | ||
phone: '+12025550123', | ||
website: 'john-doe.test', | ||
address: Address( | ||
street: '1234 Elm St', | ||
suite: 'Apt. 123', | ||
city: 'Springfield', | ||
zipCode: '12345-6789', | ||
geoLocation: GeoLocation( | ||
lat: 37.1234, | ||
lng: -122.1234, | ||
), | ||
), | ||
company: Company( | ||
name: 'John Doe Inc.', | ||
catchPhrase: 'Hello, World!', | ||
businessStrategy: 'Hello, World!', | ||
), | ||
); | ||
|
||
usersService.getAll(); | ||
usersService.getAll(id: 1); | ||
usersService.getAll(username: 'Antonette'); | ||
usersService.getAll(email: '[email protected]'); | ||
usersService.getAll(phone: '(254)954-1289'); | ||
usersService.getAll(website: 'elvis.io'); | ||
usersService.get(1); | ||
usersService.getAlbums(1); | ||
usersService.getTodos(1); | ||
usersService.getArticles(1); | ||
usersService.post(johnDoe); | ||
usersService.put( | ||
1, | ||
johnDoe.copyWith( | ||
address: johnDoe.address.copyWith( | ||
city: 'New York', | ||
street: '1234 Main St', | ||
geoLocation: johnDoe.address.geoLocation.copyWith( | ||
lat: 40.7128, | ||
lng: -74.0060, | ||
), | ||
), | ||
), | ||
); | ||
usersService.patch( | ||
1, | ||
johnDoe.copyWith( | ||
address: johnDoe.address.copyWith( | ||
city: 'Los Angeles', | ||
street: '1234 Maple St', | ||
geoLocation: johnDoe.address.geoLocation.copyWith( | ||
lat: 34.0522, | ||
lng: -118.2437, | ||
), | ||
), | ||
), | ||
); | ||
usersService.delete(1); | ||
usersService.put( | ||
123456, | ||
johnDoe.copyWith( | ||
id: 123456, | ||
name: 'Jane Doe', | ||
username: 'janedoe', | ||
email: '[email protected]', | ||
phone: '+12025550124', | ||
website: 'jane-doe.test', | ||
address: johnDoe.address.copyWith( | ||
street: '1234 Elm St', | ||
suite: 'Apt. 123', | ||
city: 'Springfield', | ||
zipCode: '12345-6789', | ||
geoLocation: johnDoe.address.geoLocation.copyWith( | ||
lat: 37.1234, | ||
lng: -122.1234, | ||
), | ||
), | ||
company: johnDoe.company.copyWith( | ||
name: 'Jane Doe Inc.', | ||
catchPhrase: 'Hello, World!', | ||
businessStrategy: 'Hello, World!', | ||
), | ||
), | ||
); | ||
usersService.patch( | ||
123456, | ||
johnDoe.copyWith( | ||
id: 123456, | ||
name: 'Jane Doe', | ||
username: 'janedoe', | ||
email: '[email protected]', | ||
phone: '+12025550124', | ||
website: 'jane-doe.test', | ||
address: johnDoe.address.copyWith( | ||
street: '1234 Elm St', | ||
suite: 'Apt. 123', | ||
city: 'Springfield', | ||
zipCode: '12345-6789', | ||
geoLocation: johnDoe.address.geoLocation.copyWith( | ||
lat: 37.1234, | ||
lng: -122.1234, | ||
), | ||
), | ||
company: johnDoe.company.copyWith( | ||
name: 'Jane Doe Inc.', | ||
catchPhrase: 'Hello, World!', | ||
businessStrategy: 'Hello, World!', | ||
), | ||
), | ||
); | ||
usersService.get(123456); | ||
usersService.delete(123456); | ||
} | ||
|
||
/// Run all Chopper HTTP requests | ||
Future<void> _runChopperHttpRequests() => Future.wait([ | ||
_albumsRequests(), | ||
_articlesRequests(), | ||
_commentsRequests(), | ||
_photosRequests(), | ||
_todosRequests(), | ||
_usersRequests(), | ||
]); | ||
|
||
void _runHttpInspector() { | ||
_alice.showInspector(); | ||
} | ||
|
Oops, something went wrong.