UNPKG

849 BJavaScriptView Raw
1var jpath = require('..')
2, http = require('http')
3, util = require('util')
4;
5
6var feed = "http://api.flickr.com/services/feeds/photos_public.gne?tags=surf,pipeline&tagmode=all&format=json&jsoncallback=processResponse"
7;
8
9function processResponse(json) {
10 var p = jpath.create("#/items[first(3)][@]")
11 var res = p.resolve(json, function(obj, accum) {
12 accum.push({
13 title: obj.title,
14 author: obj.author,
15 media: obj.media.m
16 });
17 return accum;
18 });
19
20 console.log( util.inspect(res, false, 5) );
21}
22
23http.get(feed, function(res) {
24 console.log("Got response: " + res.statusCode);
25
26 var data = '';
27
28 res.on('data', function (chunk){
29 data += chunk;
30 });
31
32 res.on('end',function(){
33 // result is formatted as jsonp... this is for illustration only.
34 eval(data);
35 })
36}).on('error', function(e) {
37 console.log("Got error: " + e.message);
38});