Index: 2-7-serve/lib/client/piratesapi.dart |
diff --git a/2-7-serve/lib/client/piratesapi.dart b/2-7-serve/lib/client/piratesapi.dart |
index 789f1fadf8f84813156101952a1bdfdc284d24f3..10a88adf811aa259299b00c2745687738714fdda 100644 |
--- a/2-7-serve/lib/client/piratesapi.dart |
+++ b/2-7-serve/lib/client/piratesapi.dart |
@@ -5,30 +5,29 @@ import 'dart:collection' as collection; |
import 'dart:async' as async; |
import 'dart:convert' as convert; |
-import 'package:_discoveryapis_commons/_discoveryapis_commons.dart' |
- as commons; |
+import 'package:_discoveryapis_commons/_discoveryapis_commons.dart' as commons; |
import 'package:crypto/crypto.dart' as crypto; |
import 'package:http/http.dart' as http; |
import 'package:server_code_lab/common/messages.dart'; |
-export 'package:_discoveryapis_commons/_discoveryapis_commons.dart' |
- show ApiRequestError, DetailedApiRequestError; |
+export 'package:_discoveryapis_commons/_discoveryapis_commons.dart' show |
+ ApiRequestError, DetailedApiRequestError; |
const core.String USER_AGENT = 'dart-api-client piratesApi/v1'; |
class PiratesApi { |
+ |
final commons.ApiRequester _requester; |
- PiratesApi(http.Client client, |
- {core.String rootUrl: "http://localhost:9090/", |
- core.String servicePath: "piratesApi/v1/"}) |
- : _requester = new commons.ApiRequester( |
- client, rootUrl, servicePath, USER_AGENT); |
+ PiratesApi(http.Client client, {core.String rootUrl: "http://localhost:9090/", core.String servicePath: "piratesApi/v1/"}) : |
+ _requester = new commons.ApiRequester(client, rootUrl, servicePath, USER_AGENT); |
/** |
- * [request] - The metadata request object. |
- * |
* Request parameters: |
* |
+ * [name] - Path parameter: 'name'. |
+ * |
+ * [appellation] - Path parameter: 'appellation'. |
+ * |
* Completes with a [Pirate]. |
* |
* Completes with a [commons.ApiRequestError] if the API endpoint returned an |
@@ -37,7 +36,7 @@ class PiratesApi { |
* If the used [http.Client] completes with an error when making a REST call, |
* this method will complete with the same error. |
*/ |
- async.Future<Pirate> addPirate(Pirate request) { |
+ async.Future<Pirate> firePirate(core.String name, core.String appellation) { |
var _url = null; |
var _queryParams = new core.Map(); |
var _uploadMedia = null; |
@@ -45,27 +44,30 @@ class PiratesApi { |
var _downloadOptions = commons.DownloadOptions.Metadata; |
var _body = null; |
- if (request != null) { |
- _body = convert.JSON.encode(PirateFactory.toJson(request)); |
+ if (name == null) { |
+ throw new core.ArgumentError("Parameter name is required."); |
+ } |
+ if (appellation == null) { |
+ throw new core.ArgumentError("Parameter appellation is required."); |
} |
- _url = 'pirate'; |
- var _response = _requester.request(_url, "POST", |
- body: _body, |
- queryParams: _queryParams, |
- uploadOptions: _uploadOptions, |
- uploadMedia: _uploadMedia, |
- downloadOptions: _downloadOptions); |
+ _url = 'pirate/' + commons.Escaper.ecapeVariable('$name') + '/the/' + commons.Escaper.ecapeVariable('$appellation'); |
+ |
+ var _response = _requester.request(_url, |
+ "DELETE", |
+ body: _body, |
+ queryParams: _queryParams, |
+ uploadOptions: _uploadOptions, |
+ uploadMedia: _uploadMedia, |
+ downloadOptions: _downloadOptions); |
return _response.then((data) => PirateFactory.fromJson(data)); |
} |
/** |
- * Request parameters: |
- * |
- * [name] - Path parameter: 'name'. |
+ * [request] - The metadata request object. |
* |
- * [appellation] - Path parameter: 'appellation'. |
+ * Request parameters: |
* |
* Completes with a [Pirate]. |
* |
@@ -75,8 +77,7 @@ class PiratesApi { |
* If the used [http.Client] completes with an error when making a REST call, |
* this method will complete with the same error. |
*/ |
- async.Future<Pirate> killPirate( |
- core.String name, core.String appellation) { |
+ async.Future<Pirate> hirePirate(Pirate request) { |
var _url = null; |
var _queryParams = new core.Map(); |
var _uploadMedia = null; |
@@ -84,25 +85,20 @@ class PiratesApi { |
var _downloadOptions = commons.DownloadOptions.Metadata; |
var _body = null; |
- if (name == null) { |
- throw new core.ArgumentError("Parameter name is required."); |
- } |
- if (appellation == null) { |
- throw new core.ArgumentError( |
- "Parameter appellation is required."); |
+ if (request != null) { |
+ _body = convert.JSON.encode(PirateFactory.toJson(request)); |
} |
- _url = 'pirate/' + |
- commons.Escaper.ecapeVariable('$name') + |
- '/the/' + |
- commons.Escaper.ecapeVariable('$appellation'); |
- |
- var _response = _requester.request(_url, "DELETE", |
- body: _body, |
- queryParams: _queryParams, |
- uploadOptions: _uploadOptions, |
- uploadMedia: _uploadMedia, |
- downloadOptions: _downloadOptions); |
+ |
+ _url = 'pirate'; |
+ |
+ var _response = _requester.request(_url, |
+ "POST", |
+ body: _body, |
+ queryParams: _queryParams, |
+ uploadOptions: _uploadOptions, |
+ uploadMedia: _uploadMedia, |
+ downloadOptions: _downloadOptions); |
return _response.then((data) => PirateFactory.fromJson(data)); |
} |
@@ -125,16 +121,18 @@ class PiratesApi { |
var _downloadOptions = commons.DownloadOptions.Metadata; |
var _body = null; |
+ |
+ |
_url = 'pirates'; |
- var _response = _requester.request(_url, "GET", |
- body: _body, |
- queryParams: _queryParams, |
- uploadOptions: _uploadOptions, |
- uploadMedia: _uploadMedia, |
- downloadOptions: _downloadOptions); |
- return _response.then((data) => |
- data.map((value) => PirateFactory.fromJson(value)).toList()); |
+ var _response = _requester.request(_url, |
+ "GET", |
+ body: _body, |
+ queryParams: _queryParams, |
+ uploadOptions: _uploadOptions, |
+ uploadMedia: _uploadMedia, |
+ downloadOptions: _downloadOptions); |
+ return _response.then((data) => data.map((value) => PirateFactory.fromJson(value)).toList()); |
} |
/** |
@@ -156,14 +154,17 @@ class PiratesApi { |
var _downloadOptions = commons.DownloadOptions.Metadata; |
var _body = null; |
+ |
+ |
_url = 'proper/pirates'; |
- var _response = _requester.request(_url, "GET", |
- body: _body, |
- queryParams: _queryParams, |
- uploadOptions: _uploadOptions, |
- uploadMedia: _uploadMedia, |
- downloadOptions: _downloadOptions); |
+ var _response = _requester.request(_url, |
+ "GET", |
+ body: _body, |
+ queryParams: _queryParams, |
+ uploadOptions: _uploadOptions, |
+ uploadMedia: _uploadMedia, |
+ downloadOptions: _downloadOptions); |
return _response.then((data) => data); |
} |
@@ -186,18 +187,24 @@ class PiratesApi { |
var _downloadOptions = commons.DownloadOptions.Metadata; |
var _body = null; |
+ |
+ |
_url = 'shanghai'; |
- var _response = _requester.request(_url, "GET", |
- body: _body, |
- queryParams: _queryParams, |
- uploadOptions: _uploadOptions, |
- uploadMedia: _uploadMedia, |
- downloadOptions: _downloadOptions); |
+ var _response = _requester.request(_url, |
+ "GET", |
+ body: _body, |
+ queryParams: _queryParams, |
+ uploadOptions: _uploadOptions, |
+ uploadMedia: _uploadMedia, |
+ downloadOptions: _downloadOptions); |
return _response.then((data) => PirateFactory.fromJson(data)); |
} |
+ |
} |
+ |
+ |
class PirateFactory { |
static Pirate fromJson(core.Map _json) { |
var message = new Pirate(); |
@@ -221,3 +228,5 @@ class PirateFactory { |
return _json; |
} |
} |
+ |
+ |