From 09613bbfa31a15dc9715127ee1267ba491e951b0 Mon Sep 17 00:00:00 2001 From: thosakwe Date: Sat, 3 Sep 2016 08:02:32 -0400 Subject: [PATCH] Restructured --- .DS_Store | Bin 0 -> 6148 bytes lib/angel_client.dart | 7 +- lib/browser.dart | 18 ++--- lib/cli.dart | 4 +- lib/rest.dart | 101 --------------------------- lib/shared.dart | 44 ------------ pubspec.yaml | 4 +- test/.DS_Store | Bin 0 -> 6148 bytes test/browser.dart | 11 +-- test/cli.dart | 16 ++--- test/for_browser_tests.dart | 9 +-- test/rest.dart | 133 ------------------------------------ test/shared.dart | 2 +- 13 files changed, 34 insertions(+), 315 deletions(-) create mode 100644 .DS_Store delete mode 100644 lib/rest.dart delete mode 100644 lib/shared.dart create mode 100644 test/.DS_Store delete mode 100644 test/rest.dart diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a2eb533abf551d042629249e6fe5fb378b3b5ee0 GIT binary patch literal 6148 zcmeH~u?oUK42Bc!Ah>jNyu}Cb4Gz&K=nFU~E>c0O^F6wMazU^xC+1b{XuyJ79K1T}(S!u1*@b}wNMJ-@TJzTK|1JE}{6A`8N&+PC zX9Tp_belC^D(=>|*R%RAs index([Map params]) async { - var response = await client.get( - "$basePath/${_buildQuery(params)}", headers: _readHeaders); - - if (outputType == null) - return god.deserialize(response.body); - - else { - return JSON.decode(response.body).map((x) => - god.deserializeDatum(x, outputType: outputType)).toList(); - } - } - - @override - Future read(id, [Map params]) async { - var response = await client.get( - "$basePath/$id${_buildQuery(params)}", headers: _readHeaders); - return god.deserialize(response.body, outputType: outputType); - } - - @override - Future create(data, [Map params]) async { - var response = await client.post( - "$basePath/${_buildQuery(params)}", body: _makeBody(data), - headers: _writeHeaders); - return god.deserialize(response.body, outputType: outputType); - } - - @override - Future modify(id, data, [Map params]) async { - var response = await client.patch( - "$basePath/$id${_buildQuery(params)}", body: _makeBody(data), - headers: _writeHeaders); - return god.deserialize(response.body, outputType: outputType); - } - - @override - Future update(id, data, [Map params]) async { - var response = await client.patch( - "$basePath/$id${_buildQuery(params)}", body: _makeBody(data), - headers: _writeHeaders); - return god.deserialize(response.body, outputType: outputType); - } - - @override - Future remove(id, [Map params]) async { - var response = await client.delete( - "$basePath/$id${_buildQuery(params)}", headers: _readHeaders); - return god.deserialize(response.body, outputType: outputType); - } -} diff --git a/lib/shared.dart b/lib/shared.dart deleted file mode 100644 index 654b3167..00000000 --- a/lib/shared.dart +++ /dev/null @@ -1,44 +0,0 @@ -import 'dart:async'; - -/// A function that configures an [Angel] client in some way. -typedef Future AngelConfigurer(Angel app); - -/// Represents an Angel server that we are querying. -abstract class Angel { - /// The URL of the server. - String basePath; - - Angel(String this.basePath); - - /// Applies an [AngelConfigurer] to this instance. - Future configure(AngelConfigurer configurer) async { - await configurer(this); - } - - /// Returns a representation of a service on the server. - Service service(Pattern path, {Type type}); -} - -/// Queries a service on an Angel server, with the same API. -abstract class Service { - /// The Angel instance powering this service. - Angel app; - - /// Retrieves all resources. - Future index([Map params]); - - /// Retrieves the desired resource. - Future read(id, [Map params]); - - /// Creates a resource. - Future create(data, [Map params]); - - /// Modifies a resource. - Future modify(id, data, [Map params]); - - /// Overwrites a resource. - Future update(id, data, [Map params]); - - /// Removes the given resource. - Future remove(id, [Map params]); -} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 61969cd9..a51c40b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_client -version: 1.0.0-dev+1 +version: 1.0.0-dev+6 description: Client library for the Angel framework. author: Tobe O homepage: https://github.com/angel-dart/angel_client @@ -9,4 +9,4 @@ dependencies: merge_map: ">=1.0.0 <2.0.0" dev_dependencies: angel_framework: ">=1.0.0-dev <2.0.0" - test: ">= 0.12.13 < 0.13.0" \ No newline at end of file + test: ">= 0.12.13 < 0.13.0" diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f17ada42b9498f0bc5247e6446dd56a64a31694e GIT binary patch literal 6148 zcmeHKOHRW;41F#YDwIW6h-H>tA#sDKDoAYM0EK>_h(J+N1j`(QLva9ZQ=Vt6s!f_L zs*o+&Z!)pRGjB$527nCSrx!pEK!>W>I-=Pj`d+mrE$cZXN*JTS3^~p*#eL1&JNA(Q z-MbTvxoZo2U~~U+EU&Z0WSlL=^w9(IP3^COu%(A$f(%c#-!*@^sraAbfmw2lD)~lO z^4t`(MdMgMm9dVQ_m$^thEK-K8T*2)GT$qWp~`AStMh&1xt!pc_E9tL@c-IaUzhWl z(>JH@v}tC6mCdM-%8fJN3^)UO%>Zk*N~asqtux>ZI0I`2^!t!d6;s19V)%5>gew5C z&F&y<>#w55B!;PB8If-&5<`hGRP2f&F`WI0`K5+s#25~-%ZFHIu^Wnn>>NJ{?vOO1 zTW7!-*k<4$KK8W!UpC+Ww}br28E^*v6$8>9-VO&`lGWDQ;()); serverPostcards = serverApp.service("postcards"); - clientApp = new client.Rest("http://localhost:3000", new http.Client()); + clientApp = new client.Rest(url, new http.Client()); clientPostcards = clientApp.service("postcards"); clientTypedPostcards = clientApp.service("postcards", type: Postcard); }); @@ -131,4 +131,4 @@ main() { expect(removed2, equals(remove2)); }); }); -} \ No newline at end of file +} diff --git a/test/for_browser_tests.dart b/test/for_browser_tests.dart index ea5253cc..072f1d52 100644 --- a/test/for_browser_tests.dart +++ b/test/for_browser_tests.dart @@ -1,5 +1,6 @@ import 'dart:io'; -import 'package:angel_framework/angel_framework.dart'; +import "package:angel_framework/angel_framework.dart"; +import "package:angel_framework/defs.dart"; main() async { Angel app = new Angel(); @@ -9,12 +10,12 @@ main() async { app.use("/todos", new MemoryService()); - await app.startServer(InternetAddress.LOOPBACK_IP_V4, 3000); - print("Server up on localhost:3000"); + await app.startServer(InternetAddress.LOOPBACK_IP_V4, 3001); + print("Server up on localhost:3001"); } class Todo extends MemoryModel { String hello; Todo({String this.hello}); -} \ No newline at end of file +} diff --git a/test/rest.dart b/test/rest.dart deleted file mode 100644 index 0bcdb6b8..00000000 --- a/test/rest.dart +++ /dev/null @@ -1,133 +0,0 @@ -import 'dart:io'; -import 'package:angel_client/angel_client.dart' as client; -import 'package:angel_framework/angel_framework.dart' as server; -import 'package:http/http.dart' as http; -import 'package:json_god/json_god.dart' as god; -import 'package:test/test.dart'; -import 'shared.dart'; - -main() { - group("rest", () { - server.Angel serverApp = new server.Angel(); - server.HookedService serverPostcards; - client.Angel clientApp; - client.Service clientPostcards; - client.Service clientTypedPostcards; - HttpServer httpServer; - - setUp(() async { - httpServer = - await serverApp.startServer(InternetAddress.LOOPBACK_IP_V4, 3000); - serverApp.use("/postcards", new server.MemoryService()); - serverPostcards = serverApp.service("postcards"); - - clientApp = new client.Rest("http://localhost:3000", new http.Client()); - clientPostcards = clientApp.service("postcards"); - clientTypedPostcards = clientApp.service("postcards", type: Postcard); - }); - - tearDown(() async { - await httpServer.close(force: true); - }); - - test("index", () async { - Postcard niagaraFalls = await serverPostcards.create( - new Postcard(location: "Niagara Falls", message: "Missing you!")); - List indexed = await clientPostcards.index(); - print(indexed); - - expect(indexed.length, equals(1)); - expect(indexed[0].keys.length, equals(3)); - expect(indexed[0]['id'], equals(niagaraFalls.id)); - expect(indexed[0]['location'], equals(niagaraFalls.location)); - expect(indexed[0]['message'], equals(niagaraFalls.message)); - - Postcard louvre = await serverPostcards.create(new Postcard( - location: "The Louvre", message: "The Mona Lisa was watching me!")); - print(god.serialize(louvre)); - List typedIndexed = await clientTypedPostcards.index(); - expect(typedIndexed.length, equals(2)); - expect(typedIndexed[1], equals(louvre)); - }); - - test("create/read", () async { - Map opry = {"location": "Grand Ole Opry", "message": "Yeehaw!"}; - var created = await clientPostcards.create(opry); - print(created); - - expect(created['id'] == null, equals(false)); - expect(created["location"], equals(opry["location"])); - expect(created["message"], equals(opry["message"])); - - var read = await clientPostcards.read(created['id']); - print(read); - expect(read['id'], equals(created['id'])); - expect(read['location'], equals(created['location'])); - expect(read['message'], equals(created['message'])); - - Postcard canyon = new Postcard(location: "Grand Canyon", - message: "But did you REALLY experience it???"); - created = await clientTypedPostcards.create(canyon); - print(god.serialize(created)); - - expect(created.location, equals(canyon.location)); - expect(created.message, equals(canyon.message)); - - read = await clientTypedPostcards.read(created.id); - print(god.serialize(read)); - expect(read.id, equals(created.id)); - expect(read.location, equals(created.location)); - expect(read.message, equals(created.message)); - }); - - test("modify/update", () async { - server.MemoryService innerPostcards = serverPostcards.inner; - print(innerPostcards.items); - Postcard mecca = await clientTypedPostcards.create( - new Postcard(location: "Mecca", message: "Pilgrimage")); - print(god.serialize(mecca)); - - // I'm too lazy to write the tests twice, because I know it works - // So I'll modify using the type-based client, and update using the - // map-based one - - print("Postcards on server: " + - god.serialize(await serverPostcards.index())); - print("Postcards on client: " + - god.serialize(await clientPostcards.index())); - - Postcard modified = await clientTypedPostcards.modify( - mecca.id, {"location": "Saudi Arabia"}); - print(god.serialize(modified)); - expect(modified.id, equals(mecca.id)); - expect(modified.location, equals("Saudi Arabia")); - expect(modified.message, equals(mecca.message)); - - Map updated = await clientPostcards.update( - mecca.id, {"location": "Full", "message": "Overwrite"}); - print(updated); - - expect(updated.keys.length, equals(3)); - expect(updated['id'], equals(mecca.id)); - expect(updated['location'], equals("Full")); - expect(updated['message'], equals("Overwrite")); - }); - - test("remove", () async { - Postcard remove1 = await clientTypedPostcards.create( - {"location": "remove", "message": "#1"}); - Postcard remove2 = await clientTypedPostcards.create( - {"location": "remove", "message": "#2"}); - print(god.serialize([remove1, remove2])); - - Map removed1 = await clientPostcards.remove(remove1.id); - expect(removed1.keys.length, equals(3)); - expect(removed1['id'], equals(remove1.id)); - expect(removed1['location'], equals(remove1.location)); - expect(removed1['message'], equals(remove1.message)); - - Postcard removed2 = await clientTypedPostcards.remove(remove2.id); - expect(removed2, equals(remove2)); - }); - }); -} \ No newline at end of file diff --git a/test/shared.dart b/test/shared.dart index 4b6621a0..a7f4e662 100644 --- a/test/shared.dart +++ b/test/shared.dart @@ -1,4 +1,4 @@ -import 'package:angel_framework/angel_framework.dart'; +import "package:angel_framework/defs.dart"; class Postcard extends MemoryModel { int id;