Skip to content

Commit 1af602d

Browse files
committed
*Sob* I *STILL* do not understand git, missed some commits, and I'm too lazy to squish my commits!
1 parent 99eff44 commit 1af602d

File tree

3 files changed

+68
-21
lines changed

3 files changed

+68
-21
lines changed

lib/flickrapi.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ var Request= require("./request").Request,
33
Blogs= require("./blogs").Blogs,
44
People= require("./people").People,
55
Photos= require("./photos").Photos,
6-
Photosets= require("./photosets").Photosets;
6+
Photosets= require("./photosets").Photosets,
7+
Contacts= require("./contacts").Contacts,
8+
Feeds= require("./feeds").Feeds,
9+
Urls= require("./urls").Urls;
710

811
var FlickrAPI= function FlickrAPI(api_key, shared_secret, auth_token) {
912
this._configure(api_key, shared_secret, auth_token);
@@ -17,10 +20,16 @@ FlickrAPI.prototype._configure= function(api_key, shared_secret, auth_token) {
1720
this.photosets= new Photosets(this._request);
1821
this.auth= new Auth(this._request);
1922
this.blogs= new Blogs(this._request);
23+
this.contacts= new Contacts(this._request);
24+
this.urls= new Urls(this._request);
25+
26+
this._feedRequest= new Request(api_key, shared_secret, auth_token, true);
27+
this.feeds= new Feeds(this._feedRequest);
2028
};
2129

2230
FlickrAPI.prototype.setAuthenticationToken= function(auth_token) {
2331
this._request.setAuthenticationToken(auth_token);
32+
this._feedRequest.setAuthenticationToken(auth_token);
2433
};
2534

2635
FlickrAPI.prototype.getLoginUrl= function(permissions, frob) {

lib/photos.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
var PhotoComments= require("./photos_comments").PhotosComments;
2+
13
var Photos= function Photos(request) {
24
this._request= request;
5+
this.comments= new PhotoComments(this._request);
36
};
47

58
Photos.prototype.getInfo= function(photo_id, secret) {

lib/request.js

+55-20
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ var sys = require("sys"),
44

55
var flickr_request = http.createClient(80, "api.flickr.com");
66

7-
var Request= function Request(api_key, shared_secret, auth_token) {
7+
var Request= function Request(api_key, shared_secret, auth_token, isFeedRequest) {
88
this._configure(api_key, shared_secret, auth_token);
9+
this.isFeedRequest= false;
10+
if( isFeedRequest !== undefined ) this.isFeedRequest= isFeedRequest;
11+
12+
if( this.isFeedRequest ) {
13+
this.baseUrl= "/services/feeds";
14+
}
15+
else {
16+
this.baseUrl= "/services/rest";
17+
}
918
};
1019

1120
Request.prototype._configure= function(api_key, shared_secret, auth_token) {
@@ -41,19 +50,26 @@ Request.prototype.getRequestPromise= function(method, arguments, sign_it, result
4150
var promise= new process.Promise()
4251
var argumentString = "";
4352
var api_sig= undefined;
53+
4454
if( arguments === undefined ) arguments = {};
4555

4656
// apply default arguments
4757
arguments.format= "json";
4858
arguments.nojsoncallback= "1";
49-
arguments["method"]= method;
50-
arguments.api_key= this.api_key;
51-
if( this.auth_token ) arguments.auth_token= this.auth_token;
59+
60+
if( this.isFeedRequest ) {
61+
argumentString= "/"+ method;
62+
}
63+
else {
64+
arguments.api_key= this.api_key;
65+
arguments["method"]= method;
66+
if( this.auth_token ) arguments.auth_token= this.auth_token;
5267

53-
if( this.shared_secret && (sign_it || this.auth_token) ) {
54-
api_sig= this.generateSignature(this.shared_secret, arguments);
55-
if( api_sig ) {
56-
arguments.api_sig= api_sig;
68+
if( this.shared_secret && (sign_it || this.auth_token) ) {
69+
api_sig= this.generateSignature(this.shared_secret, arguments);
70+
if( api_sig ) {
71+
arguments.api_sig= api_sig;
72+
}
5773
}
5874
}
5975
var operator= "?";
@@ -62,30 +78,49 @@ Request.prototype.getRequestPromise= function(method, arguments, sign_it, result
6278
if( operator == "?" ) operator= "&";
6379
}
6480
var request= flickr_request.request("GET",
65-
"/services/rest"+ argumentString,
81+
this.baseUrl+ argumentString,
6682
{"host": "api.flickr.com"});
83+
var isFeedRequest= this.isFeedRequest;
6784
request.finish(function (response) {
6885
var result= "";
6986
response.setBodyEncoding("utf8");
7087
response.addListener("body", function (chunk) {
7188
result+= chunk;
7289
});
7390
response.addListener("complete", function () {
74-
var res= JSON.parse(result);
75-
if( res.stat == "ok" ) {
76-
// Munge the response to strip out the stat and just return the response value
77-
for(var key in res) {
78-
if( key !== "stat" ) {
79-
res= res[key];
80-
}
91+
if( isFeedRequest ) {
92+
//Dear-god this is bound to fail horribly.
93+
var m;
94+
if(!result || (m= result.match(/[\S\s]+We were unable to generate the feed you requested, for the following reason:<\/p>\s*?<p[\S\s]+?>([\S\s]+?)<\/p>[\S\s]+/) ) ) {
95+
var errorString= m[1].replace(/^\s+/,"");
96+
errorString= errorString.replace(/\s+$/, "");
97+
promise.emitError({code: -1, message: errorString});
8198
}
82-
if( result_mapper ) {
83-
res= result_mapper(res);
99+
else {
100+
var res= JSON.parse(result);
101+
if( result_mapper ) {
102+
res= result_mapper(res);
103+
}
104+
promise.emitSuccess(res);
84105
}
85-
promise.emitSuccess(res);
86106
}
87107
else {
88-
promise.emitError({code: res.code, message: res.message});
108+
var res= JSON.parse(result);
109+
if( res.stat && res.stat == "ok" ) {
110+
// Munge the response to strip out the stat and just return the response value
111+
for(var key in res) {
112+
if( key !== "stat" ) {
113+
res= res[key];
114+
}
115+
}
116+
if( result_mapper ) {
117+
res= result_mapper(res);
118+
}
119+
promise.emitSuccess(res);
120+
}
121+
else {
122+
promise.emitError({code: res.code, message: res.message});
123+
}
89124
}
90125
});
91126
});

0 commit comments

Comments
 (0)