added instagram

This commit is contained in:
Jeena Paradies 2012-10-11 18:29:45 +02:00
parent 672a345396
commit 3cc362f1d5
2 changed files with 127 additions and 37 deletions

View file

@ -22,6 +22,9 @@
1F70619F1178FBB300C85707 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F70619E1178FBB300C85707 /* Carbon.framework */; }; 1F70619F1178FBB300C85707 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F70619E1178FBB300C85707 /* Carbon.framework */; };
1F77DB47118C5F1C007C7F1E /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F77DB46118C5F1C007C7F1E /* Constants.m */; }; 1F77DB47118C5F1C007C7F1E /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F77DB46118C5F1C007C7F1E /* Constants.m */; };
1F98DC9E124BFFD7004289ED /* pin.png in Resources */ = {isa = PBXBuildFile; fileRef = 1F98DC9D124BFFD7004289ED /* pin.png */; }; 1F98DC9E124BFFD7004289ED /* pin.png in Resources */ = {isa = PBXBuildFile; fileRef = 1F98DC9D124BFFD7004289ED /* pin.png */; };
1FA09845144600C20079E258 /* RegexKitLite.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FA09844144600C20079E258 /* RegexKitLite.m */; };
1FA09847144602530079E258 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FA09846144602530079E258 /* libicucore.dylib */; };
1FA0984A144606D60079E258 /* NewTweetTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FA09849144606D60079E258 /* NewTweetTextView.m */; };
1FC254941427BC050035D84B /* index_oauth.html in Resources */ = {isa = PBXBuildFile; fileRef = 1FC254931427BC050035D84B /* index_oauth.html */; }; 1FC254941427BC050035D84B /* index_oauth.html in Resources */ = {isa = PBXBuildFile; fileRef = 1FC254931427BC050035D84B /* index_oauth.html */; };
1FC254951427BF150035D84B /* TwittiaOauth.js in Resources */ = {isa = PBXBuildFile; fileRef = 1FC254911427ADF90035D84B /* TwittiaOauth.js */; }; 1FC254951427BF150035D84B /* TwittiaOauth.js in Resources */ = {isa = PBXBuildFile; fileRef = 1FC254911427ADF90035D84B /* TwittiaOauth.js */; };
1FC2549F1427DC7F0035D84B /* Constants.js in Resources */ = {isa = PBXBuildFile; fileRef = 1FC2549D1427DC2B0035D84B /* Constants.js */; }; 1FC2549F1427DC7F0035D84B /* Constants.js in Resources */ = {isa = PBXBuildFile; fileRef = 1FC2549D1427DC2B0035D84B /* Constants.js */; };
@ -79,6 +82,11 @@
1F77DB45118C5F1C007C7F1E /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = "<group>"; }; 1F77DB45118C5F1C007C7F1E /* Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Constants.h; sourceTree = "<group>"; };
1F77DB46118C5F1C007C7F1E /* Constants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Constants.m; sourceTree = "<group>"; }; 1F77DB46118C5F1C007C7F1E /* Constants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Constants.m; sourceTree = "<group>"; };
1F98DC9D124BFFD7004289ED /* pin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pin.png; sourceTree = "<group>"; }; 1F98DC9D124BFFD7004289ED /* pin.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = pin.png; sourceTree = "<group>"; };
1FA09843144600C20079E258 /* RegexKitLite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegexKitLite.h; sourceTree = "<group>"; };
1FA09844144600C20079E258 /* RegexKitLite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RegexKitLite.m; sourceTree = "<group>"; };
1FA09846144602530079E258 /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; };
1FA09848144606D60079E258 /* NewTweetTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewTweetTextView.h; sourceTree = "<group>"; };
1FA09849144606D60079E258 /* NewTweetTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewTweetTextView.m; sourceTree = "<group>"; };
1FC254911427ADF90035D84B /* TwittiaOauth.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = TwittiaOauth.js; sourceTree = "<group>"; }; 1FC254911427ADF90035D84B /* TwittiaOauth.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = TwittiaOauth.js; sourceTree = "<group>"; };
1FC254931427BC050035D84B /* index_oauth.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index_oauth.html; sourceTree = "<group>"; }; 1FC254931427BC050035D84B /* index_oauth.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index_oauth.html; sourceTree = "<group>"; };
1FC2549A1427D9930035D84B /* AccessToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessToken.h; sourceTree = "<group>"; }; 1FC2549A1427D9930035D84B /* AccessToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessToken.h; sourceTree = "<group>"; };
@ -111,6 +119,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
1FA09847144602530079E258 /* libicucore.dylib in Frameworks */,
8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */, 8D15AC340486D014006FF6A4 /* Cocoa.framework in Frameworks */,
1FFA37071177DAF4006C8562 /* WebKit.framework in Frameworks */, 1FFA37071177DAF4006C8562 /* WebKit.framework in Frameworks */,
1F70619F1178FBB300C85707 /* Carbon.framework in Frameworks */, 1F70619F1178FBB300C85707 /* Carbon.framework in Frameworks */,
@ -177,6 +186,7 @@
2A37F4AAFDCFA73011CA2CEA /* Twittia 2 */ = { 2A37F4AAFDCFA73011CA2CEA /* Twittia 2 */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
1FA09846144602530079E258 /* libicucore.dylib */,
2A37F4ABFDCFA73011CA2CEA /* Classes */, 2A37F4ABFDCFA73011CA2CEA /* Classes */,
2A37F4AFFDCFA73011CA2CEA /* Other Sources */, 2A37F4AFFDCFA73011CA2CEA /* Other Sources */,
2A37F4B8FDCFA73011CA2CEA /* Resources */, 2A37F4B8FDCFA73011CA2CEA /* Resources */,
@ -189,12 +199,16 @@
2A37F4ABFDCFA73011CA2CEA /* Classes */ = { 2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
1FA09843144600C20079E258 /* RegexKitLite.h */,
1FA09844144600C20079E258 /* RegexKitLite.m */,
1FFA36D21177D879006C8562 /* Controller.h */, 1FFA36D21177D879006C8562 /* Controller.h */,
1FFA36D31177D879006C8562 /* Controller.m */, 1FFA36D31177D879006C8562 /* Controller.m */,
1FFA36D41177D879006C8562 /* ViewDelegate.h */, 1FFA36D41177D879006C8562 /* ViewDelegate.h */,
1FFA36D51177D879006C8562 /* ViewDelegate.m */, 1FFA36D51177D879006C8562 /* ViewDelegate.m */,
2A37F4AEFDCFA73011CA2CEA /* NewTweetWindow.h */, 2A37F4AEFDCFA73011CA2CEA /* NewTweetWindow.h */,
2A37F4ACFDCFA73011CA2CEA /* NewTweetWindow.m */, 2A37F4ACFDCFA73011CA2CEA /* NewTweetWindow.m */,
1FA09848144606D60079E258 /* NewTweetTextView.h */,
1FA09849144606D60079E258 /* NewTweetTextView.m */,
1F77DB45118C5F1C007C7F1E /* Constants.h */, 1F77DB45118C5F1C007C7F1E /* Constants.h */,
1F77DB46118C5F1C007C7F1E /* Constants.m */, 1F77DB46118C5F1C007C7F1E /* Constants.m */,
1F618EC812DB5E6100E500D9 /* TweetModel.h */, 1F618EC812DB5E6100E500D9 /* TweetModel.h */,
@ -269,7 +283,7 @@
2A37F4A9FDCFA73011CA2CEA /* Project object */ = { 2A37F4A9FDCFA73011CA2CEA /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastUpgradeCheck = 0410; LastUpgradeCheck = 0420;
}; };
buildConfigurationList = C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "Twittia 2" */; buildConfigurationList = C05733CB08A9546B00998B17 /* Build configuration list for PBXProject "Twittia 2" */;
compatibilityVersion = "Xcode 3.2"; compatibilityVersion = "Xcode 3.2";
@ -332,6 +346,8 @@
1FFA36D81177D879006C8562 /* ViewDelegate.m in Sources */, 1FFA36D81177D879006C8562 /* ViewDelegate.m in Sources */,
1F77DB47118C5F1C007C7F1E /* Constants.m in Sources */, 1F77DB47118C5F1C007C7F1E /* Constants.m in Sources */,
1F618ECA12DB5E6100E500D9 /* TweetModel.m in Sources */, 1F618ECA12DB5E6100E500D9 /* TweetModel.m in Sources */,
1FA09845144600C20079E258 /* RegexKitLite.m in Sources */,
1FA0984A144606D60079E258 /* NewTweetTextView.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View file

@ -7,15 +7,23 @@
// //
function Twittia(action) { function Twittia(action) {
this.max_length = 100; this.max_length = 100;
this.since_id; this.since_id;
this.timeout = 2 * 60 * 1000; this.timeout = 2 * 60 * 1000;
this.action = action; this.action = action;
this.getNewData(); this.getNewData();
this.unread_mentions = 0; this.unread_mentions = 0;
this.body = document.createElement("ol"); this.body = document.createElement("ol");
this.body.className = this.action; this.body.className = this.action;
/*
if (action == "home_timeline") {
this.usernames = [];
this.getUsernames("friends");
this.getUsernames("followers");
}
*/
} }
Twittia.prototype.newStatus = function(status, supress_new_with_timeout) { Twittia.prototype.newStatus = function(status, supress_new_with_timeout) {
@ -106,6 +114,7 @@ Twittia.prototype.getItem = function(status) {
if(media.type == "photo") { if(media.type == "photo") {
var a = document.createElement("a"); var a = document.createElement("a");
a.href = media.media_url; a.href = media.media_url;
alert(a.href)
var img = document.createElement("img"); var img = document.createElement("img");
img.className = "photo"; img.className = "photo";
@ -243,7 +252,6 @@ Twittia.prototype.getTemplate = function() {
return jQuery.extend(true, {}, this.template); return jQuery.extend(true, {}, this.template);
} }
Twittia.prototype.getNewData = function(supress_new_with_timeout) { Twittia.prototype.getNewData = function(supress_new_with_timeout) {
var url = API_PATH + "statuses/" + this.action + ".json" var url = API_PATH + "statuses/" + this.action + ".json"
@ -352,6 +360,89 @@ Twittia.prototype.retweet = function(status_id, item) {
}); });
} }
Twittia.prototype.getUsernames = function(type, cursor) {
cursor = typeof cursor == "undefined" ? -1 : cursor;
var url = API_PATH + type + "/ids.json";
var _this = this;
var parameters = { stringify_ids: "true", cursor:cursor };
var message = { method:"GET" , action:url, parameters:parameters };
OAuth.completeRequest(message,
{ consumerKey : OAUTH_CONSUMER_KEY
, consumerSecret: OAUTH_CONSUMER_SECRET
, token : controller.accessToken.accessToken()
, tokenSecret : controller.accessToken.secret()
});
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", OAuth.getAuthorizationHeader("", message.parameters));
},
url: url + "?stringify_ids=true&cursor=" + cursor ,
type: 'GET',
dataType: 'json',
success: function(data) {
for (var i=0; i < data.ids.length; i = i + 100) {
_this.getUsernamesFromIds(data.ids.slice(i, i + 100));
}
if (data.next_cursor > 0) {
_this.getUsernames(type, data.next_cursor);
}
},
error:function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
Twittia.prototype.getUsernamesFromIds = function(ids) {
var url = API_PATH + "users/lookup.json";
var _this = this;
var parameters = { user_id:ids.join(",") };
var message = { method:"GET" , action:url, parameters:parameters };
OAuth.completeRequest(message,
{ consumerKey : OAUTH_CONSUMER_KEY
, consumerSecret: OAUTH_CONSUMER_SECRET
, token : controller.accessToken.accessToken()
, tokenSecret : controller.accessToken.secret()
});
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", OAuth.getAuthorizationHeader("", message.parameters));
},
url: url + "?user_id=" + ids.join(","),
type: 'GET',
dataType: 'json',
success: function(data) {
for (var i=0; i < data.length; i++) {
_this.usernames.push(data[i].screen_name);
}
},
error:function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
Twittia.prototype.findUsernamesFor = function(query) {
var ret = [];
for (var i=0; i < this.usernames.length; i++) {
if(this.usernames[i].startsWith(query)) {
ret.push(this.usernames[i]);
}
}
return ret;
}
/* Helper functions */
function replaceURLWithHTMLLinks(text, entities, message_node) { function replaceURLWithHTMLLinks(text, entities, message_node) {
var urls = entities.urls; var urls = entities.urls;
@ -368,6 +459,7 @@ function replaceURLWithHTMLLinks(text, entities, message_node) {
var media = null; var media = null;
// add thumbnail
if(replace.startsWith("http://youtube.com/") || replace.startsWith("http://www.youtube.com/")) { if(replace.startsWith("http://youtube.com/") || replace.startsWith("http://www.youtube.com/")) {
var v = getUrlVars(replace)["v"]; var v = getUrlVars(replace)["v"];
if (v) { if (v) {
@ -391,6 +483,13 @@ function replaceURLWithHTMLLinks(text, entities, message_node) {
url: original, url: original,
media_url: replace + ":small" media_url: replace + ":small"
} }
} else if (replace.startsWith("http://instagr.am/p/") || replace.startsWith("http://instagram.com/p/")) {
media = {
type: "twittia_photo",
url: original,
media_url: replace + "media?size=t"
}
} }
if(media) { if(media) {
@ -469,30 +568,5 @@ function replaceShortened(url, message_node) {
} }
}); });
} }
/*
function replaceFlickrThumbnail(url, message_node) {
var flickr_id = "6154030877";
var api_url = "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=1f3f2fc4474854c8e86618c0ae9368bd&photo_id=" + flickr_id + "&format=json&nojsoncallback=1";
$.ajax({
url: api_url,
success: function(data) {
var new_url;
for(var size in data.sizes.size) {
if(size.label == "Thumbnail") {
new_url = size.source;
}
}
if (new_url) {
$("<img/>").attr("src", src).appendTo($(message_node));
}
},
error:function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
*/
var twittia_instance; var twittia_instance;