Created
August 7, 2008 14:55
-
-
Save cho45/4419 to your computer and use it in GitHub Desktop.
ダイアリの編集API適当にたたく
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
var url = "http://cho45.g.hatena.ne.jp/cho45/"; | |
var s = {}; | |
next(function getRkm () { | |
return xhttp.get(url). | |
next(function (r) { | |
s.rkm = r.responseText.replace(/^[\S\s]*Hatena\.rkm\s*=\s*(?:'([^']+)'|"([^"]+)")[\S\s]*$/, function (_, v1, v2) { | |
return v1 || v2; | |
}); | |
}); | |
}). | |
next(function postDiary () { | |
log(s.rkm); | |
return xhttp.post(url, toData({ | |
entry_key : "new", | |
rkm : s.rkm, | |
title : "[test] xhr", | |
body : "test" | |
})); | |
function toData (q) { | |
var ret = []; | |
for (var k in q) if (q.hasOwnProperty(k)) { | |
ret.push(encodeURIComponent(k) + "=" + encodeURIComponent(q[k])); | |
} | |
return ret.join("&"); | |
} | |
}). | |
error(function (e) { | |
alert(e); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment