This commit is contained in:
thosakwe 2016-12-13 11:35:35 -05:00
parent ec67091b10
commit c700a399e4
10 changed files with 100 additions and 96 deletions

View file

@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["add-module-exports"]
}

50
.gitignore vendored
View file

@ -28,4 +28,52 @@ pubspec.lock
.idea
lib/angel_client.js
*.sum
*.sum
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity

View file

@ -1,79 +1,10 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
# Sensitive or high-churn files:
.idea/dataSources/
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Dart template
# See https://www.dartlang.org/tools/private-files.html
# Files and directories created by pub
# SDK 1.20 and later (no longer creates packages directories)
.packages
.pub/
build/
# Older SDK versions
# (Include if the minimum SDK version specified in pubsepc.yaml is earlier than 1.20)
.project
.buildlog
**/packages/
# Files created by dart2js
# (Most Dart developers will use pub build to compile Dart, use/modify these
# rules if you intend to use dart2js directly
# Convention is to use extension '.dart.js' for Dart compiled to Javascript to
# differentiate from explicit Javascript files)
*.dart.js
*.part.js
*.js.deps
*.js.map
*.info.json
# Directory created by dartdoc
doc/api/
# Don't commit pubspec lock file
# (Library packages only! Remove pattern if developing an application package)
pubspec.lock
.babelrc
.istanbul.yml
.travis.yml
.editorconfig
.idea/
src/
test/
!lib/
.github/
coverage

View file

@ -1,6 +1,6 @@
# angel_client
[![pub 1.0.0-dev+20](https://img.shields.io/badge/pub-1.0.0--dev+20-red.svg)](https://pub.dartlang.org/packages/angel_client)
[![pub 1.0.0-dev+21](https://img.shields.io/badge/pub-1.0.0--dev+21-red.svg)](https://pub.dartlang.org/packages/angel_client)
![build status](https://travis-ci.org/angel-dart/client.svg)
Client library for the Angel framework.

View file

@ -9,6 +9,12 @@ export 'package:angel_framework/src/http/angel_http_exception.dart';
/// A function that configures an [Angel] client in some way.
typedef Future AngelConfigurer(Angel app);
/// A function that deserializes data received from the server.
///
/// This is only really necessary in the browser, where `json_god`
/// doesn't work.
typedef AngelDeserializer(x);
/// Represents an Angel server that we are querying.
abstract class Angel {
String get authToken;
@ -29,7 +35,7 @@ abstract class Angel {
await configurer(this);
}
Service service<T>(String path, {Type type});
Service service<T>(String path, {Type type, AngelDeserializer deserializer});
Future<http.Response> delete(String url,
{Map<String, String> headers});

View file

@ -128,9 +128,10 @@ abstract class BaseAngelClient extends Angel {
}
@override
Service service<T>(String path, {Type type}) {
Service service<T>(String path, {Type type, AngelDeserializer deserializer}) {
String uri = path.toString().replaceAll(straySlashes, "");
return new BaseAngelService(client, this, '$basePath/$uri');
return new BaseAngelService(client, this, '$basePath/$uri',
deserializer: deserializer);
}
String _join(url) {
@ -179,8 +180,13 @@ class BaseAngelService extends Service {
final Angel app;
final String basePath;
final http.BaseClient client;
final AngelDeserializer deserializer;
BaseAngelService(this.client, this.app, this.basePath);
BaseAngelService(this.client, this.app, this.basePath, {this.deserializer});
deserialize(x) {
return deserializer != null ? deserializer(x) : x;
}
makeBody(x) {
return JSON.encode(x);
@ -234,7 +240,7 @@ class BaseAngelService extends Service {
throw failure(response);
}
return json;
return json.map(deserialize).toList();
} catch (e, st) {
throw failure(response, error: e, stack: st);
}
@ -250,7 +256,7 @@ class BaseAngelService extends Service {
throw failure(response);
}
return JSON.decode(response.body);
return deserialize(JSON.decode(response.body));
} catch (e, st) {
throw failure(response, error: e, stack: st);
}
@ -266,7 +272,7 @@ class BaseAngelService extends Service {
throw failure(response);
}
return JSON.decode(response.body);
return deserialize(JSON.decode(response.body));
} catch (e, st) {
throw failure(response, error: e, stack: st);
}
@ -282,7 +288,7 @@ class BaseAngelService extends Service {
throw failure(response);
}
return JSON.decode(response.body);
return deserialize(JSON.decode(response.body));
} catch (e, st) {
throw failure(response, error: e, stack: st);
}
@ -298,7 +304,7 @@ class BaseAngelService extends Service {
throw failure(response);
}
return JSON.decode(response.body);
return deserialize(JSON.decode(response.body));
} catch (e, st) {
throw failure(response, error: e, stack: st);
}
@ -314,7 +320,7 @@ class BaseAngelService extends Service {
throw failure(response);
}
return JSON.decode(response.body);
return deserialize(JSON.decode(response.body));
} catch (e, st) {
throw failure(response, error: e, stack: st);
}

View file

@ -13,7 +13,7 @@ class Rest extends BaseAngelClient {
Rest(String path) : super(new http.Client(), path);
@override
Service service<T>(String path, {Type type}) {
Service service<T>(String path, {Type type, AngelDeserializer deserializer}) {
String uri = path.replaceAll(straySlashes, "");
return new RestService(
client, this, "$basePath/$uri", T != dynamic ? T : type);

View file

@ -2,11 +2,15 @@
"name": "angel_client",
"version": "1.0.0-dev",
"description": "Client library for the Angel framework.",
"main": "lib/angel_client.js",
"main": "build/angel_client.js",
"jsnext:main": "lib/angel_client.js",
"directories": {
"test": "test"
},
"scripts": {
"compile": "npm run dartdevc && babel -o build/angel_client.js lib/angel_client.js",
"dartdevc": "dartdevc --modules node -o lib/angel_client.js lib/angel_client.dart",
"prepublish": "npm run compile",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@ -22,5 +26,10 @@
"bugs": {
"url": "https://github.com/angel-dart/angel_client/issues"
},
"homepage": "https://github.com/angel-dart/angel_client#readme"
"homepage": "https://github.com/angel-dart/angel_client#readme",
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.18.0"
}
}

View file

@ -1,5 +1,5 @@
name: angel_client
version: 1.0.0-dev+20
version: 1.0.0-dev+21
description: Client library for the Angel framework.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_client

View file

@ -23,7 +23,7 @@ main() {
clientApp = new client.Rest(url);
clientPostcards = clientApp.service("postcards");
clientTypedPostcards = clientApp.service<Postcard>("postcards", type: Postcard);
clientTypedPostcards = clientApp.service("postcards", type: Postcard);
});
tearDown(() async {