OLD | NEW |
(Empty) | |
| 1 library googleapis.urlshortener.v1; |
| 2 |
| 3 import "dart:core" as core; |
| 4 import "dart:collection" as collection; |
| 5 import "dart:async" as async; |
| 6 import "dart:convert" as convert; |
| 7 |
| 8 import "package:crypto/crypto.dart" as crypto; |
| 9 import 'package:http/http.dart' as http; |
| 10 import '../src/common_internal.dart' as common_internal; |
| 11 import '../common/common.dart' as common; |
| 12 |
| 13 export '../common/common.dart' show ApiRequestError; |
| 14 export '../common/common.dart' show DetailedApiRequestError; |
| 15 |
| 16 /** Lets you create, inspect, and manage goo.gl short URLs */ |
| 17 class UrlshortenerApi { |
| 18 /** Manage your goo.gl short URLs */ |
| 19 static const UrlshortenerScope = "https://www.googleapis.com/auth/urlshortener
"; |
| 20 |
| 21 |
| 22 final common_internal.ApiRequester _requester; |
| 23 |
| 24 UrlResourceApi get url => new UrlResourceApi(_requester); |
| 25 |
| 26 UrlshortenerApi(http.Client client) : |
| 27 _requester = new common_internal.ApiRequester(client, "https://www.googlea
pis.com/", "/urlshortener/v1/"); |
| 28 } |
| 29 |
| 30 |
| 31 /** Not documented yet. */ |
| 32 class UrlResourceApi { |
| 33 final common_internal.ApiRequester _requester; |
| 34 |
| 35 UrlResourceApi(common_internal.ApiRequester client) : |
| 36 _requester = client; |
| 37 |
| 38 /** |
| 39 * Expands a short URL or gets creation time and analytics. |
| 40 * |
| 41 * Request parameters: |
| 42 * |
| 43 * [shortUrl] - The short URL, including the protocol. |
| 44 * |
| 45 * [projection] - Additional information to return. |
| 46 * Possible string values are: |
| 47 * - "ANALYTICS_CLICKS" : Returns only click counts. |
| 48 * - "ANALYTICS_TOP_STRINGS" : Returns only top string counts. |
| 49 * - "FULL" : Returns the creation timestamp and all available analytics. |
| 50 * |
| 51 * Completes with a [Url]. |
| 52 * |
| 53 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 54 * error. |
| 55 * |
| 56 * If the used [http.Client] completes with an error when making a REST call, |
| 57 * this method will complete with the same error. |
| 58 */ |
| 59 async.Future<Url> get(core.String shortUrl, {core.String projection}) { |
| 60 var _url = null; |
| 61 var _queryParams = new core.Map(); |
| 62 var _uploadMedia = null; |
| 63 var _uploadOptions = null; |
| 64 var _downloadOptions = common.DownloadOptions.Metadata; |
| 65 var _body = null; |
| 66 |
| 67 if (shortUrl == null) { |
| 68 throw new core.ArgumentError("Parameter shortUrl is required."); |
| 69 } |
| 70 _queryParams["shortUrl"] = [shortUrl]; |
| 71 if (projection != null) { |
| 72 _queryParams["projection"] = [projection]; |
| 73 } |
| 74 |
| 75 |
| 76 _url = 'url'; |
| 77 |
| 78 var _response = _requester.request(_url, |
| 79 "GET", |
| 80 body: _body, |
| 81 queryParams: _queryParams, |
| 82 uploadOptions: _uploadOptions, |
| 83 uploadMedia: _uploadMedia, |
| 84 downloadOptions: _downloadOptions); |
| 85 return _response.then((data) => new Url.fromJson(data)); |
| 86 } |
| 87 |
| 88 /** |
| 89 * Creates a new short URL. |
| 90 * |
| 91 * [request] - The metadata request object. |
| 92 * |
| 93 * Request parameters: |
| 94 * |
| 95 * Completes with a [Url]. |
| 96 * |
| 97 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 98 * error. |
| 99 * |
| 100 * If the used [http.Client] completes with an error when making a REST call, |
| 101 * this method will complete with the same error. |
| 102 */ |
| 103 async.Future<Url> insert(Url request) { |
| 104 var _url = null; |
| 105 var _queryParams = new core.Map(); |
| 106 var _uploadMedia = null; |
| 107 var _uploadOptions = null; |
| 108 var _downloadOptions = common.DownloadOptions.Metadata; |
| 109 var _body = null; |
| 110 |
| 111 if (request != null) { |
| 112 _body = convert.JSON.encode((request).toJson()); |
| 113 } |
| 114 |
| 115 |
| 116 _url = 'url'; |
| 117 |
| 118 var _response = _requester.request(_url, |
| 119 "POST", |
| 120 body: _body, |
| 121 queryParams: _queryParams, |
| 122 uploadOptions: _uploadOptions, |
| 123 uploadMedia: _uploadMedia, |
| 124 downloadOptions: _downloadOptions); |
| 125 return _response.then((data) => new Url.fromJson(data)); |
| 126 } |
| 127 |
| 128 /** |
| 129 * Retrieves a list of URLs shortened by a user. |
| 130 * |
| 131 * Request parameters: |
| 132 * |
| 133 * [projection] - Additional information to return. |
| 134 * Possible string values are: |
| 135 * - "ANALYTICS_CLICKS" : Returns short URL click counts. |
| 136 * - "FULL" : Returns short URL click counts. |
| 137 * |
| 138 * [start_token] - Token for requesting successive pages of results. |
| 139 * |
| 140 * Completes with a [UrlHistory]. |
| 141 * |
| 142 * Completes with a [common.ApiRequestError] if the API endpoint returned an |
| 143 * error. |
| 144 * |
| 145 * If the used [http.Client] completes with an error when making a REST call, |
| 146 * this method will complete with the same error. |
| 147 */ |
| 148 async.Future<UrlHistory> list({core.String projection, core.String start_token
}) { |
| 149 var _url = null; |
| 150 var _queryParams = new core.Map(); |
| 151 var _uploadMedia = null; |
| 152 var _uploadOptions = null; |
| 153 var _downloadOptions = common.DownloadOptions.Metadata; |
| 154 var _body = null; |
| 155 |
| 156 if (projection != null) { |
| 157 _queryParams["projection"] = [projection]; |
| 158 } |
| 159 if (start_token != null) { |
| 160 _queryParams["start-token"] = [start_token]; |
| 161 } |
| 162 |
| 163 |
| 164 _url = 'url/history'; |
| 165 |
| 166 var _response = _requester.request(_url, |
| 167 "GET", |
| 168 body: _body, |
| 169 queryParams: _queryParams, |
| 170 uploadOptions: _uploadOptions, |
| 171 uploadMedia: _uploadMedia, |
| 172 downloadOptions: _downloadOptions); |
| 173 return _response.then((data) => new UrlHistory.fromJson(data)); |
| 174 } |
| 175 |
| 176 } |
| 177 |
| 178 |
| 179 |
| 180 /** Not documented yet. */ |
| 181 class AnalyticsSnapshot { |
| 182 /** |
| 183 * Top browsers, e.g. "Chrome"; sorted by (descending) click counts. Only |
| 184 * present if this data is available. |
| 185 */ |
| 186 core.List<StringCount> browsers; |
| 187 |
| 188 /** |
| 189 * Top countries (expressed as country codes), e.g. "US" or "DE"; sorted by |
| 190 * (descending) click counts. Only present if this data is available. |
| 191 */ |
| 192 core.List<StringCount> countries; |
| 193 |
| 194 /** Number of clicks on all goo.gl short URLs pointing to this long URL. */ |
| 195 core.String longUrlClicks; |
| 196 |
| 197 /** |
| 198 * Top platforms or OSes, e.g. "Windows"; sorted by (descending) click counts. |
| 199 * Only present if this data is available. |
| 200 */ |
| 201 core.List<StringCount> platforms; |
| 202 |
| 203 /** |
| 204 * Top referring hosts, e.g. "www.google.com"; sorted by (descending) click |
| 205 * counts. Only present if this data is available. |
| 206 */ |
| 207 core.List<StringCount> referrers; |
| 208 |
| 209 /** Number of clicks on this short URL. */ |
| 210 core.String shortUrlClicks; |
| 211 |
| 212 |
| 213 AnalyticsSnapshot(); |
| 214 |
| 215 AnalyticsSnapshot.fromJson(core.Map _json) { |
| 216 if (_json.containsKey("browsers")) { |
| 217 browsers = _json["browsers"].map((value) => new StringCount.fromJson(value
)).toList(); |
| 218 } |
| 219 if (_json.containsKey("countries")) { |
| 220 countries = _json["countries"].map((value) => new StringCount.fromJson(val
ue)).toList(); |
| 221 } |
| 222 if (_json.containsKey("longUrlClicks")) { |
| 223 longUrlClicks = _json["longUrlClicks"]; |
| 224 } |
| 225 if (_json.containsKey("platforms")) { |
| 226 platforms = _json["platforms"].map((value) => new StringCount.fromJson(val
ue)).toList(); |
| 227 } |
| 228 if (_json.containsKey("referrers")) { |
| 229 referrers = _json["referrers"].map((value) => new StringCount.fromJson(val
ue)).toList(); |
| 230 } |
| 231 if (_json.containsKey("shortUrlClicks")) { |
| 232 shortUrlClicks = _json["shortUrlClicks"]; |
| 233 } |
| 234 } |
| 235 |
| 236 core.Map toJson() { |
| 237 var _json = new core.Map(); |
| 238 if (browsers != null) { |
| 239 _json["browsers"] = browsers.map((value) => (value).toJson()).toList(); |
| 240 } |
| 241 if (countries != null) { |
| 242 _json["countries"] = countries.map((value) => (value).toJson()).toList(); |
| 243 } |
| 244 if (longUrlClicks != null) { |
| 245 _json["longUrlClicks"] = longUrlClicks; |
| 246 } |
| 247 if (platforms != null) { |
| 248 _json["platforms"] = platforms.map((value) => (value).toJson()).toList(); |
| 249 } |
| 250 if (referrers != null) { |
| 251 _json["referrers"] = referrers.map((value) => (value).toJson()).toList(); |
| 252 } |
| 253 if (shortUrlClicks != null) { |
| 254 _json["shortUrlClicks"] = shortUrlClicks; |
| 255 } |
| 256 return _json; |
| 257 } |
| 258 } |
| 259 |
| 260 |
| 261 /** Not documented yet. */ |
| 262 class AnalyticsSummary { |
| 263 /** Click analytics over all time. */ |
| 264 AnalyticsSnapshot allTime; |
| 265 |
| 266 /** Click analytics over the last day. */ |
| 267 AnalyticsSnapshot day; |
| 268 |
| 269 /** Click analytics over the last month. */ |
| 270 AnalyticsSnapshot month; |
| 271 |
| 272 /** Click analytics over the last two hours. */ |
| 273 AnalyticsSnapshot twoHours; |
| 274 |
| 275 /** Click analytics over the last week. */ |
| 276 AnalyticsSnapshot week; |
| 277 |
| 278 |
| 279 AnalyticsSummary(); |
| 280 |
| 281 AnalyticsSummary.fromJson(core.Map _json) { |
| 282 if (_json.containsKey("allTime")) { |
| 283 allTime = new AnalyticsSnapshot.fromJson(_json["allTime"]); |
| 284 } |
| 285 if (_json.containsKey("day")) { |
| 286 day = new AnalyticsSnapshot.fromJson(_json["day"]); |
| 287 } |
| 288 if (_json.containsKey("month")) { |
| 289 month = new AnalyticsSnapshot.fromJson(_json["month"]); |
| 290 } |
| 291 if (_json.containsKey("twoHours")) { |
| 292 twoHours = new AnalyticsSnapshot.fromJson(_json["twoHours"]); |
| 293 } |
| 294 if (_json.containsKey("week")) { |
| 295 week = new AnalyticsSnapshot.fromJson(_json["week"]); |
| 296 } |
| 297 } |
| 298 |
| 299 core.Map toJson() { |
| 300 var _json = new core.Map(); |
| 301 if (allTime != null) { |
| 302 _json["allTime"] = (allTime).toJson(); |
| 303 } |
| 304 if (day != null) { |
| 305 _json["day"] = (day).toJson(); |
| 306 } |
| 307 if (month != null) { |
| 308 _json["month"] = (month).toJson(); |
| 309 } |
| 310 if (twoHours != null) { |
| 311 _json["twoHours"] = (twoHours).toJson(); |
| 312 } |
| 313 if (week != null) { |
| 314 _json["week"] = (week).toJson(); |
| 315 } |
| 316 return _json; |
| 317 } |
| 318 } |
| 319 |
| 320 |
| 321 /** Not documented yet. */ |
| 322 class StringCount { |
| 323 /** |
| 324 * Number of clicks for this top entry, e.g. for this particular country or |
| 325 * browser. |
| 326 */ |
| 327 core.String count; |
| 328 |
| 329 /** Label assigned to this top entry, e.g. "US" or "Chrome". */ |
| 330 core.String id; |
| 331 |
| 332 |
| 333 StringCount(); |
| 334 |
| 335 StringCount.fromJson(core.Map _json) { |
| 336 if (_json.containsKey("count")) { |
| 337 count = _json["count"]; |
| 338 } |
| 339 if (_json.containsKey("id")) { |
| 340 id = _json["id"]; |
| 341 } |
| 342 } |
| 343 |
| 344 core.Map toJson() { |
| 345 var _json = new core.Map(); |
| 346 if (count != null) { |
| 347 _json["count"] = count; |
| 348 } |
| 349 if (id != null) { |
| 350 _json["id"] = id; |
| 351 } |
| 352 return _json; |
| 353 } |
| 354 } |
| 355 |
| 356 |
| 357 /** Not documented yet. */ |
| 358 class Url { |
| 359 /** |
| 360 * A summary of the click analytics for the short and long URL. Might not be |
| 361 * present if not requested or currently unavailable. |
| 362 */ |
| 363 AnalyticsSummary analytics; |
| 364 |
| 365 /** |
| 366 * Time the short URL was created; ISO 8601 representation using the |
| 367 * yyyy-MM-dd'T'HH:mm:ss.SSSZZ format, e.g. "2010-10-14T19:01:24.944+00:00". |
| 368 */ |
| 369 core.String created; |
| 370 |
| 371 /** Short URL, e.g. "http://goo.gl/l6MS". */ |
| 372 core.String id; |
| 373 |
| 374 /** The fixed string "urlshortener#url". */ |
| 375 core.String kind; |
| 376 |
| 377 /** |
| 378 * Long URL, e.g. "http://www.google.com/". Might not be present if the status |
| 379 * is "REMOVED". |
| 380 */ |
| 381 core.String longUrl; |
| 382 |
| 383 /** |
| 384 * Status of the target URL. Possible values: "OK", "MALWARE", "PHISHING", or |
| 385 * "REMOVED". A URL might be marked "REMOVED" if it was flagged as spam, for |
| 386 * example. |
| 387 */ |
| 388 core.String status; |
| 389 |
| 390 |
| 391 Url(); |
| 392 |
| 393 Url.fromJson(core.Map _json) { |
| 394 if (_json.containsKey("analytics")) { |
| 395 analytics = new AnalyticsSummary.fromJson(_json["analytics"]); |
| 396 } |
| 397 if (_json.containsKey("created")) { |
| 398 created = _json["created"]; |
| 399 } |
| 400 if (_json.containsKey("id")) { |
| 401 id = _json["id"]; |
| 402 } |
| 403 if (_json.containsKey("kind")) { |
| 404 kind = _json["kind"]; |
| 405 } |
| 406 if (_json.containsKey("longUrl")) { |
| 407 longUrl = _json["longUrl"]; |
| 408 } |
| 409 if (_json.containsKey("status")) { |
| 410 status = _json["status"]; |
| 411 } |
| 412 } |
| 413 |
| 414 core.Map toJson() { |
| 415 var _json = new core.Map(); |
| 416 if (analytics != null) { |
| 417 _json["analytics"] = (analytics).toJson(); |
| 418 } |
| 419 if (created != null) { |
| 420 _json["created"] = created; |
| 421 } |
| 422 if (id != null) { |
| 423 _json["id"] = id; |
| 424 } |
| 425 if (kind != null) { |
| 426 _json["kind"] = kind; |
| 427 } |
| 428 if (longUrl != null) { |
| 429 _json["longUrl"] = longUrl; |
| 430 } |
| 431 if (status != null) { |
| 432 _json["status"] = status; |
| 433 } |
| 434 return _json; |
| 435 } |
| 436 } |
| 437 |
| 438 |
| 439 /** Not documented yet. */ |
| 440 class UrlHistory { |
| 441 /** A list of URL resources. */ |
| 442 core.List<Url> items; |
| 443 |
| 444 /** |
| 445 * Number of items returned with each full "page" of results. Note that the |
| 446 * last page could have fewer items than the "itemsPerPage" value. |
| 447 */ |
| 448 core.int itemsPerPage; |
| 449 |
| 450 /** The fixed string "urlshortener#urlHistory". */ |
| 451 core.String kind; |
| 452 |
| 453 /** A token to provide to get the next page of results. */ |
| 454 core.String nextPageToken; |
| 455 |
| 456 /** |
| 457 * Total number of short URLs associated with this user (may be approximate). |
| 458 */ |
| 459 core.int totalItems; |
| 460 |
| 461 |
| 462 UrlHistory(); |
| 463 |
| 464 UrlHistory.fromJson(core.Map _json) { |
| 465 if (_json.containsKey("items")) { |
| 466 items = _json["items"].map((value) => new Url.fromJson(value)).toList(); |
| 467 } |
| 468 if (_json.containsKey("itemsPerPage")) { |
| 469 itemsPerPage = _json["itemsPerPage"]; |
| 470 } |
| 471 if (_json.containsKey("kind")) { |
| 472 kind = _json["kind"]; |
| 473 } |
| 474 if (_json.containsKey("nextPageToken")) { |
| 475 nextPageToken = _json["nextPageToken"]; |
| 476 } |
| 477 if (_json.containsKey("totalItems")) { |
| 478 totalItems = _json["totalItems"]; |
| 479 } |
| 480 } |
| 481 |
| 482 core.Map toJson() { |
| 483 var _json = new core.Map(); |
| 484 if (items != null) { |
| 485 _json["items"] = items.map((value) => (value).toJson()).toList(); |
| 486 } |
| 487 if (itemsPerPage != null) { |
| 488 _json["itemsPerPage"] = itemsPerPage; |
| 489 } |
| 490 if (kind != null) { |
| 491 _json["kind"] = kind; |
| 492 } |
| 493 if (nextPageToken != null) { |
| 494 _json["nextPageToken"] = nextPageToken; |
| 495 } |
| 496 if (totalItems != null) { |
| 497 _json["totalItems"] = totalItems; |
| 498 } |
| 499 return _json; |
| 500 } |
| 501 } |
| 502 |
| 503 |
OLD | NEW |