Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed a lot of test files and rewrote README.md

  • Loading branch information...
commit 99d76c766246168281fc996411d2b1bb9c41d2e9 1 parent 408927a
Christopher Brown authored
20 .gitignore
... ... @@ -1,18 +1,2 @@
1   -lib-cov
2   -*.seed
3   -*.log
4   -*.csv
5   -*.dat
6   -*.out
7   -*.pid
8   -*.gz
9   -
10   -pids
11   -logs
12   -results
13   -
14   -node_modules
15   -npm-debug.log
16   -
17   -*.tmproj
18   -.env
  1 +node_modules/
  2 +.env
6 .travis.yml
... ... @@ -1,6 +0,0 @@
1   -language: node_js
2   -node_js:
3   - - 0.4
4   - - 0.6
5   -env:
6   - - FLICKR_API_KEY=ca01c854434e434f21a6f1eda2d0c1e7 FLICKR_API_SECRET=f693f5ddea2ec42a FLICKR_OA_TOKEN="72157629620192540-fbd2433c48791953" FLICKR_OA_TOKEN_SECRET=1c01af722c9d31aa
4 LICENSE
... ... @@ -1,4 +1,8 @@
1 1 Copyright (c) 2012 Forche LLC
  2 +Copyright (c) 2012 Christopher Brown
  3 +
  4 +MIT License
  5 +===========
