Created
January 28, 2011 11:56
-
-
Save gumayunov/800158 to your computer and use it in GitHub Desktop.
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
this.Twitter = function(opts) { this.init(opts); }; | |
this.Twitter.prototype = { | |
init: function(opts) { | |
var self = this; | |
self.opts = opts; | |
if (!self.opts.container) self.opts.container = default_container(); | |
debug("initializing Twitter"); | |
self.setup(); | |
}, | |
setup: function() { | |
var self = this; | |
debug('setuping Twitter'); | |
twttr.anywhere(function (T) { | |
$("#tw-login").click(function() { | |
if (T.isConnected()) { | |
debug("user already connected"); | |
self.createSession(T.currentUser); | |
} else { | |
T.bind("authComplete", function(user) { | |
debug("connection completed"); | |
self.createSession(T.currentUser); | |
}); | |
T.signIn(); | |
} | |
}); | |
}); | |
}, | |
createSession: function(current_user) { | |
debug("creating session"); | |
var fields = ['name', 'screen_name', 'profile_image_url', 'description', 'url', 'location']; | |
var uinfo = {}; | |
$(fields).each(function(i, field){ | |
uinfo[field] = current_user.data(field); | |
}); | |
$.post("/user_session", { user_session: {social_connect: 'twitter', data: uinfo}} ); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment