Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
E.Azer Koçulu committed Jun 15, 2014
0 parents commit 6ac83fa
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
node_modules
npm-debug.log
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
test
test.js
example
examples
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## flickr-photo-urls

Get source urls with varied sizes of a Flickr photo

## Install

```bash
$ npm install flickr-photo-urls
```

## Usage

```js
var urls = require('flickr-photo-urls')({
key: 'api-key'
})

urls('14321741011', function (error, result) {
if (error) return callback(error);

result.square
// => { "label": "Square", "width": 75, "height": 75, "source": "https:\/\/farm3.staticflickr.com\/2922\/14321741011_aeb3b41d62_s.jpg", "url": "https:\/\/www.flickr.com\/photos\/azer\/14321741011\/sizes\/sq\/", "photo": true }

result.large2048
// => { "label": "Large 2048", "width": 2048, "height": 1365, "source": "https:\/\/farm3.staticflickr.com\/2922\/14321741011_3c581b37ec_k.jpg", "url": "https:\/\/www.flickr.com\/photos\/azer\/14321741011\/sizes\/k\/", "photo": true }
})
```

See `test.js` for more info.

[flickr-client](http://github.com/npm-flickr/flickr-client) can be passed to avoid repeating auth options:

```js
var client = require('flickr-client')({
key: 'api-key'
});

var urls = require('flickr-photo-urls')(client)
```
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var createClient = require("flickr-client");
var variableName = require("variable-name");

var client;

module.exports = setup;

function setup (options) {
client = createClient(options);
return photoURLs;
}

function photoURLs (photoId, callback) {
client('photos.getSizes', { photo_id: photoId }, function (error, response) {
if (error) return callback(error);

var result = {};

var i = response.sizes.size.length;
while (i--) {
if (response.sizes.size[i].media == 'video') response.sizes.size[i].video = true;
if (response.sizes.size[i].media == 'photo') response.sizes.size[i].photo = true;
delete response.sizes.size[i].media == 'photo';

response.sizes.size[i].width = Number(response.sizes.size[i].width);
response.sizes.size[i].height = Number(response.sizes.size[i].height);

result[variableName(response.sizes.size[i].label)] = response.sizes.size[i];
}

callback(undefined, result);

});
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "flickr-photo-urls",
"version": "0.0.0",
"description": "Get source urls with varied sizes of a Flickr photo",
"main": "index.js",
"scripts": {
"test": "node test"
},
"keywords": [
"flickr",
"photos",
"photography",
"api",
"client"
],
"repository": {
"url": "[email protected]:azer/flickr-photo-urls.git",
"type": "git"
},
"author": "azer",
"license": "BSD",
"dependencies": {
"variable-name": "0.0.1",
"with-env": "^0.1.0",
"flickr-client": "0.0.2"
},
"devDependencies": {
"prova": "^1.11.1"
}
}
28 changes: 28 additions & 0 deletions test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ac83fa

Please sign in to comment.