2 6
3 7 Permission is hereby granted, free of charge, to any person obtaining
4 8 a copy of this software and associated documentation files (the
17 Makefile
... ... @@ -1,17 +0,0 @@
1   -TESTS = test/*.js
2   -REPORTER = dot
3   -
4   --include .env
5   -
6   -test:
7   - @FLICKR_OA_TOKEN=${FLICKR_OA_TOKEN} \
8   - FLICKR_OA_TOKEN_SECRET=${FLICKR_OA_TOKEN_SECRET} \
9   - FLICKR_API_KEY=${FLICKR_API_KEY} \
10   - FLICKR_API_SECRET=${FLICKR_API_SECRET} \
11   - ./node_modules/.bin/mocha \
12   - --require should \
13   - --reporter $(REPORTER) \
14   - --growl \
15   - $(TESTS)
16   -
17   -.PHONY: test bench
126 README.md
Source Rendered
... ... @@ -1,83 +1,105 @@
1   -# node-flickr
  1 +# flickr-with-uploads
2 2
3   -__A simple node wrapper for the Flickr API that supports oAuth authentication__
  3 +124-line Node.js wrapper for the Flickr API, using oAuth authentication, supporting uploads.
4 4
5   -This is a small library that adds a thin wrapper around the Flickr API to make it easier to
6   -call methods, sign them when necessary.
  5 +It currently supports only Flickr's "API Methods" (on the right side of the page [Flickr API Documentation](http://www.flickr.com/services/api/)), and [Uploading](http://www.flickr.com/services/api/upload.api.html).
7 6
8   -It currently does __not__ support the RSS/Atom feeds, nor does it handle the
9   -oAuth login process. It may in the future -- I'd appreciate any patches if you have time.
  7 +A pull request is in the process, to ciaranj's `node-oauth`, for some required functionality to allow signing but not GET/POSTing with that oAuth library. For the time being, this package requires my `node-oauth` fork, which includes that functionality.
10 8
11   -The library is heavily inspired by the
12   -[flickrnode library by Ciaran Jessup](https://github.com/ciaranj/flickrnode).
  9 +The library is forked from [node-flickr](https://github.com/sujal/node-flickr), but I pretty much rewrote the whole flickr.js file. I fixed the formatting, simplified the signing or not-signing handling, and **most importantly** now support uploading. Even though I added a pretty big feature, I decreased the line count from 158 to 124.
  10 +[node-flickr](https://github.com/sujal/node-flickr), in turn, is heavily inspired by [the flickrnode library by Ciaran Jessup](https://github.com/ciaranj/flickrnode).
13 11
14   -__Current Test Status__: [![Build Status](https://secure.travis-ci.org/sujal/node-flickr.png)](http://travis-ci.org/sujal/node-flickr)
15   -
16   -## Usage
  12 +## Initialization
17 13
18 14 Install the library into your package.json file or using the following command:
19 15
20   - npm install flickr
21   -
22   -Once installed, you can interact with the library with something like this:
  16 + npm install flickr-with-uploads
23 17
24 18 ````javascript
25 19 var Flickr = require('flickr').Flickr;
26 20
27   -var client = new Flickr('YOUR_CONSUMER_KEY/API_KEY', 'YOUR_CONSUMER_SECRET',
28   - {"oauth_token": 'optional oauth token', "oauth_token_secret": 'optional oauth token secret'});
29   -
  21 +// constructor arguments: new Flickr(consumer_key, consumer_secret, oauth_token, oauth_token_secret, base_url)
  22 +var client = new Flickr('0RjUImXvsYx2P8Gi4eZScFh9fkLJltDV', 'mbu87dOB0FWncTRJ',
  23 + '3XF0pqP4daZf9oIlx-a7H1uMLeGrBidkJU', 'KpslBxHoh4QYk6ad')
30 24 ````
31 25
32   -Some examples follow.
33   -
34   -## Examples
  26 +I read in options from a `.env` file like so, but you can do it however you want:
35 27
36   -_Coming Soon_
  28 +````javascript
  29 +function readOptions(callback) {
  30 + fs.readFile(path.join(__dirname, '.env'), 'utf8', function(err, text) {
  31 + var opts = {};
  32 + if (!err) {
  33 + text.split(/\n/).forEach(function(line) {
  34 + var line_parts = line.split(/\=/);
  35 + opts[line_parts[0]] = line_parts[1];
  36 + });
  37 + }
  38 + callback(err, opts);
  39 + });
  40 +}
  41 +````
37 42
38   -## Development
  43 +And my .env file (all my values are fake, obviously--actual credentials are all hexadecimal):
39 44
40   -Contributions are welcome. Please feel free to submit pull requests. I prefer that pull requests
41   -come from properly named feature branches (_don't dev in master!_). This makes it easier for people
42   -scanning the Network tab above to see what your fork offers.
  45 + FLICKR_API_KEY=0RjUImXvsYx2P8Gi4eZScFh9fkLJltDV
  46 + FLICKR_API_SECRET=mbu87dOB0FWncTRJ
  47 + FLICKR_OA_TOKEN=3XF0pqP4daZf9oIlx-a7H1uMLeGrBidkJU
  48 + FLICKR_OA_TOKEN_SECRET=KpslBxHoh4QYk6ad
43 49
44   -### Running tests
  50 +And then since all my calls are signed, I wrote a helper function, `api`:
45 51
46   -To setup your local copy for testing, I recommend you run
  52 +````javascript
  53 +function api(method_name, data, options, callback) {
  54 + // overloaded as (method_name, data, callback)
  55 + return client.createRequest(method_name, data, true, options, callback).send();
  56 +}
  57 +````
47 58
48   - npm link
  59 +## Examples
49 60
50   -in the project directory to
51   -install all the dependencies. I found that easiest.
  61 +Using my `api` function from above:
52 62
53   -Next, create a .env file in the root of the project directory. The `Makefile`
54   -sets up the testing environment to use those values.
55   -Yes, the tests run against the live API (for now).
  63 +````javascript
  64 +var fullpath = '/Users/chbrown/Pictures/Seaworld - The Heist/orca_019.jpg';
  65 +var params = {
  66 + title: 'My new pet: baby orca', description: "Don't tell Seaworld!",
  67 + is_public: 0, is_friend: 1, is_family: 1, hidden: 2
  68 +};
  69 +var options = {
  70 + method: 'POST',
  71 + file: fs.createReadStream(fullpath, {flags: 'r'})
  72 +};
  73 +// the method_name gets the special value of "upload" for uploads.
  74 +api('upload', params, options, function(err, response) {
  75 + if (err) {
  76 + console.error("Could not upload photo: ", self.toString() + ". Error message:");
  77 + console.error();
  78 + }
  79 + else {
  80 + var photo_id = response.photoid;
  81 + // usually, the method name is precisely the name of the API method, as they are here:
  82 + api('flickr.photosets.addPhoto', {photoset_id: 1272356126, photo_id: photo_id}, function(err, response) {
  83 + api('flickr.photos.getInfo', {photo_id: photo_id}, function(err, response) {
  84 + console.log("Full photo info:", response.photo);
  85 + });
  86 + });
  87 + }
  88 +});
  89 +````
56 90
57   -You should probably start with the following contents:
  91 +## Development
58 92
59   -````
60   -FLICKR_API_KEY=<Your API Key>
61   -FLICKR_API_SECRET=<Your API Secret>
62   -FLICKR_OA_TOKEN=<A valid access token>
63   -FLICKR_OA_TOKEN_SECRET=<A valid access token secret>
64   -````
  93 +Fixes are totally welcome! In the master branch, even! Just use sane formatting (like what jsbeautifier.org uses, but with 2-space indents, not 4).
65 94
66   -To get the access token and the access token secret, you will need to go through
67   -the OAuth dance. You can use something like [this OAuth test client](http://term.ie/oauth/example/client.php)
68   -to generate those values. Using that tool is beyond the scope of this readme.
  95 +## Dependencies
69 96
70   -Then, whenever you want to run tests:
  97 +Just one dependency: [form-data](https://github.com/felixge/node-form-data). This is just for the uploads. It works awesome, only takes about three lines to use. felixge is the author of (node-formidable)[https://github.com/felixge/node-formidable], the awesome form parsing library.
71 98
72   -````
73   -make test
74   -````
  99 +## Related
75 100
76   -You should get a nicely formatted output for your tests. You can also override the
77   -reporter used by Mocha by setting a `REPORTER` value in `.env`. Read the `Makefile`
78   -for details.
  101 +The node-flickr rewrite was all just to support my (Flickr Backup Script)[https://github.com/chbrown/flickr-backup]. There are lots more examples in that code, too.
79 102
80 103 ## License
81 104
82   -See the LICENSE file for details.
83   -
  105 +MIT Licensed. See the LICENSE file for full text.
2  lib/flickr.js
@@ -112,7 +112,7 @@ FlickrRequest.prototype.processResponse = function(response_body) {
112 112 this.callback(null, res);
113 113 }
114 114 else {
115   - throw new Error('Flickr Error (' + res.code + '): ' + res.message);
  115 + throw new Error('Flickr Error ' + res.code + ': ' + res.message);
116 116 }
117 117 }
118 118 catch (exc) {
24 package.json
... ... @@ -1,24 +1,16 @@
1 1 {
2   - "name": "flickr",
3   - "description": "A simple wrapper for the Flickr API using oAuth 1.0a auth",
4   - "version": "0.2.0",
  2 + "name": "flickr-with-uploads",
  3 + "description": "Simple Flickr API for Node.js using OAuth 1.0a, supporting uploads.",
  4 + "version": "0.2.1",
5 5 "authors": [
6   - "Sujal Shah <codesujal@gmail.com>",
7   - "Christopher Brown <audiere@gmail.com>"
  6 + "Christopher Brown <audiere@gmail.com>",
  7 + "Sujal Shah <codesujal@gmail.com>"
8 8 ],
9   - "keywords": ["flickr", "api", "oauth"],
10   - "repository": "git://github.com/chbrown/node-flickr.git",
  9 + "keywords": ["flickr", "uploads", "api", "oauth"],
  10 + "repository": "git://github.com/chbrown/flickr-with-uploads.git",
11 11 "dependencies": {
12 12 "oauth": "git://github.com/chbrown/node-oauth.git",
13 13 "form-data": "*"
14 14 },
15   - "devDependencies": {
16   - "mocha": "*",
17   - "should": "*",
18   - "growl": "*"
19   - },
20   - "main": "index",
21   - "scripts": {
22   - "test": "make test"
23   - }
  15 + "main": "index"
24 16 }
4 test/mocha.opts
... ... @@ -1,4 +0,0 @@
1   ---require should
2   ---reporter dot
3   ---ui bdd
4   ---growl
25 test/request.js
... ... @@ -1,25 +0,0 @@
1   -var should = require('should'),
2   - Flickr = require('../lib/flickr').Flickr;
3   -
4   -describe('requests', function(){
5   - describe('basic unauthenticated requests', function(){
6   - it('should execute a search without error', function(done){
7   - this.timeout(5000);
8   - var client = new Flickr(process.env.FLICKR_API_KEY, process.env.FLICKR_API_SECRET);
9   - client.executeAPIRequest("flickr.photos.search",{text: "sujal"}, false, done);
10   - });
11   - });
12   -
13   - describe('authenticated requests', function(){
14   - it('should execute a simple echo call without error', function(done){
15   -
16   - var client = new Flickr(process.env.FLICKR_API_KEY, process.env.FLICKR_API_SECRET,
17   - {"oauth_token": process.env.FLICKR_OA_TOKEN, "oauth_token_secret": process.env.FLICKR_OA_TOKEN_SECRET});
18   - client.executeAPIRequest("flickr.test.login", null, true, function(err, response){
19   - if (err) { done(err); }
20   - response.should.have.property('user').with.property('id');
21   - done();
22   - });
23   - })
24   - });
25   -});

0 comments on commit 99d76c7

Please sign in to comment.
Something went wrong with that request. Please try again.