Skip to content
Browse files

Removed a lot of test files and rewrote README.md

  • Loading branch information...
1 parent 408927a commit 99d76c766246168281fc996411d2b1bb9c41d2e9 @chbrown committed Aug 10, 2012
Showing with 89 additions and 139 deletions.
  1. +2 −18 .gitignore
  2. +0 −6 .travis.yml
  3. +4 −0 LICENSE
  4. +0 −17 Makefile
  5. +74 −52 README.md
  6. +1 −1 lib/flickr.js
  7. +8 −16 package.json
  8. +0 −4 test/mocha.opts
  9. +0 −25 test/request.js
View
20 .gitignore
@@ -1,18 +1,2 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
-*.gz
-
-pids
-logs
-results
-
-node_modules
-npm-debug.log
-
-*.tmproj
-.env
+node_modules/
+.env
View
6 .travis.yml
@@ -1,6 +0,0 @@
-language: node_js
-node_js:
- - 0.4
- - 0.6
-env:
- - FLICKR_API_KEY=ca01c854434e434f21a6f1eda2d0c1e7 FLICKR_API_SECRET=f693f5ddea2ec42a FLICKR_OA_TOKEN="72157629620192540-fbd2433c48791953" FLICKR_OA_TOKEN_SECRET=1c01af722c9d31aa
View
4 LICENSE
@@ -1,4 +1,8 @@
Copyright (c) 2012 Forche LLC
+Copyright (c) 2012 Christopher Brown
+
+MIT License
+===========
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
17 Makefile
@@ -1,17 +0,0 @@
-TESTS = test/*.js
-REPORTER = dot
-
--include .env
-
-test:
- @FLICKR_OA_TOKEN=${FLICKR_OA_TOKEN} \
- FLICKR_OA_TOKEN_SECRET=${FLICKR_OA_TOKEN_SECRET} \
- FLICKR_API_KEY=${FLICKR_API_KEY} \
- FLICKR_API_SECRET=${FLICKR_API_SECRET} \
- ./node_modules/.bin/mocha \
- --require should \
- --reporter $(REPORTER) \
- --growl \
- $(TESTS)
-
-.PHONY: test bench
View
126 README.md
@@ -1,83 +1,105 @@
-# node-flickr
+# flickr-with-uploads
-__A simple node wrapper for the Flickr API that supports oAuth authentication__
+124-line Node.js wrapper for the Flickr API, using oAuth authentication, supporting uploads.
-This is a small library that adds a thin wrapper around the Flickr API to make it easier to
-call methods, sign them when necessary.
+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).
-It currently does __not__ support the RSS/Atom feeds, nor does it handle the
-oAuth login process. It may in the future -- I'd appreciate any patches if you have time.
+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.
-The library is heavily inspired by the
-[flickrnode library by Ciaran Jessup](https://github.com/ciaranj/flickrnode).
+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.
+[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).
-__Current Test Status__: [![Build Status](https://secure.travis-ci.org/sujal/node-flickr.png)](http://travis-ci.org/sujal/node-flickr)
-
-## Usage
+## Initialization
Install the library into your package.json file or using the following command:
- npm install flickr
-
-Once installed, you can interact with the library with something like this:
+ npm install flickr-with-uploads
````javascript
var Flickr = require('flickr').Flickr;
-var client = new Flickr('YOUR_CONSUMER_KEY/API_KEY', 'YOUR_CONSUMER_SECRET',
- {"oauth_token": 'optional oauth token', "oauth_token_secret": 'optional oauth token secret'});
-
+// constructor arguments: new Flickr(consumer_key, consumer_secret, oauth_token, oauth_token_secret, base_url)
+var client = new Flickr('0RjUImXvsYx2P8Gi4eZScFh9fkLJltDV', 'mbu87dOB0FWncTRJ',
+ '3XF0pqP4daZf9oIlx-a7H1uMLeGrBidkJU', 'KpslBxHoh4QYk6ad')
````
-Some examples follow.
-
-## Examples
+I read in options from a `.env` file like so, but you can do it however you want:
-_Coming Soon_
+````javascript
+function readOptions(callback) {
+ fs.readFile(path.join(__dirname, '.env'), 'utf8', function(err, text) {
+ var opts = {};
+ if (!err) {
+ text.split(/\n/).forEach(function(line) {
+ var line_parts = line.split(/\=/);
+ opts[line_parts[0]] = line_parts[1];
+ });
+ }
+ callback(err, opts);
+ });
+}
+````
-## Development
+And my .env file (all my values are fake, obviously--actual credentials are all hexadecimal):
-Contributions are welcome. Please feel free to submit pull requests. I prefer that pull requests
-come from properly named feature branches (_don't dev in master!_). This makes it easier for people
-scanning the Network tab above to see what your fork offers.
+ FLICKR_API_KEY=0RjUImXvsYx2P8Gi4eZScFh9fkLJltDV
+ FLICKR_API_SECRET=mbu87dOB0FWncTRJ
+ FLICKR_OA_TOKEN=3XF0pqP4daZf9oIlx-a7H1uMLeGrBidkJU
+ FLICKR_OA_TOKEN_SECRET=KpslBxHoh4QYk6ad
-### Running tests
+And then since all my calls are signed, I wrote a helper function, `api`:
-To setup your local copy for testing, I recommend you run
+````javascript
+function api(method_name, data, options, callback) {
+ // overloaded as (method_name, data, callback)
+ return client.createRequest(method_name, data, true, options, callback).send();
+}
+````
- npm link
+## Examples
-in the project directory to
-install all the dependencies. I found that easiest.
+Using my `api` function from above:
-Next, create a .env file in the root of the project directory. The `Makefile`
-sets up the testing environment to use those values.
-Yes, the tests run against the live API (for now).
+````javascript
+var fullpath = '/Users/chbrown/Pictures/Seaworld - The Heist/orca_019.jpg';
+var params = {
+ title: 'My new pet: baby orca', description: "Don't tell Seaworld!",
+ is_public: 0, is_friend: 1, is_family: 1, hidden: 2
+};
+var options = {
+ method: 'POST',
+ file: fs.createReadStream(fullpath, {flags: 'r'})
+};
+// the method_name gets the special value of "upload" for uploads.
+api('upload', params, options, function(err, response) {
+ if (err) {
+ console.error("Could not upload photo: ", self.toString() + ". Error message:");
+ console.error();
+ }
+ else {
+ var photo_id = response.photoid;
+ // usually, the method name is precisely the name of the API method, as they are here:
+ api('flickr.photosets.addPhoto', {photoset_id: 1272356126, photo_id: photo_id}, function(err, response) {
+ api('flickr.photos.getInfo', {photo_id: photo_id}, function(err, response) {
+ console.log("Full photo info:", response.photo);
+ });
+ });
+ }
+});
+````
-You should probably start with the following contents:
+## Development
-````
-FLICKR_API_KEY=<Your API Key>
-FLICKR_API_SECRET=<Your API Secret>
-FLICKR_OA_TOKEN=<A valid access token>
-FLICKR_OA_TOKEN_SECRET=<A valid access token secret>
-````
+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).
-To get the access token and the access token secret, you will need to go through
-the OAuth dance. You can use something like [this OAuth test client](http://term.ie/oauth/example/client.php)
-to generate those values. Using that tool is beyond the scope of this readme.
+## Dependencies
-Then, whenever you want to run tests:
+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.
-````
-make test
-````
+## Related
-You should get a nicely formatted output for your tests. You can also override the
-reporter used by Mocha by setting a `REPORTER` value in `.env`. Read the `Makefile`
-for details.
+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.
## License
-See the LICENSE file for details.
-
+MIT Licensed. See the LICENSE file for full text.
View
2 lib/flickr.js
@@ -112,7 +112,7 @@ FlickrRequest.prototype.processResponse = function(response_body) {
this.callback(null, res);
}
else {
- throw new Error('Flickr Error (' + res.code + '): ' + res.message);
+ throw new Error('Flickr Error ' + res.code + ': ' + res.message);
}
}
catch (exc) {
View
24 package.json
@@ -1,24 +1,16 @@
{
- "name": "flickr",
- "description": "A simple wrapper for the Flickr API using oAuth 1.0a auth",
- "version": "0.2.0",
+ "name": "flickr-with-uploads",
+ "description": "Simple Flickr API for Node.js using OAuth 1.0a, supporting uploads.",
+ "version": "0.2.1",
"authors": [
- "Sujal Shah <codesujal@gmail.com>",
- "Christopher Brown <audiere@gmail.com>"
+ "Christopher Brown <audiere@gmail.com>",
+ "Sujal Shah <codesujal@gmail.com>"
],
- "keywords": ["flickr", "api", "oauth"],
- "repository": "git://github.com/chbrown/node-flickr.git",
+ "keywords": ["flickr", "uploads", "api", "oauth"],
+ "repository": "git://github.com/chbrown/flickr-with-uploads.git",
"dependencies": {
"oauth": "git://github.com/chbrown/node-oauth.git",
"form-data": "*"
},
- "devDependencies": {
- "mocha": "*",
- "should": "*",
- "growl": "*"
- },
- "main": "index",
- "scripts": {
- "test": "make test"
- }
+ "main": "index"
}
View
4 test/mocha.opts
@@ -1,4 +0,0 @@
---require should
---reporter dot
---ui bdd
---growl
View
25 test/request.js
@@ -1,25 +0,0 @@
-var should = require('should'),
- Flickr = require('../lib/flickr').Flickr;
-
-describe('requests', function(){
- describe('basic unauthenticated requests', function(){
- it('should execute a search without error', function(done){
- this.timeout(5000);
- var client = new Flickr(process.env.FLICKR_API_KEY, process.env.FLICKR_API_SECRET);
- client.executeAPIRequest("flickr.photos.search",{text: "sujal"}, false, done);
- });
- });
-
- describe('authenticated requests', function(){
- it('should execute a simple echo call without error', function(done){
-
- var client = new Flickr(process.env.FLICKR_API_KEY, process.env.FLICKR_API_SECRET,
- {"oauth_token": process.env.FLICKR_OA_TOKEN, "oauth_token_secret": process.env.FLICKR_OA_TOKEN_SECRET});
- client.executeAPIRequest("flickr.test.login", null, true, function(err, response){
- if (err) { done(err); }
- response.should.have.property('user').with.property('id');
- done();
- });
- })
- });
-});

0 comments on commit 99d76c7

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