Created
June 8, 2012 04:05
-
-
Save bugcloud/2893508 to your computer and use it in GitHub Desktop.
on{X}でロック解除時にランダムにGlitch画像を取得するアレ
This file contains 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
class Tumblr | |
constructor: () -> | |
@offset = Math.floor(Math.random() * 10) | |
apiConsumerKey: "YOUR_KEY" | |
hostName: "glitchgifs.tumblr.com" | |
offset: 0 | |
photoPostsCallback: (body, textStatus, response) -> | |
data = JSON.parse(body) | |
srcs = [] | |
for post in data.response.posts | |
for photo in post.photos | |
srcs.push photo.original_size.url | |
rmd = Math.floor(Math.random() * data.response.posts.length) | |
url = srcs[rmd] | |
notification = device.notifications.createNotification("I've got a glitch GIF!") | |
notification.content = "Click to see: [#{url}]" | |
notification.on 'click', () -> | |
device.browser.showOverlay url | |
notification.show() | |
photoPostsBefore: () -> | |
photoPosts: () -> | |
_that = this | |
_that.photoPostsBefore() | |
params = | |
url: "http://api.tumblr.com/v2/blog/#{@hostName}/posts/photo?api_key=#{@apiConsumerKey}&offset=#{@offset}" | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
onSuccess = (body, textStatus, response) -> | |
_that.photoPostsCallback(body, textStatus, response) | |
onError = (textStatus, response) -> | |
device.notifications.createNotification(textStatus).show() | |
console.error textStatus | |
console.error response | |
device.ajax params, onSuccess, onError | |
device.screen.on "unlock", () -> | |
_tumblr = new Tumblr() | |
_tumblr.photoPosts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Generated by CoffeeScript 1.3.3
var Tumblr;
Tumblr = (function() {
function Tumblr() {
this.offset = Math.floor(Math.random() * 10);
}
Tumblr.prototype.apiConsumerKey = "YOUR_KEY";
Tumblr.prototype.hostName = "glitchgifs.tumblr.com";
Tumblr.prototype.offset = 0;
Tumblr.prototype.photoPostsCallback = function(body, textStatus, response) {
var data, notification, photo, post, rmd, srcs, url, _i, _j, _len, _len1, _ref, _ref1;
data = JSON.parse(body);
srcs = [];
_ref = data.response.posts;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
post = _ref[_i];
_ref1 = post.photos;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
photo = _ref1[_j];
srcs.push(photo.original_size.url);
}
}
rmd = Math.floor(Math.random() * data.response.posts.length);
url = srcs[rmd];
notification = device.notifications.createNotification("I've got a glitch GIF!");
notification.content = "Click to see: [" + url + "]";
notification.on('click', function() {
return device.browser.showOverlay(url);
});
return notification.show();
};
Tumblr.prototype.photoPostsBefore = function() {};
Tumblr.prototype.photoPosts = function() {
var onError, onSuccess, params, _that;
_that = this;
_that.photoPostsBefore();
params = {
url: "http://api.tumblr.com/v2/blog/" + this.hostName + "/posts/photo?api_key=" + this.apiConsumerKey + "&offset=" + this.offset,
headers: {
'Content-Type': 'application/json'
}
};
onSuccess = function(body, textStatus, response) {
return _that.photoPostsCallback(body, textStatus, response);
};
onError = function(textStatus, response) {
device.notifications.createNotification(textStatus).show();
console.error(textStatus);
return console.error(response);
};
return device.ajax(params, onSuccess, onError);
};
return Tumblr;
})();
device.screen.on("unlock", function() {
var _tumblr;
_tumblr = new Tumblr();
return _tumblr.photoPosts();
});