Skip to content
This repository was archived by the owner on Nov 18, 2017. It is now read-only.

Commit 505c1e9

Browse files
initial commit
0 parents  commit 505c1e9

File tree

166 files changed

+6675
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+6675
-0
lines changed

README.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=============================================
2+
phnx - a twitter app
3+
=============================================
4+
5+
Author: David Strack
6+
Twitter: @rmxdave
7+
8+
Web: http://prettyappmachine.com
9+
10+
You may not reproduce any part of this application without written permission from the author.
11+
Viewing source code for educational purposes is permitted - as long as nothing is copied for use in
12+
another application.
13+
14+
Before you steal this app, remember that you are hurting a young developer and his family,
15+
not a large software company.
16+
17+
Copyright 2010 - 2011 David Strack (D.B.A. Pretty App Machine)

app/assistants/app-assistant.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function AppAssistant(){
2+
3+
}
4+
5+
AppAssistant.prototype = {
6+
7+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
function FinishAuthAssistant(r) {
2+
this.tokens = {oauth_token: "", oauth_token_secret: "", user_id: "", screen_name: ""};
3+
this.response = r.response;
4+
}
5+
FinishAuthAssistant.prototype = {
6+
setup: function(){
7+
this.listen();
8+
var tokens = this.response.strip().split("&");
9+
var i;
10+
for (i = 0; i < tokens.length; i++) {
11+
var token = tokens[i];
12+
if (token.substr(0, 12) === "oauth_token=") {
13+
this.tokens.oauth_token = token.substr(12);
14+
}
15+
else if (token.substr(0, 18) === "oauth_token_secret") {
16+
this.tokens.oauth_token_secret = token.substr(19);
17+
}
18+
else if (token.substr(0,8) === "user_id="){
19+
this.tokens.user_id = token.substr(8);
20+
}
21+
else if (token.substr(0,12) === "screen_name="){
22+
this.tokens.screen_name = token.substr(12);
23+
}
24+
}
25+
this.storeTokens();
26+
},
27+
storeTokens: function(){
28+
var u = {
29+
key: this.tokens.screen_name,
30+
id: this.tokens.user_id,
31+
username: this.tokens.screen_name,
32+
token: this.tokens.oauth_token,
33+
secret: this.tokens.oauth_token_secret
34+
};
35+
36+
currentUser = u;
37+
cachedUsers.push(u);
38+
var users = new Lawnchair("phoenixusers");
39+
users.save(u);
40+
//
41+
// Mojo.Controller.stageController.swapScene({
42+
// 'name': 'main',
43+
// transition: Mojo.Transition.crossFade
44+
// });
45+
},
46+
nextTapped: function(event){
47+
Mojo.Controller.stageController.swapScene({
48+
'name': 'main',
49+
transition: Mojo.Transition.crossFade,
50+
disableSceneScroller: true
51+
});
52+
},
53+
followTapped: function(event){
54+
var userId = event.currentTarget.id;
55+
var url = 'http://api.twitter.com/1/friendships/create.json';
56+
var message = {
57+
method: "POST",
58+
action: url,
59+
parameters: []
60+
};
61+
message.parameters.push(["screen_name", userId]);
62+
OAuth.completeRequest(message, {
63+
consumerKey: twitter.key,
64+
consumerSecret: twitter.secret,
65+
token: currentUser.token,
66+
tokenSecret: currentUser.secret
67+
});
68+
var authHeader = OAuth.getAuthorizationHeader('http://api.twitter.com', message.parameters);
69+
var request = new Ajax.Request(url, {
70+
method: "POST",
71+
requestHeaders: {
72+
Authorization: authHeader,
73+
Accept: 'application/json'
74+
},
75+
postBody: "screen_name=" + userId,
76+
onSuccess: function(transport){
77+
banner('Thanks for following!');
78+
},
79+
onFailure: function(transport){
80+
ex('Sadface! There was an error...');
81+
}
82+
});
83+
},
84+
listen: function(event){
85+
this.controller.listen('next', Mojo.Event.tap, this.nextTapped.bind(this));
86+
this.controller.listen('rmxdave', Mojo.Event.tap, this.followTapped.bind(this));
87+
this.controller.listen('phnxapp', Mojo.Event.tap, this.followTapped.bind(this));
88+
},
89+
cleanup: function(event){
90+
this.controller.stopListening('next', Mojo.Event.tap, this.nextTapped());
91+
this.controller.stopListening('rmxdave', Mojo.Event.tap, this.followTapped());
92+
this.controller.stopListening('phnxapp', Mojo.Event.tap, this.followTapped());
93+
}
94+
};

app/assistants/launch-assistant.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
function LaunchAssistant() {}
2+
3+
LaunchAssistant.prototype = {
4+
setup: function() {
5+
//$('version-info').update("Version " + Mojo.Controller.appInfo.version);
6+
var that = this;
7+
this.userCookie = new Mojo.Model.Cookie('phoenixFirstRun');
8+
this.themeCookie = new Mojo.Model.Cookie('phnxTheme');
9+
10+
//load the theme
11+
if (typeof(this.themeCookie.get()) !== "undefined"){
12+
$$('body')[0].addClassName(this.themeCookie.get().className);
13+
}
14+
else{
15+
$$('body')[0].addClassName('default');
16+
}
17+
18+
if (typeof(this.userCookie.get()) !== "undefined") {
19+
//using a regular cookie makes sure that the Lawnchair stores have been initialized
20+
setTimeout(function(){
21+
that.startApp();
22+
}, 1000);
23+
}else{
24+
//just create the cookie so it isn't null anymore
25+
this.userCookie.put({
26+
run: true
27+
});
28+
var user = new Lawnchair('phoenixusers'); //create the lawnchair stores
29+
var prefs = new Lawnchair('phoenixprefs');
30+
var timelines = new Lawnchair('phoenixtimelines');
31+
setTimeout(function(){
32+
that.controller.get("add-button").setStyle({"bottom":"0px"});
33+
}, 500);
34+
}
35+
},
36+
startApp: function(){
37+
var users = new Lawnchair('phoenixusers');
38+
var that = this;
39+
users.all(function(r){
40+
if (r.length === 0){
41+
var that = this;
42+
setTimeout(function(){
43+
that.controller.get("add-button").setStyle({"bottom":"0px"});
44+
}, 500);
45+
}else{
46+
currentUser = r[0];
47+
cachedUsers = r;
48+
Mojo.Controller.stageController.swapScene({
49+
'name': 'main',
50+
transition: Mojo.Transition.crossFade,
51+
disableSceneScroller: true
52+
});
53+
54+
}
55+
}.bind(this));
56+
},
57+
doOAuth: function() {
58+
this.visited = true;
59+
var oauthConfig={
60+
callbackScene:'finishAuth', //Name of the assistant to be called on the OAuth Success
61+
requestTokenUrl:'https://api.twitter.com/oauth/request_token',
62+
requestTokenMethod:'GET', // Optional - 'GET' by default if not specified
63+
authorizeUrl:'https://api.twitter.com/oauth/authorize',
64+
accessTokenUrl:'https://api.twitter.com/oauth/access_token',
65+
accessTokenMethod:'GET', // Optional - 'GET' by default if not specified
66+
consumer_key: twitter.key,
67+
consumer_key_secret: twitter.secret,
68+
callback:'http://www.google.com' // Optional - 'oob' by default if not specified
69+
};
70+
Mojo.Controller.stageController.swapScene('oauth',oauthConfig);
71+
},
72+
buttonTapped: function(event){
73+
this.doOAuth();
74+
},
75+
activate: function(event){
76+
this.controller.listen(this.controller.get("add-button"), Mojo.Event.tap, this.buttonTapped.bind(this));
77+
//this.controller.listen(this.controller.get("btnGo"), Mojo.Event.tap, this.checkActivation.bind(this));
78+
},
79+
deactivate: function(event){
80+
this.controller.stopListening(this.controller.get("add-button"), Mojo.Event.tap, this.buttonTapped.bind(this));
81+
}
82+
}

0 commit comments

Comments
 (0)