Last active
January 3, 2016 18:59
-
-
Save siyo/8505293 to your computer and use it in GitHub Desktop.
pebbleのsimplyjsを使って俳句を読む奴
http://simplyjs.meiguro.com/
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 config = require('config.js'), | |
twitter = require('twitter.js'); | |
twitter.initialize(config.twitter); | |
simply.text({ | |
title: 'Haiku tweet', | |
subtitle: 'press select button', | |
body: 'powered by http://haiku.jgate.de/' | |
}, true); | |
simply.on('singleClick', function(e) { | |
// ruby: 'ここで一句、'.codepoints.collect{|cp| "\\u%04X" % [cp]}.join | |
var prefix = '\u3053\u3053\u3067\u4E00\u53E5\u3001', | |
suffix = ' #pebble #simplyjs'; | |
var onSuccess = function(data) { | |
var status = prefix + data + suffix; | |
var fn = function(req) { | |
simply.text({ | |
subtitle: 'http status:' + req.status, | |
body: JSON.stringify(req.responseText) | |
}); | |
}; | |
twitter.updateStatus(status, fn, fn); | |
}; | |
var onFailure = function(body, status) { | |
simply.text({ | |
title: 'Haiku failure', | |
subtitle: 'status:' + status, | |
body: body | |
}); | |
}; | |
switch (e.button) { | |
case 'select': | |
ajax({ | |
url: 'http://haiku.jgate.de/' | |
}, onSuccess, onFailure); | |
break; | |
} | |
}); |
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 config = { | |
twitter: { | |
consumerKey: 'XXXXXXXXXXXXXXXX', | |
consumerSecret: 'XXXXXXXXXXXXXXXX', | |
token: 'XXXXXXXXXXXXXXXX', | |
tokenSecret: 'XXXXXXXXXXXXXXXX' | |
} | |
}; | |
return config; |
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
// dependencies | |
// http://oauth.googlecode.com/svn/code/javascript/ | |
// - oauth.js | |
// - sha1.js | |
var oauth = require('oauth.js'); | |
var twitter = twitter || (function() { | |
var URL = 'https://api.twitter.com/1.1'; | |
return { | |
initialize: function(config) { | |
this._accessor = config; | |
}, | |
updateStatus: function(status, success, error) { | |
var url = URL + '/statuses/update.json', | |
parameters = [], | |
req, message, requestBody, realm = ''; | |
parameters.push(['status', status]); | |
message = { | |
'method': 'POST', | |
'action': url, | |
'parameters': parameters | |
}; | |
requestBody = oauth.formEncode(message.parameters); | |
oauth.completeRequest(message, this._accessor); | |
req = new XMLHttpRequest(); | |
req.open(message.method, message.action, true); | |
req.setRequestHeader( | |
'Authorization', | |
oauth.getAuthorizationHeader(realm, message.parameters) | |
); | |
req.setRequestHeader( | |
'Content-Type', | |
'application/x-www-form-urlencoded;charset=UTF-8' | |
); | |
req.onreadystatechange = function() { | |
if (req.readyState != 4) | |
return; | |
if (req.status == 200) { | |
if (success) | |
success(req); | |
} else { | |
if (error) | |
error(req); | |
} | |
}; | |
req.send(requestBody); | |
} | |
}; | |
})(); | |
return twitter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment