From 1e4a86c5fdad1113793811a9ade0864ea1cdab44 Mon Sep 17 00:00:00 2001 From: Adam Burmister Date: Mon, 11 Jan 2016 15:25:33 -0800 Subject: [PATCH 1/4] Pinterest JS SDK definitions --- pinterest-sdk/pinterest-sdk.d.ts | 130 +++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 pinterest-sdk/pinterest-sdk.d.ts diff --git a/pinterest-sdk/pinterest-sdk.d.ts b/pinterest-sdk/pinterest-sdk.d.ts new file mode 100644 index 0000000000..2c7b32b0d0 --- /dev/null +++ b/pinterest-sdk/pinterest-sdk.d.ts @@ -0,0 +1,130 @@ +// Type definitions for pinterest-sdk +// Project: +// Definitions by: Adam Burmister +// Definitions: https://github.com/adamburmister/DefinitelyTyped +declare module PDK { + + type OauthSession = { + accessToken?: string; + scope?: string; + error?: string; + } + + interface LoginOptions { + method?: string; + appId?: string; + cookie?: boolean; + logging?: boolean; + session?: OauthSession; + } + + interface OAuthRequestParams { + accessToken?: string; + data?: any; + } + + interface InitOptions { + /** Your application ID from developer.pinterest.com */ + appId?: string; + cookie?: boolean; + logging?: boolean; + session?: OauthSession; + } + + enum HttpMethod { 'get', 'put', 'post', 'delete' } + + /** + * Get information on the currently authenticated user + * @param path the url path + * @param params the parameters for the request + * @param cb the callback export function to handle the response + */ + export function me(path?: string, params?: Object, callback?: Function): void; + + /** + * Make an API call to the server + * + * The path is the only required argument. + * + * @param path URL path + * @param httpMethod HTTP verb + */ + export function request(path: string, httpMethod?: string|HttpMethod, params?: OAuthRequestParams, callback?: Function): void; + + /** + * Show user login dialog, and save access token + */ + export function login(options: LoginOptions, callback: Function): void; + + /** + * Remove the session of the current user. + * + * Need to call login to re-connect, unless session is saved on server. + */ + export function logout(callback: (session: OauthSession) => any): void; + + /** + * Get the active session for the current user + */ + export function getSession(): OauthSession; + + /** + * Save the user specified session + */ + export function setSession(session: OauthSession, callback?: (session: OauthSession) => any): void; + + /** + * Initialize the library. + * + * Typical initialization enabling all optional features: + * ``` + * + * + * ``` + * The best place to put this code is right before the closing + * `` tag. + * + * - Asynchronous Loading - + * + * The library makes non-blocking loading of the script easy to use by + * providing the `pAsyncInit` hook. If this global export function is defined, it + * will be executed when the library is loaded: + * ``` + *
+ * + * ``` + */ + export function init(options: InitOptions): void; + + /** + * Allow an unauthenticated user to pin using a popup + * + * @param imageUrl URL for image being pinned + * @param note description for pin + * @param url url where pin is from + */ + export function pin(imageUrl: string, note: string, url: string, callback: Function): void; +} + +declare module 'pinterest-sdk' { + export = PDK; +} From b7b7da9f379ed4134a6aaa35e1c48ebcc9ab767a Mon Sep 17 00:00:00 2001 From: Adam Burmister Date: Mon, 11 Jan 2016 15:40:22 -0800 Subject: [PATCH 2/4] Test suite for Pinterest SDK --- pinterest-sdk/pinterest-sdk-tests.ts | 17 +++++++++++++++++ pinterest-sdk/pinterest-sdk.d.ts | 17 ++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 pinterest-sdk/pinterest-sdk-tests.ts diff --git a/pinterest-sdk/pinterest-sdk-tests.ts b/pinterest-sdk/pinterest-sdk-tests.ts new file mode 100644 index 0000000000..0c0f9a9345 --- /dev/null +++ b/pinterest-sdk/pinterest-sdk-tests.ts @@ -0,0 +1,17 @@ +/// + +const PIN_FIELDS = "id,name,image[small]"; +const PIN_SCOPE = "read_public, write_public"; +const CALLBACK = (...args: any[]) => {}; +const DATA = { board: "test", note: "test", link: "tets", image_url: "test" }; + +// Examples from https://github.com/pinterest/pinterest-api-demo + +// Auth +PDK.login({ scope : PIN_SCOPE }, CALLBACK); +PDK.logout(); +PDK.getSession(); + +// Requests +PDK.request("/pins/", "POST", DATA, CALLBACK); +PDK.me("boards", { fields: PIN_FIELDS }, CALLBACK); diff --git a/pinterest-sdk/pinterest-sdk.d.ts b/pinterest-sdk/pinterest-sdk.d.ts index 2c7b32b0d0..6c9d48493f 100644 --- a/pinterest-sdk/pinterest-sdk.d.ts +++ b/pinterest-sdk/pinterest-sdk.d.ts @@ -1,9 +1,13 @@ // Type definitions for pinterest-sdk -// Project: +// Project: https://assets.pinterest.com/sdk/sdk.js // Definitions by: Adam Burmister // Definitions: https://github.com/adamburmister/DefinitelyTyped declare module PDK { + enum OAuthScopes { 'read_public', 'write_public', 'read_relationships', 'write_relationships' } + + enum HttpMethod { 'get', 'put', 'post', 'delete' } + type OauthSession = { accessToken?: string; scope?: string; @@ -11,6 +15,7 @@ declare module PDK { } interface LoginOptions { + scope: string|OAuthScopes; method?: string; appId?: string; cookie?: boolean; @@ -31,8 +36,6 @@ declare module PDK { session?: OauthSession; } - enum HttpMethod { 'get', 'put', 'post', 'delete' } - /** * Get information on the currently authenticated user * @param path the url path @@ -61,7 +64,7 @@ declare module PDK { * * Need to call login to re-connect, unless session is saved on server. */ - export function logout(callback: (session: OauthSession) => any): void; + export function logout(callback?: (session: OauthSession) => any): void; /** * Get the active session for the current user @@ -118,9 +121,9 @@ declare module PDK { /** * Allow an unauthenticated user to pin using a popup * - * @param imageUrl URL for image being pinned - * @param note description for pin - * @param url url where pin is from + * @param imageUrl URL for image that you want to Pin. + * @param note The Pin's description. + * @param url The URL the Pin will link to when you click through. */ export function pin(imageUrl: string, note: string, url: string, callback: Function): void; } From 7c674066763d9ef1f38dd4cfbe4bf909d5275308 Mon Sep 17 00:00:00 2001 From: Adam Burmister Date: Mon, 11 Jan 2016 15:44:12 -0800 Subject: [PATCH 3/4] Tidy --- pinterest-sdk/pinterest-sdk-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pinterest-sdk/pinterest-sdk-tests.ts b/pinterest-sdk/pinterest-sdk-tests.ts index 0c0f9a9345..ea1e2d438e 100644 --- a/pinterest-sdk/pinterest-sdk-tests.ts +++ b/pinterest-sdk/pinterest-sdk-tests.ts @@ -1,12 +1,12 @@ /// +// Examples from https://github.com/pinterest/pinterest-api-demo + const PIN_FIELDS = "id,name,image[small]"; const PIN_SCOPE = "read_public, write_public"; const CALLBACK = (...args: any[]) => {}; const DATA = { board: "test", note: "test", link: "tets", image_url: "test" }; -// Examples from https://github.com/pinterest/pinterest-api-demo - // Auth PDK.login({ scope : PIN_SCOPE }, CALLBACK); PDK.logout(); From 29844903a52da1b82ef1ea4ef70c1b6a330f495f Mon Sep 17 00:00:00 2001 From: Adam Burmister Date: Mon, 11 Jan 2016 16:02:27 -0800 Subject: [PATCH 4/4] Add overloads for PDK.me --- pinterest-sdk/pinterest-sdk.d.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pinterest-sdk/pinterest-sdk.d.ts b/pinterest-sdk/pinterest-sdk.d.ts index 6c9d48493f..a72fe9d892 100644 --- a/pinterest-sdk/pinterest-sdk.d.ts +++ b/pinterest-sdk/pinterest-sdk.d.ts @@ -36,13 +36,26 @@ declare module PDK { session?: OauthSession; } + /** + * Get information on the currently authenticated user + * @param cb the callback export function to handle the response + */ + export function me(callback: Function): void; + + /** + * Get information on the currently authenticated user + * @param path the url path + * @param cb the callback export function to handle the response + */ + export function me(path: string, callback: Function): void; + /** * Get information on the currently authenticated user * @param path the url path * @param params the parameters for the request * @param cb the callback export function to handle the response */ - export function me(path?: string, params?: Object, callback?: Function): void; + export function me(path: string, params: Object, callback: Function): void; /** * Make an API call to the server