From e31a1af76d66ee082acc8673dbf5e49e2ed0b6bb Mon Sep 17 00:00:00 2001 From: aghosh47 Date: Wed, 13 Jul 2016 13:51:39 +0530 Subject: [PATCH] [finishes #92] adds ability to pass default options for request module --- README.md | 24 +++++++++++++++++++++++- src/FlickrAPI.js | 5 ++++- src/utils.js | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bd403de..46c6d2a 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,25 @@ Flickr.authenticate(flickrOptions, function(error, flickr) { }); ``` +### As flickrapi internally uses the request module, you can also pass default options for request + +``` +var Flickr = require("flickrapi"), + flickrOptions = { + api_key: "API key that you get from Flickr", + secret: "API key secret that you get from Flickr", + requestOptions: { + timeout: 20000 + } + }; + +Flickr.tokenOnly(flickrOptions, function(error, flickr) { + // we can now use "flickr" as our API object, + // but we can only call public methods and access public data +}); + +``` + # The end. That's it, that's all the quickstart guiding you need. For more detailed information, keep reading. If you just wanted to get up and running, then the preceding text should have gotten you there! @@ -149,7 +168,7 @@ flickr.people.getPhotos({ /* This will now give all public and private results, because we explicitly ran this as an authenticated call - */ + */ }); ``` @@ -524,3 +543,6 @@ optional boolean, suppresses the default console logging on successful authentic ###progress optional boolean, suppresses writing progress bars to stdout if set to `false` + +###requestOptions +adds ability to pass default options for [request](https://github.com/request/request) module diff --git a/src/FlickrAPI.js b/src/FlickrAPI.js index 17fcb4d..8a17720 100644 --- a/src/FlickrAPI.js +++ b/src/FlickrAPI.js @@ -48,7 +48,7 @@ module.exports = (function Flickr() { signature = Utils.sign(data, options.secret, options.access_token_secret), flickrURL = url + "?" + queryString + "&oauth_signature=" + signature; - request.get(flickrURL, function(error, response, body) { + request.defaults(options.requestOptions).get(flickrURL, function(error, response, body) { if(error) { callback(error); } @@ -100,6 +100,7 @@ module.exports = (function Flickr() { // out-of-browser authentication unless specified otherwise if(!options.callback) { options.callback = "oob"; } + if(!options.requestOptions) options.requestOptions = {}; // effect authentication checkToken(options, function(err, access) { @@ -141,6 +142,8 @@ module.exports = (function Flickr() { return next(new Error("Please pass an valid Flickr API key and secret to the Flickr module.\n"+ "Visit http://www.flickr.com/services/apps/create/apply to get one.")); } + + if(!options.requestOptions) options.requestOptions = {}; var APIBuilder = require("./flickr-api-object"); options.tokenonly = true; new APIBuilder(options, Utils, next); diff --git a/src/utils.js b/src/utils.js index f73c41e..64b5a52 100644 --- a/src/utils.js +++ b/src/utils.js @@ -291,7 +291,7 @@ module.exports = (function() { signature = authed ? "&oauth_signature=" + this.sign(data, flickrOptions.secret, flickrOptions.access_token_secret) : '', flickrURL = url + "?" + queryString + signature; - request.get(flickrURL, function(error, response, body) { + request.defaults(flickrOptions.requestOptions).get(flickrURL, function(error, response, body) { if(!response) { error = "HTTP Error: no response for url [" + flickrURL + "]";