Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
Restructured
Browse files Browse the repository at this point in the history
  • Loading branch information
thosakwe committed Sep 3, 2016
1 parent 6f7321a commit 09613bb
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 315 deletions.
Binary file added .DS_Store
Binary file not shown.
7 changes: 1 addition & 6 deletions lib/angel_client.dart
Expand Up @@ -2,11 +2,6 @@
library angel_client;

import 'dart:async';
import 'dart:convert' show JSON;
import 'package:http/http.dart';
import 'package:json_god/json_god.dart' as god;

part 'rest.dart';

/// A function that configures an [Angel] client in some way.
typedef Future AngelConfigurer(Angel app);
Expand Down Expand Up @@ -47,4 +42,4 @@ abstract class Service {

/// Removes the given resource.
Future remove(id, [Map params]);
}
}
18 changes: 9 additions & 9 deletions lib/browser.dart
Expand Up @@ -4,7 +4,8 @@ library angel_client.browser;
import 'dart:async';
import 'dart:convert' show JSON;
import 'dart:html';
import 'shared.dart';
import 'angel_client.dart';
export 'angel_client.dart';

_buildQuery(Map params) {
if (params == null || params == {})
Expand All @@ -21,7 +22,7 @@ class Rest extends Angel {
@override
RestService service(String path, {Type type}) {
String uri = path.replaceAll(new RegExp(r"(^\/)|(\/+$)"), "");
return new RestService._base("$basePath/$uri")
return new RestService("$basePath/$uri")
..app = this;
}
}
Expand All @@ -30,15 +31,15 @@ class Rest extends Angel {
class RestService extends Service {
String basePath;

RestService._base(Pattern path) {
RestService(Pattern path) {
this.basePath = (path is RegExp) ? path.pattern : path;
}

_makeBody(data) {
return JSON.encode(data);
}

HttpRequest _buildRequest(String url,
HttpRequest buildRequest(String url,
{String method: "POST", bool write: true}) {
HttpRequest request = new HttpRequest();
request.open(method, url, async: false);
Expand All @@ -63,30 +64,29 @@ class RestService extends Service {

@override
Future create(data, [Map params]) async {
var request = _buildRequest("$basePath/${_buildQuery(params)}");
var request = buildRequest("$basePath/${_buildQuery(params)}");
request.send(_makeBody(data));
return request.response;
}

@override
Future modify(id, data, [Map params]) async {
var request = _buildRequest("$basePath/$id${_buildQuery(params)}", method: "PATCH");
var request = buildRequest("$basePath/$id${_buildQuery(params)}", method: "PATCH");
request.send(_makeBody(data));
return request.response;
}

@override
Future update(id, data, [Map params]) async {
var request = _buildRequest("$basePath/$id${_buildQuery(params)}");
var request = buildRequest("$basePath/$id${_buildQuery(params)}");
request.send(_makeBody(data));
return request.response;
}

@override
Future remove(id, [Map params]) async {
var request = _buildRequest("$basePath/$id${_buildQuery(params)}", method: "DELETE");
var request = buildRequest("$basePath/$id${_buildQuery(params)}", method: "DELETE");
request.send();
return request.response;
}
}

4 changes: 2 additions & 2 deletions lib/cli.dart
Expand Up @@ -5,7 +5,8 @@ import 'dart:async';
import 'dart:convert' show JSON;
import 'package:http/http.dart';
import 'package:json_god/json_god.dart' as god;
import 'shared.dart';
import 'angel_client.dart';
export 'angel_client.dart';

_buildQuery(Map params) {
if (params == null || params == {})
Expand Down Expand Up @@ -107,4 +108,3 @@ class RestService extends Service {
return god.deserialize(response.body, outputType: outputType);
}
}

101 changes: 0 additions & 101 deletions lib/rest.dart

This file was deleted.

44 changes: 0 additions & 44 deletions lib/shared.dart

This file was deleted.

4 changes: 2 additions & 2 deletions 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 <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/angel_client
Expand All @@ -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"
test: ">= 0.12.13 < 0.13.0"
Binary file added test/.DS_Store
Binary file not shown.
11 changes: 6 additions & 5 deletions test/browser.dart
@@ -1,10 +1,11 @@
import 'package:angel_client/shared.dart';
import 'package:angel_client/browser.dart';
import 'package:test/test.dart';

main() async {
Angel app = new Rest("http://localhost:3000");
Service Todos = app.service("todos");
test("list todos", () async {
Angel app = new Rest("http://localhost:3001");
Service Todos = app.service("todos");

print(await Todos.index());
}
print(await Todos.index());
});
}
16 changes: 8 additions & 8 deletions test/cli.dart
@@ -1,5 +1,4 @@
import 'dart:io';
import 'package:angel_client/shared.dart' as clientLib;
import 'package:angel_client/cli.dart' as client;
import 'package:angel_framework/angel_framework.dart' as server;
import 'package:http/http.dart' as http;
Expand All @@ -11,18 +10,19 @@ main() {
group("rest", () {
server.Angel serverApp = new server.Angel();
server.HookedService serverPostcards;
clientLib.Angel clientApp;
clientLib.Service clientPostcards;
clientLib.Service clientTypedPostcards;
client.Angel clientApp;
client.Service clientPostcards;
client.Service clientTypedPostcards;
HttpServer httpServer;
String url;

setUp(() async {
httpServer =
await serverApp.startServer(InternetAddress.LOOPBACK_IP_V4, 3000);
httpServer = await serverApp.startServer(InternetAddress.LOOPBACK_IP_V4, 0);
url = "http://localhost:${httpServer.port}";
serverApp.use("/postcards", new server.MemoryService<Postcard>());
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);
});
Expand Down Expand Up @@ -131,4 +131,4 @@ main() {
expect(removed2, equals(remove2));
});
});
}
}
9 changes: 5 additions & 4 deletions 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();
Expand All @@ -9,12 +10,12 @@ main() async {

app.use("/todos", new MemoryService<Todo>());

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});
}
}

0 comments on commit 09613bb

Please sign in to comment.