Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: 2-6-client/lib/client/piratesapi.dart

Issue 1056193003: Rename methods to better match new terminology and get rid of json data file. (Closed) Base URL: https://github.com/dart-lang/one-hour-codelab.git@server2
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « 2-5-generated/lib/server/piratesapi.dart ('k') | 2-6-client/lib/common/messages.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 library server_code_lab.piratesApi.client; 1 library server_code_lab.piratesApi.client;
2 2
3 import 'dart:core' as core; 3 import 'dart:core' as core;
4 import 'dart:collection' as collection; 4 import 'dart:collection' as collection;
5 import 'dart:async' as async; 5 import 'dart:async' as async;
6 import 'dart:convert' as convert; 6 import 'dart:convert' as convert;
7 7
8 import 'package:_discoveryapis_commons/_discoveryapis_commons.dart' 8 import 'package:_discoveryapis_commons/_discoveryapis_commons.dart' as commons;
9 as commons;
10 import 'package:crypto/crypto.dart' as crypto; 9 import 'package:crypto/crypto.dart' as crypto;
11 import 'package:http/http.dart' as http; 10 import 'package:http/http.dart' as http;
12 import 'package:server_code_lab/common/messages.dart'; 11 import 'package:server_code_lab/common/messages.dart';
13 export 'package:_discoveryapis_commons/_discoveryapis_commons.dart' 12 export 'package:_discoveryapis_commons/_discoveryapis_commons.dart' show
14 show ApiRequestError, DetailedApiRequestError; 13 ApiRequestError, DetailedApiRequestError;
15 14
16 const core.String USER_AGENT = 'dart-api-client piratesApi/v1'; 15 const core.String USER_AGENT = 'dart-api-client piratesApi/v1';
17 16
18 class PiratesApi { 17 class PiratesApi {
18
19 final commons.ApiRequester _requester; 19 final commons.ApiRequester _requester;
20 20
21 PiratesApi(http.Client client, 21 PiratesApi(http.Client client, {core.String rootUrl: "http://localhost:9090/", core.String servicePath: "piratesApi/v1/"}) :
22 {core.String rootUrl: "http://localhost:9090/", 22 _requester = new commons.ApiRequester(client, rootUrl, servicePath, USER_A GENT);
23 core.String servicePath: "piratesApi/v1/"})
24 : _requester = new commons.ApiRequester(
25 client, rootUrl, servicePath, USER_AGENT);
26 23
27 /** 24 /**
28 * [request] - The metadata request object. 25 * Request parameters:
29 * 26 *
30 * Request parameters: 27 * [name] - Path parameter: 'name'.
28 *
29 * [appellation] - Path parameter: 'appellation'.
31 * 30 *
32 * Completes with a [Pirate]. 31 * Completes with a [Pirate].
33 * 32 *
34 * Completes with a [commons.ApiRequestError] if the API endpoint returned an 33 * Completes with a [commons.ApiRequestError] if the API endpoint returned an
35 * error. 34 * error.
36 * 35 *
37 * If the used [http.Client] completes with an error when making a REST call, 36 * If the used [http.Client] completes with an error when making a REST call,
38 * this method will complete with the same error. 37 * this method will complete with the same error.
39 */ 38 */
40 async.Future<Pirate> addPirate(Pirate request) { 39 async.Future<Pirate> firePirate(core.String name, core.String appellation) {
41 var _url = null; 40 var _url = null;
42 var _queryParams = new core.Map(); 41 var _queryParams = new core.Map();
43 var _uploadMedia = null; 42 var _uploadMedia = null;
44 var _uploadOptions = null; 43 var _uploadOptions = null;
45 var _downloadOptions = commons.DownloadOptions.Metadata; 44 var _downloadOptions = commons.DownloadOptions.Metadata;
46 var _body = null; 45 var _body = null;
47 46
48 if (request != null) { 47 if (name == null) {
49 _body = convert.JSON.encode(PirateFactory.toJson(request)); 48 throw new core.ArgumentError("Parameter name is required.");
49 }
50 if (appellation == null) {
51 throw new core.ArgumentError("Parameter appellation is required.");
50 } 52 }
51 53
52 _url = 'pirate';
53 54
54 var _response = _requester.request(_url, "POST", 55 _url = 'pirate/' + commons.Escaper.ecapeVariable('$name') + '/the/' + common s.Escaper.ecapeVariable('$appellation');
55 body: _body, 56
56 queryParams: _queryParams, 57 var _response = _requester.request(_url,
57 uploadOptions: _uploadOptions, 58 "DELETE",
58 uploadMedia: _uploadMedia, 59 body: _body,
59 downloadOptions: _downloadOptions); 60 queryParams: _queryParams,
61 uploadOptions: _uploadOptions,
62 uploadMedia: _uploadMedia,
63 downloadOptions: _downloadOptions);
60 return _response.then((data) => PirateFactory.fromJson(data)); 64 return _response.then((data) => PirateFactory.fromJson(data));
61 } 65 }
62 66
63 /** 67 /**
68 * [request] - The metadata request object.
69 *
64 * Request parameters: 70 * Request parameters:
65 * 71 *
66 * [name] - Path parameter: 'name'.
67 *
68 * [appellation] - Path parameter: 'appellation'.
69 *
70 * Completes with a [Pirate]. 72 * Completes with a [Pirate].
71 * 73 *
72 * Completes with a [commons.ApiRequestError] if the API endpoint returned an 74 * Completes with a [commons.ApiRequestError] if the API endpoint returned an
73 * error. 75 * error.
74 * 76 *
75 * If the used [http.Client] completes with an error when making a REST call, 77 * If the used [http.Client] completes with an error when making a REST call,
76 * this method will complete with the same error. 78 * this method will complete with the same error.
77 */ 79 */
78 async.Future<Pirate> killPirate( 80 async.Future<Pirate> hirePirate(Pirate request) {
79 core.String name, core.String appellation) {
80 var _url = null; 81 var _url = null;
81 var _queryParams = new core.Map(); 82 var _queryParams = new core.Map();
82 var _uploadMedia = null; 83 var _uploadMedia = null;
83 var _uploadOptions = null; 84 var _uploadOptions = null;
84 var _downloadOptions = commons.DownloadOptions.Metadata; 85 var _downloadOptions = commons.DownloadOptions.Metadata;
85 var _body = null; 86 var _body = null;
86 87
87 if (name == null) { 88 if (request != null) {
88 throw new core.ArgumentError("Parameter name is required."); 89 _body = convert.JSON.encode(PirateFactory.toJson(request));
89 }
90 if (appellation == null) {
91 throw new core.ArgumentError(
92 "Parameter appellation is required.");
93 } 90 }
94 91
95 _url = 'pirate/' +
96 commons.Escaper.ecapeVariable('$name') +
97 '/the/' +
98 commons.Escaper.ecapeVariable('$appellation');
99 92
100 var _response = _requester.request(_url, "DELETE", 93 _url = 'pirate';
101 body: _body, 94
102 queryParams: _queryParams, 95 var _response = _requester.request(_url,
103 uploadOptions: _uploadOptions, 96 "POST",
104 uploadMedia: _uploadMedia, 97 body: _body,
105 downloadOptions: _downloadOptions); 98 queryParams: _queryParams,
99 uploadOptions: _uploadOptions,
100 uploadMedia: _uploadMedia,
101 downloadOptions: _downloadOptions);
106 return _response.then((data) => PirateFactory.fromJson(data)); 102 return _response.then((data) => PirateFactory.fromJson(data));
107 } 103 }
108 104
109 /** 105 /**
110 * Request parameters: 106 * Request parameters:
111 * 107 *
112 * Completes with a [core.List<Pirate>]. 108 * Completes with a [core.List<Pirate>].
113 * 109 *
114 * Completes with a [commons.ApiRequestError] if the API endpoint returned an 110 * Completes with a [commons.ApiRequestError] if the API endpoint returned an
115 * error. 111 * error.
116 * 112 *
117 * If the used [http.Client] completes with an error when making a REST call, 113 * If the used [http.Client] completes with an error when making a REST call,
118 * this method will complete with the same error. 114 * this method will complete with the same error.
119 */ 115 */
120 async.Future<core.List<Pirate>> listPirates() { 116 async.Future<core.List<Pirate>> listPirates() {
121 var _url = null; 117 var _url = null;
122 var _queryParams = new core.Map(); 118 var _queryParams = new core.Map();
123 var _uploadMedia = null; 119 var _uploadMedia = null;
124 var _uploadOptions = null; 120 var _uploadOptions = null;
125 var _downloadOptions = commons.DownloadOptions.Metadata; 121 var _downloadOptions = commons.DownloadOptions.Metadata;
126 var _body = null; 122 var _body = null;
127 123
124
125
128 _url = 'pirates'; 126 _url = 'pirates';
129 127
130 var _response = _requester.request(_url, "GET", 128 var _response = _requester.request(_url,
131 body: _body, 129 "GET",
132 queryParams: _queryParams, 130 body: _body,
133 uploadOptions: _uploadOptions, 131 queryParams: _queryParams,
134 uploadMedia: _uploadMedia, 132 uploadOptions: _uploadOptions,
135 downloadOptions: _downloadOptions); 133 uploadMedia: _uploadMedia,
136 return _response.then((data) => 134 downloadOptions: _downloadOptions);
137 data.map((value) => PirateFactory.fromJson(value)).toList()); 135 return _response.then((data) => data.map((value) => PirateFactory.fromJson(v alue)).toList());
138 } 136 }
139 137
140 /** 138 /**
141 * Request parameters: 139 * Request parameters:
142 * 140 *
143 * Completes with a [core.Map<core.String, core.List<core.String>>]. 141 * Completes with a [core.Map<core.String, core.List<core.String>>].
144 * 142 *
145 * Completes with a [commons.ApiRequestError] if the API endpoint returned an 143 * Completes with a [commons.ApiRequestError] if the API endpoint returned an
146 * error. 144 * error.
147 * 145 *
148 * If the used [http.Client] completes with an error when making a REST call, 146 * If the used [http.Client] completes with an error when making a REST call,
149 * this method will complete with the same error. 147 * this method will complete with the same error.
150 */ 148 */
151 async.Future<core.Map<core.String, core.List<core.String>>> properPirates() { 149 async.Future<core.Map<core.String, core.List<core.String>>> properPirates() {
152 var _url = null; 150 var _url = null;
153 var _queryParams = new core.Map(); 151 var _queryParams = new core.Map();
154 var _uploadMedia = null; 152 var _uploadMedia = null;
155 var _uploadOptions = null; 153 var _uploadOptions = null;
156 var _downloadOptions = commons.DownloadOptions.Metadata; 154 var _downloadOptions = commons.DownloadOptions.Metadata;
157 var _body = null; 155 var _body = null;
158 156
157
158
159 _url = 'proper/pirates'; 159 _url = 'proper/pirates';
160 160
161 var _response = _requester.request(_url, "GET", 161 var _response = _requester.request(_url,
162 body: _body, 162 "GET",
163 queryParams: _queryParams, 163 body: _body,
164 uploadOptions: _uploadOptions, 164 queryParams: _queryParams,
165 uploadMedia: _uploadMedia, 165 uploadOptions: _uploadOptions,
166 downloadOptions: _downloadOptions); 166 uploadMedia: _uploadMedia,
167 downloadOptions: _downloadOptions);
167 return _response.then((data) => data); 168 return _response.then((data) => data);
168 } 169 }
169 170
170 /** 171 /**
171 * Request parameters: 172 * Request parameters:
172 * 173 *
173 * Completes with a [Pirate]. 174 * Completes with a [Pirate].
174 * 175 *
175 * Completes with a [commons.ApiRequestError] if the API endpoint returned an 176 * Completes with a [commons.ApiRequestError] if the API endpoint returned an
176 * error. 177 * error.
177 * 178 *
178 * If the used [http.Client] completes with an error when making a REST call, 179 * If the used [http.Client] completes with an error when making a REST call,
179 * this method will complete with the same error. 180 * this method will complete with the same error.
180 */ 181 */
181 async.Future<Pirate> shanghaiAPirate() { 182 async.Future<Pirate> shanghaiAPirate() {
182 var _url = null; 183 var _url = null;
183 var _queryParams = new core.Map(); 184 var _queryParams = new core.Map();
184 var _uploadMedia = null; 185 var _uploadMedia = null;
185 var _uploadOptions = null; 186 var _uploadOptions = null;
186 var _downloadOptions = commons.DownloadOptions.Metadata; 187 var _downloadOptions = commons.DownloadOptions.Metadata;
187 var _body = null; 188 var _body = null;
188 189
190
191
189 _url = 'shanghai'; 192 _url = 'shanghai';
190 193
191 var _response = _requester.request(_url, "GET", 194 var _response = _requester.request(_url,
192 body: _body, 195 "GET",
193 queryParams: _queryParams, 196 body: _body,
194 uploadOptions: _uploadOptions, 197 queryParams: _queryParams,
195 uploadMedia: _uploadMedia, 198 uploadOptions: _uploadOptions,
196 downloadOptions: _downloadOptions); 199 uploadMedia: _uploadMedia,
200 downloadOptions: _downloadOptions);
197 return _response.then((data) => PirateFactory.fromJson(data)); 201 return _response.then((data) => PirateFactory.fromJson(data));
198 } 202 }
203
199 } 204 }
200 205
206
207
201 class PirateFactory { 208 class PirateFactory {
202 static Pirate fromJson(core.Map _json) { 209 static Pirate fromJson(core.Map _json) {
203 var message = new Pirate(); 210 var message = new Pirate();
204 if (_json.containsKey("appellation")) { 211 if (_json.containsKey("appellation")) {
205 message.appellation = _json["appellation"]; 212 message.appellation = _json["appellation"];
206 } 213 }
207 if (_json.containsKey("name")) { 214 if (_json.containsKey("name")) {
208 message.name = _json["name"]; 215 message.name = _json["name"];
209 } 216 }
210 return message; 217 return message;
211 } 218 }
212 219
213 static core.Map toJson(Pirate message) { 220 static core.Map toJson(Pirate message) {
214 var _json = new core.Map(); 221 var _json = new core.Map();
215 if (message.appellation != null) { 222 if (message.appellation != null) {
216 _json["appellation"] = message.appellation; 223 _json["appellation"] = message.appellation;
217 } 224 }
218 if (message.name != null) { 225 if (message.name != null) {
219 _json["name"] = message.name; 226 _json["name"] = message.name;
220 } 227 }
221 return _json; 228 return _json;
222 } 229 }
223 } 230 }
231
232
OLDNEW
« no previous file with comments | « 2-5-generated/lib/server/piratesapi.dart ('k') | 2-6-client/lib/common/messages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698