api calls

This commit is contained in:
Jeena Paradies 2013-05-26 09:51:01 +02:00
parent 422dbd34ff
commit f73ce7d196
10 changed files with 371 additions and 86 deletions

View file

@ -1,11 +1,11 @@
define([
"helper/HostApp",
"helper/Core",
"helper/Paths",
"helper/APICalls",
"lib/URI"
],
function(HostApp, Core, Paths, URI) {
function(HostApp, Core, APICalls, URI) {
function Conversation(standalone) {
@ -86,15 +86,15 @@ function(HostApp, Core, Paths, URI) {
function getRemoteStatus(profile) {
var server = profile["https://tent.io/types/info/core/v0.1.0"].servers[0];
Paths.getURL(URI(server + "/posts/" + id).toString(), "GET", callback, null, false);
APICalls.http_call(URI(server + "/posts/" + id).toString(), "GET", callback, null, false);
}
var profile = this.cache.profiles.getItem(entity);
if (entity == HostApp.stringForKey("entity")) {
var url = URI(Paths.mkApiRootPath("/posts/" + id));
Paths.getURL(url.toString(), "GET", callback, null);
var url = URI(APICalls.mkApiRootPath("/posts/" + id));
APICalls.http_call(url.toString(), "GET", callback, null);
} else if(profile) {
@ -102,7 +102,7 @@ function(HostApp, Core, Paths, URI) {
} else {
Paths.findProfileURL(entity, function(profile_url) {
APICalls.findProfileURL(entity, function(profile_url) {
if (profile_url) {
@ -113,7 +113,7 @@ function(HostApp, Core, Paths, URI) {
} else {
Paths.getURL(profile_url, "GET", function(resp) {
APICalls.http_call(profile_url, "GET", function(resp) {
var profile = JSON.parse(resp.responseText)
this.cache.profiles.setItem(entity, profile);
@ -128,7 +128,7 @@ function(HostApp, Core, Paths, URI) {
Conversation.prototype.appendMentioned = function(id, entity, node) {
var url = URI(Paths.mkApiRootPath("/posts"));
var url = URI(APICalls.mkApiRootPath("/posts"));
url.addSearch("mentioned_post", id);
url.addSearch("post_types", "https%3A%2F%2Ftent.io%2Ftypes%2Fpost%2Fstatus%2Fv0.1.0");
@ -147,7 +147,7 @@ function(HostApp, Core, Paths, URI) {
}
}
Paths.getURL(url.toString(), "GET", callback);
APICalls.http_call(url.toString(), "GET", callback);
}

View file

@ -2,11 +2,11 @@ define([
"helper/HostApp",
"controller/Timeline",
"lib/URI",
"helper/Paths",
"helper/APICalls",
"helper/Core"
],
function(HostApp, Timeline, URI, Paths, Core) {
function(HostApp, Timeline, URI, APICalls, Core) {
function Mentions() {
@ -90,7 +90,7 @@ function(HostApp, Timeline, URI, Paths, Core) {
if (!status.__repost) {
if (status && status.type == "https://tent.io/types/post/status/v0.1.0") {
var url = URI(Paths.mkApiRootPath("/profile/" + encodeURIComponent("https://tent.io/types/info/cursor/v0.1.0")));
var url = URI(APICalls.mkApiRootPath("/profile/" + encodeURIComponent("https://tent.io/types/info/cursor/v0.1.0")));
var body = {
"mentions": {
"https://tent.io/types/post/status/v0.1.0": {
@ -104,7 +104,7 @@ function(HostApp, Timeline, URI, Paths, Core) {
}
Paths.getURL(url.toString(), "PUT", callback, JSON.stringify(body));
APICalls.http_call(url.toString(), "PUT", callback, JSON.stringify(body));
}
break;
@ -115,11 +115,11 @@ function(HostApp, Timeline, URI, Paths, Core) {
Mentions.prototype.getLatestMentionRead = function() {
var cursor_url = URI(Paths.mkApiRootPath("/profile/" + encodeURIComponent("https://tent.io/types/info/cursor/v0.1.0")));
var cursor_url = URI(APICalls.mkApiRootPath("/profile/" + encodeURIComponent("https://tent.io/types/info/cursor/v0.1.0")));
Paths.getURL(cursor_url.toString(), "GET", function(resp) {
APICalls.http_call(cursor_url.toString(), "GET", function(resp) {
var url = URI(Paths.mkApiRootPath("/posts/count"));
var url = URI(APICalls.mkApiRootPath("/posts/count"));
var post_types = [
"https://tent.io/types/post/status/v0.1.0",
];
@ -139,7 +139,7 @@ function(HostApp, Timeline, URI, Paths, Core) {
HostApp.unreadMentions(this.unread_mentions);
}
Paths.getURL(url.toString(), "GET", callback); // FIXME: error callback
APICalls.http_call(url.toString(), "GET", callback); // FIXME: error callback
});
}

View file

@ -1,10 +1,10 @@
define([
"helper/HostApp",
"helper/Paths",
"helper/APICalls",
"helper/Hmac"
],
function(HostApp, Paths, Hmac) {
function(HostApp, APICalls, Hmac) {
function Oauth() {
this.app_info = {
@ -70,7 +70,7 @@ function(HostApp, Paths, Hmac) {
Oauth.prototype.requestProfileURL = function (entity) {
var those = this;
Paths.findProfileURL(entity,
APICalls.findProfileURL(entity,
function(profile_url) {
if (profile_url && (profile_url.startsWith("http://") || profile_url.startsWith("https://"))) {
those.register(profile_url);
@ -87,7 +87,7 @@ function(HostApp, Paths, Hmac) {
Oauth.prototype.register = function (url) {
var those = this;
Paths.getURL(url, "GET", function(resp) {
APICalls.get(url, { callback: function(resp) {
those.profile = JSON.parse(resp.responseText);
those.entity = those.profile.content.entity;
@ -98,16 +98,16 @@ function(HostApp, Paths, Hmac) {
var app_id = JSON.parse(resp.responseText).id;
var header_string = resp.getAllResponseHeaders();
var regexp = /https:\/\/tent.io\/rels\/credentials/i
var url = Paths.parseHeaderForLink(header_string, regexp);
Paths.getURL(url, "GET", function(resp) {
var url = APICalls.parseHeaderForLink(header_string, regexp);
APICalls.http_call(url, "GET", function(resp) {
var data = JSON.parse(resp.responseText);
those.authRequest(data, app_id);
}, null, false)
}
Paths.getURL(HostApp.serverUrl("new_post"), "POST", callback, JSON.stringify(those.app_info), false);
APICalls.post(HostApp.serverUrl("new_post"), JSON.stringify(those.app_info), {callback: callback});
}, null, false);
}});
}
Oauth.prototype.authRequest = function(credentials, app_id) {
@ -126,7 +126,7 @@ function(HostApp, Paths, Hmac) {
// /oauthtoken?code=51d0115b04d1ed94001dde751c5b360f&state=aQfH1VEohYsQr86qqyv
// https://app.example.com/oauth?code=K4m2J2bGI9rcICBqmUCYuQ&state=d173d2bb868a
var urlVars = Paths.getUrlVars(responseBody);
var urlVars = APICalls.getUrlVars(responseBody);
if(this.state && this.state != "" && urlVars["state"] == this.state) {
var url = HostApp.serverUrl("oauth_token");
@ -150,7 +150,7 @@ function(HostApp, Paths, Hmac) {
requestBody
);
Paths.getURL(url, http_method, callback, requestBody, auth_header);
APICalls.http_call(url, http_method, callback, requestBody, auth_header);
} else {
console.error("State is not the same: {" + this.state + "} vs {" + urlVars["state"] + "}")
@ -174,7 +174,7 @@ function(HostApp, Paths, Hmac) {
Oauth.prototype.logout = function() {
var url = Paths.mkApiRootPath("/apps/" + HostApp.stringForKey("app_id"));
var url = APICalls.mkApiRootPath("/apps/" + HostApp.stringForKey("app_id"));
var http_method = "DELETE";
var auth_header = Hmac.makeAuthHeader(
url,
@ -183,7 +183,7 @@ function(HostApp, Paths, Hmac) {
HostApp.stringForKey("app_mac_key_id")
);
Paths.getURL(url, http_method, function(resp) {
APICalls.http_call(url, http_method, function(resp) {
HostApp.setStringForKey(null, "app_mac_key");
HostApp.setStringForKey(null, "app_mac_key_id");
HostApp.setStringForKey(null, "app_id");

View file

@ -1,11 +1,11 @@
define([
"helper/HostApp",
"helper/Core",
"helper/Paths",
"helper/APICalls",
"lib/URI"
],
function(HostApp, Core, Paths, URI) {
function(HostApp, Core, APICalls, URI) {
function Profile() {
@ -239,11 +239,11 @@ function(HostApp, Core, Paths, URI) {
this.profile = profile;
} else {
Paths.findProfileURL(this.entity, function(profile_url) {
APICalls.findProfileURL(this.entity, function(profile_url) {
if (profile_url) {
Paths.getURL(profile_url, "GET", function(resp) {
APICalls.http_call(profile_url, "GET", function(resp) {
profile = JSON.parse(resp.responseText);
_this.showProfile(profile);
@ -258,9 +258,9 @@ function(HostApp, Core, Paths, URI) {
Profile.prototype.getFollowing = function() {
if(this.entity != HostApp.stringForKey("entity")) {
var url = Paths.mkApiRootPath("/followings") + "/" + encodeURIComponent(this.entity);
var url = APICalls.mkApiRootPath("/followings") + "/" + encodeURIComponent(this.entity);
var _this = this;
Paths.getURL(url, "GET", function(resp) {
APICalls.http_call(url, "GET", function(resp) {
if (resp.status >= 200 && resp.status < 400) {
var following = JSON.parse(resp.responseText);
_this.following_id = following.id
@ -325,18 +325,18 @@ function(HostApp, Core, Paths, URI) {
Profile.prototype.getMeta = function(root_url) {
var _this = this;
Paths.getURL(URI(root_url + "/followings/count").toString(), "GET", function(resp) {
APICalls.http_call(URI(root_url + "/followings/count").toString(), "GET", function(resp) {
_this.populate(_this.profile_template.following, resp.responseText);
}, null, false);
Paths.getURL(URI(root_url + "/followers/count").toString(), "GET", function(resp) {
APICalls.http_call(URI(root_url + "/followers/count").toString(), "GET", function(resp) {
_this.populate(_this.profile_template.followed, resp.responseText);
}, null, false);
if (this.entity != HostApp.stringForKey("entity")) {
Paths.getURL(URI(root_url + "/followers/" + encodeURIComponent(HostApp.stringForKey("entity"))).toString(), "GET", function(resp) {
APICalls.http_call(URI(root_url + "/followers/" + encodeURIComponent(HostApp.stringForKey("entity"))).toString(), "GET", function(resp) {
if (resp.status == 200) {
_this.relationships.following_you = true;
}
@ -344,7 +344,7 @@ function(HostApp, Core, Paths, URI) {
}, null, false);
Paths.getURL(URI(Paths.mkApiRootPath("/followings/" + encodeURIComponent(this.entity))), "GET", function(resp) {
APICalls.http_call(URI(APICalls.mkApiRootPath("/followings/" + encodeURIComponent(this.entity))), "GET", function(resp) {
if (resp.status == 200) {
_this.relationships.followed_by_you = true;
}
@ -363,7 +363,7 @@ function(HostApp, Core, Paths, URI) {
];
url.addSearch("post_types", post_types.join(","));
Paths.getURL(url.toString(), "GET", function(resp) {
APICalls.http_call(url.toString(), "GET", function(resp) {
_this.populate(_this.profile_template.posts, resp.responseText);
}, null, false);
@ -405,7 +405,7 @@ function(HostApp, Core, Paths, URI) {
url.addSearch(key, add_search[key]);
}
Paths.getURL(url.toString(), "GET", function(resp) {
APICalls.http_call(url.toString(), "GET", function(resp) {
var statuses = JSON.parse(resp.responseText);
@ -495,8 +495,8 @@ function(HostApp, Core, Paths, URI) {
if (this.following_id) {
this.setFollowingButton(false);
var url = Paths.mkApiRootPath("/followings/") + this.following_id;
Paths.getURL(url, "DELETE", function(resp) {
var url = APICalls.mkApiRootPath("/followings/") + this.following_id;
APICalls.http_call(url, "DELETE", function(resp) {
if (resp.status >= 200 && resp.status < 300) {
_this.setFollowingButton(false);
_this.following_id = null;
@ -508,10 +508,10 @@ function(HostApp, Core, Paths, URI) {
} else {
this.setFollowingButton(true);
var url = URI(Paths.mkApiRootPath("/followings"));
var url = URI(APICalls.mkApiRootPath("/followings"));
var data = JSON.stringify({"entity": this.entity });
Paths.getURL(url.toString(), "POST", function(resp) {
APICalls.http_call(url.toString(), "POST", function(resp) {
if (resp.status >= 200 && resp.status < 300) {
_this.following_id = JSON.parse(resp.responseText).id
_this.setFollowingButton(true);
@ -542,7 +542,7 @@ function(HostApp, Core, Paths, URI) {
var url = URI(this.server + "/followings");
url.addSearch("limit", 200);
Paths.getURL(url.toString(), "GET", callback, null, false);
APICalls.http_call(url.toString(), "GET", callback, null, false);
}
Profile.prototype.showFollowers = function() {
@ -561,7 +561,7 @@ function(HostApp, Core, Paths, URI) {
var url = URI(this.server + "/followers");
url.addSearch("limit", 200);
Paths.getURL(url.toString(), "GET", callback, null, false);
APICalls.http_call(url.toString(), "GET", callback, null, false);
}
Profile.prototype.getDOMSmallProfile = function(profile) {
@ -643,10 +643,10 @@ function(HostApp, Core, Paths, URI) {
} else {
var _this = this;
Paths.findProfileURL(profile.entity, function(profile_url) {
APICalls.findProfileURL(profile.entity, function(profile_url) {
if (profile_url) {
Paths.getURL(profile_url, "GET", function(resp) {
APICalls.http_call(profile_url, "GET", function(resp) {
var p = JSON.parse(resp.responseText);
if (p && p != "null") {
_this.cache.profiles.setItem(profile.entity, p);

View file

@ -1,11 +1,11 @@
define([
"helper/HostApp",
"helper/Core",
"helper/Paths",
"helper/APICalls",
"lib/URI"
],
function(HostApp, Core, Paths, URI) {
function(HostApp, Core, APICalls, URI) {
function Search() {
@ -79,7 +79,7 @@ function(HostApp, Core, Paths, URI) {
var _this = this;
Paths.getURL(url.toString(), "GET", function(resp) {
APICalls.http_call(url.toString(), "GET", function(resp) {
var results = JSON.parse(resp.responseText).results;
if (results && results.length > 0) {

View file

@ -1,10 +1,10 @@
define([
"helper/HostApp",
"helper/Paths",
"helper/APICalls",
"helper/Cache"
],
function(HostApp, Paths, Cache) {
function(HostApp, APICalls, Cache) {
function Sidebar() {
@ -121,10 +121,10 @@ function(HostApp, Paths, Cache) {
} else {
Paths.findProfileURL(entity, function(profile_url) {
APICalls.findProfileURL(entity, function(profile_url) {
if (profile_url) {
Paths.getURL(profile_url, "GET", function(resp) {
APICalls.http_call(profile_url, "GET", function(resp) {
var p = JSON.parse(resp.responseText);
if (p && p != "null") {
_this.cache.profiles.setItem(entity, p);

View file

@ -1,11 +1,11 @@
define([
"helper/Core",
"helper/Paths",
"helper/APICalls",
"helper/HostApp",
"lib/URI"
],
function(Core, Paths, HostApp, URI) {
function(Core, APICalls, HostApp, URI) {
function Timeline() {
@ -100,7 +100,7 @@ function(Core, Paths, HostApp, URI) {
add_to_search = add_to_search || {};
var those = this;
var url = URI(Paths.mkApiRootPath("/posts"));
var url = URI(APICalls.mkApiRootPath("/posts"));
var post_types = [
"https://tent.io/types/post/repost/v0.1.0",
@ -143,7 +143,7 @@ function(Core, Paths, HostApp, URI) {
if (!this.reload_blocked) {
this.reload_blocked = true;
Paths.getURL(url.toString(), http_method, callback, data); // FIXME: error callback
APICalls.http_call(url.toString(), http_method, callback, data); // FIXME: error callback
}
}
}