Gapi Dart
Gapi Dart
@JS()
library gapi;
import "package:js/js.dart";
import "package:js/js_util.dart" show promiseToFuture;
/// The OAuth 2.0 token object represents the OAuth 2.0 token and any associated
data.
@anonymous
@JS()
abstract class GoogleApiOAuth2TokenObject {
/// The OAuth 2.0 token. Only present in successful responses
external String get access_token;
external set access_token(String v);
/// The duration, in seconds, the token is valid for. Only present in successf
ul responses
external String get expires_in;
external set expires_in(String v);
external GoogleApiOAuth2TokenSessionState get session_state;
external set session_state(GoogleApiOAuth2TokenSessionState v);
@anonymous
@JS()
abstract class GoogleApiOAuth2TokenSessionState {
external dynamic /*{
authuser: string,
}*/
get extraQueryParams;
external set extraQueryParams(
dynamic
/*{
authuser: string,
}*/
v);
external factory GoogleApiOAuth2TokenSessionState(
{dynamic
/*{
authuser: string,
}*/
extraQueryParams});
}
// Module gapi
typedef void LoadCallback(
[dynamic args1,
dynamic args2,
dynamic args3,
dynamic args4,
dynamic args5]);
@anonymous
@JS()
abstract class LoadConfig {
external LoadCallback get callback;
external set callback(LoadCallback v);
external Function get onerror;
external set onerror(Function v);
external num get timeout;
external set timeout(num v);
external Function get ontimeout;
external set ontimeout(Function v);
external factory LoadConfig(
{LoadCallback callback,
Function onerror,
num timeout,
Function ontimeout});
}
// Module gapi.auth
/// Initiates the OAuth 2.0 authorization process. The browser displays a popup
window prompting the user authenticate and authorize. After the user authorizes,
the popup closes and the callback function fires.
@JS("gapi.auth.authorize")
external void authorize(
dynamic
/*{
/**
* The application's client ID.
*/
client_id?: string;
/**
* If true, then login uses "immediate mode", which means that the token
is refreshed behind the scenes, and no UI is shown to the user.
*/
immediate?: boolean;
/**
* The OAuth 2.0 response type property. Default: token
*/
response_type?: string;
/**
* The auth scope or scopes to authorize. Auth scopes for individual API
s can be found in their documentation.
*/
scope?: any;
/**
* The user to sign in as. -1 to toggle a multi-account chooser, 0 to de
fault to the user's current account, and 1 to automatically sign in if the user
is signed into Google Plus.
*/
authuser?: number;
}*/
params,
dynamic callback(GoogleApiOAuth2TokenObject token));
/// Initializes the authorization feature. Call this when the client loads to pr
event popup blockers from blocking the auth window on gapi.auth.authorize calls.
@JS("gapi.auth.init")
external void init(dynamic callback());
/// Signs a user out of your app without logging the user out of Google. This me
thod will only work when the user is signed in with Google+ Sign-In.
@JS("gapi.auth.signOut")
external void signOut();
// End module gapi.auth
// Module gapi.client
@anonymous
@JS()
abstract class RequestOptions {
/// The URL to handle the request
external String get path;
external set path(String v);
@anonymous
@JS()
abstract class _RequestOptions {
@JS("gapi.client.init")
external Promise<void> client_init(
dynamic
/*{
/**
* The API Key to use.
*/
apiKey?: string;
/**
* An array of discovery doc URLs or discovery doc JSON objects.
*/
discoveryDocs?: string[];
/**
* The app's client ID, found and created in the Google Developers Conso
le.
*/
clientId?: string;
/**
* The scopes to request, as a space-delimited string.
*/
scope?: string,
hosted_domain?: string;
}*/
args);
}
@anonymous
@JS()
abstract class TokenObject {
/// The access token to use in requests.
external String get access_token;
external set access_token(String v);
external factory TokenObject({String access_token});
}
/// Creates an RPC Request directly. The method name and version identify the me
thod to be executed and the RPC params are provided upon RPC creation.
@JS("gapi.client.rpcRequest")
external RpcRequest rpcRequest(String method,
[String version, dynamic rpcParams]);
@anonymous
@JS()
abstract class HttpRequestFulfilled<T> {
external T get result;
external set result(T v);
external String get body;
external set body(String v);
external List<dynamic> get headers;
external set headers(List<dynamic> v);
external num get status;
external set status(num v);
external String get statusText;
external set statusText(String v);
external factory HttpRequestFulfilled(
{T result,
String body,
List<dynamic> headers,
num status,
String statusText});
}
@anonymous
@JS()
abstract class _HttpRequestFulfilled<T> {
/*external Promise<void> client_load(String name, String version);*/
/*external void client_load(String name, String version, dynamic callback(),
[String url]);
*/
@JS("gapi.client.load")
external dynamic /*Promise<void>|void*/ client_load(
String name, String version,
[dynamic callback(), String url]);
}
@anonymous
@JS()
abstract class HttpRequestRejected {
external dynamic /*dynamic|bool*/ get result;
external set result(dynamic /*dynamic|bool*/ v);
external String get body;
external set body(String v);
external List<dynamic> get headers;
external set headers(List<dynamic> v);
external num get status;
external set status(num v);
external String get statusText;
external set statusText(String v);
external factory HttpRequestRejected(
{dynamic /*dynamic|bool*/ result,
String body,
List<dynamic> headers,
num status,
String statusText});
}
/// HttpRequest supports promises.
/// See Google API Client JavaScript Using Promises https://developers.google.co
m/api-client-library/javascript/features/promises
@JS("gapi.client.HttpRequestPromise")
class HttpRequestPromise<T> {}
@JS("gapi.client.HttpRequestPromise")
abstract class _HttpRequestPromise<T> {
/// Taken and adapted from https://github.com/Microsoft/TypeScript/blob/v2.3.1
/lib/lib.es5.d.ts#L1343
external Promise<dynamic /*TResult1|TResult2*/ > then/*<TResult1, TResult2>*/(
[dynamic /*TResult1|PromiseLike<TResult1> Function(HttpRequestFulfilled<T>
)|dynamic|Null*/ onfulfilled,
dynamic /*TResult2|PromiseLike<TResult2> Function(HttpRequestRejected)|dyn
amic|Null*/ onrejected,
dynamic opt_context]);
}
/// An object encapsulating an HTTP request. This object is not instantiated dir
ectly, rather it is returned by gapi.client.request.
@JS("gapi.client.HttpRequest")
class HttpRequest<T> extends HttpRequestPromise<T> {
/// Executes the request and runs the supplied callback on response.
external void execute(
dynamic callback(
/// contains the response parsed as JSON. If the response is not JSON,
this field will be false.
T jsonResp,
/// Represents an HTTP Batch operation. Individual HTTP requests are added with
the add method and the batch is executed using execute.
@JS("gapi.client.HttpBatch")
class HttpBatch {
/// Adds a gapi.client.HttpRequest to the batch.
external void add(HttpRequest<dynamic> httpRequest,
[dynamic
/*{
/**
* Identifies the response for this request in the map of batch resp
onses. If one is not provided, the system generates a random ID.
*/
id: string;
callback: (
/**
* is the response for this request only. Its format is defined
by the API method being called.
*/
individualResponse: any,
/**
* is the raw batch ID-response map as a string. It contains all
responses to all requests in the batch.
*/
rawBatchResponse: any
) => any
}*/
opt_params]);
/// Executes all requests in the batch. The supplied callback is executed on s
uccess or failure.
external void execute(
dynamic callback(
/// contains the response parsed as JSON. If the response is not JSON,
this field will be false.
dynamic jsonResp,
/// is the same as jsonResp, except it is a raw string that has not be
en parsed. It is typically used when the response is not JSON.
String rawResp));
}