lib/tumblr.js
function TumblrClient(options) {
    // Support for `TumblrClient(credentials, baseUrl, requestLibrary)`
    if (arguments.length > 1) {
        options = {
            credentials: arguments[0],
            baseUrl: arguments[1],
            request: arguments[2],
            returnPromises: false,
        };
    }

    options = options || {};

    this.version = CLIENT_VERSION;
    this.credentials = get(options, 'credentials', omit(options, 'baseUrl', 'request'));
    this.baseUrl = get(options, 'baseUrl', API_BASE_URL);
    this.request = get(options, 'request', request);
    this.requestOptions = {
        followRedirect: false,
        headers: {
            'User-Agent': 'tumblr.js/' + CLIENT_VERSION,
        },
    };

    this.addGetMethods(API_METHODS.GET);
    this.addPostMethods(API_METHODS.POST);

    /**
     * Creates a text post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#ptext-posts|API docs}
     *
     * @method createTextPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.body - post body text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createTextPost = wrapCreatePost('text', ['body']);

    /**
     * Creates a photo post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pphoto-posts|API docs}
     *
     * @method createPhotoPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.source - image source URL
     * @param  {Stream|Array} params.data - an image or array of images
     * @param  {string} params.data64 - base64-encoded image data
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createPhotoPost = wrapCreatePost('photo', ['data', 'data64', 'source']);

    /**
     * Creates a quote post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pquote-posts|API docs}
     *
     * @method createQuotePost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.quote - quote text
     * @param  {string} [params.source] - quote source
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createQuotePost = wrapCreatePost('quote', ['quote']);

    /**
     * Creates a link post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#plink-posts|API docs}
     *
     * @method createLinkPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.url - the link URL
     * @param  {string} [params.thumbnail] - the URL of an image to use as the thumbnail
     * @param  {string} [params.excerpt] - an excerpt from the page the link points to
     * @param  {string} [params.author] - the name of the author of the page the link points to
     * @param  {string} [params.description] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createLinkPost = wrapCreatePost('link', ['url']);

    /**
     * Creates a chat post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pchat-posts|API docs}
     *
     * @method createChatPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.conversation - chat text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createChatPost = wrapCreatePost('chat', ['conversation']);

    /**
     * Creates an audio post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#paudio-posts|API docs}
     *
     * @method createAudioPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.external_url - image source URL
     * @param  {Stream} params.data - an audio file
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createAudioPost = wrapCreatePost('audio', ['data', 'data64', 'external_url']);

    /**
     * Creates a video post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pvideo-posts|API docs}
     *
     * @method createVideoPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.embed - embed code or a video URL
     * @param  {Stream} params.data - a video file
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createVideoPost = wrapCreatePost('video', ['data', 'data64', 'embed']);

    // Enable Promise mode
    if (get(options, 'returnPromises', false)) {
        this.returnPromises();
    }
}
function TumblrClient(options) {
    // Support for `TumblrClient(credentials, baseUrl, requestLibrary)`
    if (arguments.length > 1) {
        options = {
            credentials: arguments[0],
            baseUrl: arguments[1],
            request: arguments[2],
            returnPromises: false,
        };
    }

    options = options || {};

    this.version = CLIENT_VERSION;
    this.credentials = get(options, 'credentials', omit(options, 'baseUrl', 'request'));
    this.baseUrl = get(options, 'baseUrl', API_BASE_URL);
    this.request = get(options, 'request', request);
    this.requestOptions = {
        followRedirect: false,
        headers: {
            'User-Agent': 'tumblr.js/' + CLIENT_VERSION,
        },
    };

    this.addGetMethods(API_METHODS.GET);
    this.addPostMethods(API_METHODS.POST);

    /**
     * Creates a text post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#ptext-posts|API docs}
     *
     * @method createTextPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.body - post body text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createTextPost = wrapCreatePost('text', ['body']);

    /**
     * Creates a photo post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pphoto-posts|API docs}
     *
     * @method createPhotoPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.source - image source URL
     * @param  {Stream|Array} params.data - an image or array of images
     * @param  {string} params.data64 - base64-encoded image data
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createPhotoPost = wrapCreatePost('photo', ['data', 'data64', 'source']);

    /**
     * Creates a quote post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pquote-posts|API docs}
     *
     * @method createQuotePost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.quote - quote text
     * @param  {string} [params.source] - quote source
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createQuotePost = wrapCreatePost('quote', ['quote']);

    /**
     * Creates a link post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#plink-posts|API docs}
     *
     * @method createLinkPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.url - the link URL
     * @param  {string} [params.thumbnail] - the URL of an image to use as the thumbnail
     * @param  {string} [params.excerpt] - an excerpt from the page the link points to
     * @param  {string} [params.author] - the name of the author of the page the link points to
     * @param  {string} [params.description] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createLinkPost = wrapCreatePost('link', ['url']);

    /**
     * Creates a chat post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pchat-posts|API docs}
     *
     * @method createChatPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.conversation - chat text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createChatPost = wrapCreatePost('chat', ['conversation']);

    /**
     * Creates an audio post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#paudio-posts|API docs}
     *
     * @method createAudioPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.external_url - image source URL
     * @param  {Stream} params.data - an audio file
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createAudioPost = wrapCreatePost('audio', ['data', 'data64', 'external_url']);

    /**
     * Creates a video post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pvideo-posts|API docs}
     *
     * @method createVideoPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.embed - embed code or a video URL
     * @param  {Stream} params.data - a video file
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */
    this.createVideoPost = wrapCreatePost('video', ['data', 'data64', 'embed']);

    // Enable Promise mode
    if (get(options, 'returnPromises', false)) {
        this.returnPromises();
    }
}
function TumblrClient ( options ) { // Support for `TumblrClient(credentials, baseUrl, requestLibrary)` if ( arguments . length > 1 ) { options = { credentials : arguments [ 0 ] , baseUrl : arguments [ 1 ] , request : arguments [ 2 ] , returnPromises : false , } ; } options = options || { } ; this . version = CLIENT_VERSION ; this . credentials = get ( options , 'credentials' , omit ( options , 'baseUrl' , 'request' ) ) ; this . baseUrl = get ( options , 'baseUrl' , API_BASE_URL ) ; this . request = get ( options , 'request' , request ) ; this . requestOptions = { followRedirect : false , headers : { 'User-Agent' : 'tumblr.js/' + CLIENT_VERSION , } , } ; this . addGetMethods ( API_METHODS . GET ) ; this . addPostMethods ( API_METHODS . POST ) ; /**
     * Creates a text post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#ptext-posts|API docs}
     *
     * @method createTextPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.body - post body text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */ this . createTextPost = wrapCreatePost ( 'text' , [ 'body' ] ) ; /**
     * Creates a photo post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pphoto-posts|API docs}
     *
     * @method createPhotoPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.source - image source URL
     * @param  {Stream|Array} params.data - an image or array of images
     * @param  {string} params.data64 - base64-encoded image data
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */ this . createPhotoPost = wrapCreatePost ( 'photo' , [ 'data' , 'data64' , 'source' ] ) ; /**
     * Creates a quote post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pquote-posts|API docs}
     *
     * @method createQuotePost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.quote - quote text
     * @param  {string} [params.source] - quote source
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */ this . createQuotePost = wrapCreatePost ( 'quote' , [ 'quote' ] ) ; /**
     * Creates a link post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#plink-posts|API docs}
     *
     * @method createLinkPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.url - the link URL
     * @param  {string} [params.thumbnail] - the URL of an image to use as the thumbnail
     * @param  {string} [params.excerpt] - an excerpt from the page the link points to
     * @param  {string} [params.author] - the name of the author of the page the link points to
     * @param  {string} [params.description] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */ this . createLinkPost = wrapCreatePost ( 'link' , [ 'url' ] ) ; /**
     * Creates a chat post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pchat-posts|API docs}
     *
     * @method createChatPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} [params.title] - post title text
     * @param  {string} params.conversation - chat text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */ this . createChatPost = wrapCreatePost ( 'chat' , [ 'conversation' ] ) ; /**
     * Creates an audio post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#paudio-posts|API docs}
     *
     * @method createAudioPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.external_url - image source URL
     * @param  {Stream} params.data - an audio file
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */ this . createAudioPost = wrapCreatePost ( 'audio' , [ 'data' , 'data64' , 'external_url' ] ) ; /**
     * Creates a video post on the given blog
     *
     * @see {@link https://www.tumblr.com/docs/api/v2#pvideo-posts|API docs}
     *
     * @method createVideoPost
     *
     * @param  {string} blogIdentifier - blog name or URL
     * @param  {Object} params - parameters sent with the request
     * @param  {string} params.embed - embed code or a video URL
     * @param  {Stream} params.data - a video file
     * @param  {string} [params.caption] - post caption text
     * @param  {TumblrClient~callback} [callback] - invoked when the request completes
     *
     * @return {Request|Promise} Request object, or Promise if {@link returnPromises} was used
     *
     * @memberof TumblrClient
     */ this . createVideoPost = wrapCreatePost ( 'video' , [ 'data' , 'data64' , 'embed' ] ) ; // Enable Promise mode if ( get ( options , 'returnPromises' , false ) ) { this . returnPromises ( ) ; } }
Creates a Tumblr API client using the given options

@param  {Object} [options] - client options
@param  {Object} [options.credentials] - OAuth credentials
@param  {string} [options.baseUrl] - API base URL
@param  {Object} [options.request] - library to use for making requests

@constructor
Creates a Tumblr API client using the given options