Created
July 24, 2012 13:02
-
-
Save spolu/3169820 to your computer and use it in GitHub Desktop.
Teleportd Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tl = require('teleportd').teleportd({ user_key: '_YOUR_USER_KEY_' }); | |
/** | |
* Performs a get request to retrieve the full content of a pic | |
* @param sha of the pic to retrieve the details | |
* @param cb(err, pic) the result/error callback | |
* err: set if an error was raised | |
* pic: contain the pic data otherwise | |
*/ | |
tl.get(sha, function(error, pic) { | |
if(error) { | |
// an error has been raised | |
} else { | |
// work with pic | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tl = require('teleportd').teleportd({ user_key: '_YOUR_USER_KEY_' }); | |
// search specification | |
var spec = { loc: [137.77,-122.43,0.2,0.4], | |
str: "Golden Gate Bridge", | |
period: [1342534945000, 1342621345000], | |
from: 20, | |
size:40 } | |
/** | |
* Performs a search for a given search specification | |
* @param spec a fully constructed search specification | |
* @param cb(err, hits, total, took) the result/error callback | |
* err: set if an error was raised | |
* hits: the results otherwise | |
* total: the number of hits | |
* took: the total time it took to process the query (in ms) | |
*/ | |
tl.search(spec, function(err, hits, total, took) { | |
if(err) { | |
// an error occurred | |
} | |
else { | |
// work with pic | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tl = require('teleportd').teleportd({ user_key: '_YOUR_USER_KEY_' }); | |
/** | |
* Starts a stream for the specified track words or location | |
* @param spec a fully constructed stream specification | |
* @param cb(pic) the callback | |
* pic: a newly received pic or null if the stream stopped | |
*/ | |
var sid = tl.stream({ track: ['paris', 'berlin'] }, function(pic) { | |
if (typeof pic == 'undefined') { | |
// an error occurred and the stream stopped | |
} | |
else { | |
// work with pic | |
} | |
}); | |
/** | |
* stops the above stream | |
*/ | |
tl.stop(sid); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//sha of the pic to retrieve the details | |
$sha = 'PIC_SHA'; | |
/** | |
* makes a get request to retrieve the associated pic to the sha | |
*/ | |
$pic = $tl->get($sha); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
//construct your search specifications | |
$spec = array('str' => 'ladurre', | |
'loc' => array(48.85, 2.33, 0.1, 0.3), | |
'period' => array(1342534945000, 1342621345000), | |
'from' => 10 , | |
'size' => 20 ); | |
/** | |
* makes a search query given the above spec | |
*/ | |
$json= $tl->search($spec); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/** | |
* Given most PHP scripts context of execution within | |
* a running page draw cycle, there is no support at | |
* the moment for the streaming endpoint as we believe | |
* it would not make sens to block the page drawing | |
* cycle by opening a streaming connection. | |
* | |
* Please let us know what you think | |
*/ | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from teleportd import Teleportd | |
teleportd = Teleportd('_YOUR_USER_KEY_') | |
# The sha identifier of the picture to retrieve | |
sha = {'sha': '12-07-20-98a3b3fdd9b190ef4484a06a76fc1009c03076c5'} | |
# Performs a GET request to retrieve the picture matching the sha | |
search = teleportd.get(sha) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from teleportd import Teleportd | |
teleportd = Teleportd('_YOUR_USER_KEY_') | |
# The search spec as a dictionary | |
spec = {'loc': [137.77, -122.43, 0.2, 0.4], | |
'str': 'Golden Gate Bridge', | |
'period': [1342534945000, 1342621345000], | |
'from': 20, | |
'size': 40} | |
# Performs a GET request to retrieve the picture matching the spec | |
search = teleportd.search(spec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from teleportd import Teleportd | |
teleportd = Teleportd('_YOUR_USER_KEY_') | |
# Callback function handling | |
# each JSON object received | |
def callback(data): | |
print data | |
# Starts a stream | |
stream = teleportd.stream({}, callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment