diff --git a/hellojs/hellojs-test.ts b/hellojs/hellojs-test.ts index ef0508867..cdecb287f 100644 --- a/hellojs/hellojs-test.ts +++ b/hellojs/hellojs-test.ts @@ -1,32 +1,48 @@ /// -hello.init( - { +hello.init({ 'facebook': '', - }, - { +}, { redirect_uri: 'hello.html', display: 'page', - } - ); +}); + +hello.init({ + facebook: '359288236870', + windows: '000000004403AD10' +}); hello('facebook').login(); hello('facebook').logout(); hello.on('auth.login', auth => { - alert('log to ' + auth.network) + alert('log to ' + auth.network); }).on('auth.logout', auth => { - alert('unlog from ' + auth.network) - }); + alert('unlog from ' + auth.network); + }); hello.getAuthResponse('facebook'); hello.login('facebook', null, () => { - var req = hello.getAuthResponse('facebook'); + var req = hello.getAuthResponse('facebook'); }); hello.logout('facebook'); var serviceInfo = hello.service('facebook'); +hello("facebook").api("me").success(function(json) { + alert("Your name is " + json.name); +}).error(function () { + alert("Whoops!"); +}); + +var sessionstart = function () { + alert("Session has started"); +}; +hello.on("auth.login", sessionstart); + +hello.off("auth.login", sessionstart); + +hello("facebook").login({ scope: "friends,photos,publish" }); \ No newline at end of file diff --git a/hellojs/hellojs.d.ts b/hellojs/hellojs.d.ts index a95b80a93..ce8e328ee 100644 --- a/hellojs/hellojs.d.ts +++ b/hellojs/hellojs.d.ts @@ -1,67 +1,82 @@ -// Type definitions for hello.js 0.2.1 +// Type definitions for hello.js 0.2.3 // Project: http://adodson.com/hello.js/ // Definitions by: Pavel Zika // Definitions: https://github.com/borisyankov/DefinitelyTyped interface HelloJSLoginOptions { - redirect_uri?: string; - display?: string; - scope?: string; - response_type?: string; - force?: boolean; - oauth_proxy?: string; - timeout?: number; - default_service?: string; + redirect_uri?: string; + display?: string; + scope?: string; + response_type?: string; + force?: boolean; + oauth_proxy?: string; + timeout?: number; + default_service?: string; } +interface HelloJSLogoutOptions { + force?: boolean; +} + +interface HelloJSEvent { + on(event: string, callback: (auth: HelloJSEventArgument) => void): HelloJSStatic; + off(event: string, callback: (auth: HelloJSEventArgument) => void): HelloJSStatic; + findEvents(event, callback): void; + emit(event: string, data: any): HelloJSStatic; + emitAfter(): HelloJSStatic; + success(callback: (json?: any) => void): HelloJSStatic; + error(callback: (json?: any) => void): HelloJSStatic; + complete(callback: (json?: any) => void): HelloJSStatic; +} + + interface HelloJSEventArgument { - network: string; - authResponse?: any; + network: string; + authResponse?: any; } -interface HelloJSStatic { - init(serviceAppIds: { [id: string]: string; }, defaultOptions?: HelloJSLoginOptions):void; - login(network: string, option?: HelloJSLoginOptions, callback?: () => void): void; - logout(network: string, callback?: () => void): void; - on(eventName: string, event: (auth: HelloJSEventArgument) => void): HelloJSStatic; - off(eventName: string, event: (auth: HelloJSEventArgument) => void): HelloJSStatic; - getAuthResponse(network: string): any; - service(network: string): HelloJSServiceDef; - settings: HelloJSLoginOptions; - (network: string): HelloJSStaticNamed; - init(servicesDef: { [id: string]: HelloJSServiceDef; }): void; +interface HelloJSStatic extends HelloJSEvent { + init(serviceAppIds: { [id: string]: string; }, options?: HelloJSLoginOptions): void; + login(network: string, options?: HelloJSLoginOptions, callback?: () => void): void; + logout(network: string, options?: HelloJSLogoutOptions, callback?: () => void): void; + getAuthResponse(network: string): any; + service(network: string): HelloJSServiceDef; + settings: HelloJSLoginOptions; + (network: string): HelloJSStaticNamed; + init(servicesDef: { [id: string]: HelloJSServiceDef; }): void; } interface HelloJSStaticNamed { - login(option?: HelloJSLoginOptions, callback?: () => void): void; - logout(callback?: () => void): void; - getAuthResponse(): any; + login(option?: HelloJSLoginOptions, callback?: () => void): void; + logout(callback?: () => void): void; + getAuthResponse(): any; + api(path?: string, method?: string, data?: any, callback?: (json?: any) => void): HelloJSStatic; } interface HelloJSOAuthDef { - version: number; - auth: string; - request: string; - token: string; + version: number; + auth: string; + request: string; + token: string; } interface HelloJSServiceDef { - name: string; - oauth: HelloJSOAuthDef; - scope?: { [id: string]: string; }; - scope_delim?: string; - autorefresh?: boolean; - base?: string; - root?: string; - get?: { [id: string]: any; } - post?: { [id: string]: any; } - del?: { [id: string]: string; } - put?: { [id: string]: any; } - wrap?: { [id: string]: (par: any) => void; } - xhr?: (par: any) => void; - jsonp?: (par: any) => void; - form?: (par: any) => void; - api?: (...par: any[]) => void; + name: string; + oauth: HelloJSOAuthDef; + scope?: { [id: string]: string; }; + scope_delim?: string; + autorefresh?: boolean; + base?: string; + root?: string; + get?: { [id: string]: any; }; + post?: { [id: string]: any; }; + del?: { [id: string]: string; }; + put?: { [id: string]: any; }; + wrap?: { [id: string]: (par: any) => void; }; + xhr?: (par: any) => void; + jsonp?: (par: any) => void; + form?: (par: any) => void; + api?: (...par: any[]) => void; } declare var hello: HelloJSStatic;