Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
[finishes Pomax#92] adds ability to pass default options for request …
Browse files Browse the repository at this point in the history
…module
  • Loading branch information
aghosh47 committed Jul 14, 2016
1 parent 786aa24 commit e31a1af
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
*/
*/
});
```

Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion src/FlickrAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "]";
Expand Down

0 comments on commit e31a1af

Please sign in to comment.