Permalink
Browse files

Moved to xauth, got twitter and foursquare going on it, added foursqu…

…are actions.
  • Loading branch information...
Harry Brundage
Harry Brundage committed Nov 17, 2010
1 parent 1f81401 commit bea19c0ed20ea25dfa6bbdb024478199f2639075
Showing with 1,024 additions and 178 deletions.
  1. +2 −1 Resources/app.js
  2. +2 −0 Resources/app/controllers/accounts_controller.coffee
  3. +2 −0 Resources/app/controllers/accounts_controller.js
  4. +2 −0 Resources/app/controllers/main.coffee
  5. +1 −0 Resources/app/controllers/main.js
  6. +35 −7 Resources/app/controllers/xauthorization_controller.coffee
  7. +44 −6 Resources/app/controllers/xauthorization_controller.js
  8. +0 −1 Resources/app/helpers/icons_helper.coffee
  9. +0 −1 Resources/app/helpers/icons_helper.js
  10. +82 −1 Resources/app/models/accounts/foursquare/foursquare_account.coffee
  11. +91 −3 Resources/app/models/accounts/foursquare/foursquare_account.js
  12. +32 −3 Resources/app/models/accounts/twitter/twitter_account.coffee
  13. +37 −2 Resources/app/models/accounts/twitter/twitter_account.js
  14. +6 −2 Resources/app/models/actions/foursquare/check_in_action.coffee
  15. +6 −2 Resources/app/models/actions/foursquare/check_in_action.js
  16. +2 −1 Resources/app/models/actions/foursquare/foursquare_action.coffee
  17. +2 −1 Resources/app/models/actions/foursquare/foursquare_action.js
  18. +13 −0 Resources/app/models/actions/foursquare/send_friend_request_action.coffee
  19. +26 −0 Resources/app/models/actions/foursquare/send_friend_request_action.js
  20. +2 −2 Resources/app/models/object.coffee
  21. +1 −1 Resources/app/models/object.js
  22. +1 −0 Resources/app/views/accounts/account_table_view_row.coffee
  23. +1 −0 Resources/app/views/accounts/account_table_view_row.js
  24. +0 −2 Resources/app/views/accounts/accounts_table_view_window.coffee
  25. +0 −2 Resources/app/views/accounts/accounts_table_view_window.js
  26. +0 −46 Resources/app/views/accounts/facebook_account_table_row.js
  27. +0 −2 Resources/app/views/accounts/facebook_account_table_view_row.coffee
  28. +0 −2 Resources/app/views/accounts/facebook_account_table_view_row.js
  29. +0 −46 Resources/app/views/accounts/facebook_account_table_viw_row.js
  30. +28 −0 Resources/app/views/accounts/foursquare_account_table_view_row.coffee
  31. +42 −0 Resources/app/views/accounts/foursquare_account_table_view_row.js
  32. +8 −0 Resources/app/views/accounts/foursquare_xauthorization_window.coffee
  33. +24 −0 Resources/app/views/accounts/foursquare_xauthorization_window.js
  34. +4 −0 Resources/app/views/accounts/twitter_xauthorization_window.coffee
  35. +18 −0 Resources/app/views/accounts/twitter_xauthorization_window.js
  36. +20 −0 Resources/app/views/accounts/xauthorization_window.coffee
  37. +37 −1 Resources/app/views/accounts/xauthorization_window.js
  38. +57 −0 Resources/app/views/data_collection_window.coffee
  39. +79 −0 Resources/app/views/data_collection_window.js
  40. +38 −0 Resources/test.coffee
  41. +99 −0 Resources/vendor/foursquare.coffee
  42. +122 −0 Resources/vendor/foursquare.js
  43. +31 −18 Resources/vendor/spazcore/incubator/libs/spazoauth.js
  44. +26 −25 Resources/vendor/tiajax.coffee
  45. +1 −0 Resources/vendor/tiajax.js
View
@@ -12,7 +12,7 @@ Citrus.Config = {
REMOTE_URL: "http://localhost:3000/",
SHORTENER_PREFIX: "s/",
SHORTCODE_RE: "s/([a-zA-Z0-9]+)",
- TWITTER_XAUTH: false,
+ TWITTER_XAUTH: true,
FACEBOOK_API_KEY: "965a3c93faaea82715520e175d983b58",
FACEBOOK_APP_SECRET: "4b4fefb799217cdfd60ba81098291d8c"
};
@@ -82,6 +82,7 @@ Ti.include('app/models/object.js');
Ti.include('app/models/persisted_object.js');
Ti.include('app/views/generic_window.js');
Ti.include('app/views/placeholder_window.js');
+Ti.include('app/views/data_collection_window.js');
Ti.include('app/controllers/controller.js');
var root = new Citrus.Object(); // Make sure root gets event listeners
@@ -1,3 +1,5 @@
+Ti.include('/app/controllers/oauthorization_controller.js')
+Ti.include('/app/controllers/xauthorization_controller.js')
Ti.include("/app/models/accounts/account.js")
Ti.include("/app/models/accounts/account_set.js")
Ti.include("/app/views/accounts/accounts_table_view_window.js")

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -36,6 +36,8 @@ codesTab = Titanium.UI.createTab({
window: root.CodesWindow.win
})
+Titanium.include('test.js')
+
root.tabGroup.addTab(tab) for tab in [codeReaderTab, accountsTab, codesTab]
root.tabGroup.setActiveTab(accountsTab)
root.tabGroup.open({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT})

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,14 +1,42 @@
Ti.include("/app/views/accounts/xauthorization_window.js")
class XAuthorizationController extends Citrus.Controller
- constructor: (onload, onerror)->
- @window = new Citrus.XAuthorizationWindow()
-
- loadURL: (url) ->
- @window.loadURL(url)
+ constructor: (collectSuccess, collectCancel, viewClass)->
+ viewClass ?= Citrus.XAuthorizationWindow
+ @window = new viewClass(this)
+ @window.addEventListener "info:collected", (e) =>
+ # validateInfo will alert the user of any issues
+ if this.validateInfo()
+ collectSuccess(this.data())
+
+ root.tabGroup.activeTab.open @window.win, {animated:true}
+ @loading = new Citrus.ModalLoadingView("Authorizing Account...", this)
+
- destroy: ->
- @window.destroyAuthorizeUI()
+ validateInfo: () ->
+ d this.data()
+ for name, val of this.data()
+ if val == ""
+ alert "All fields are required"
+ return false
+ return true
+ data: () ->
+ @window.data()
+
+ showCredentialsError: () ->
+ this.hideLoading()
+ alert("Your username and password could not be verified. Please ensure they are correct and try again.")
+
+ showCommunicationError: () ->
+ this.hideLoading()
+ alert("There was an error contacting the Twitter servers. Please try again.")
+
+ showLoading: () ->
+ @loading.show(@window.win)
+ hideLoading: () ->
+ @loading.hide(@window.win)
+ destroy: () ->
+ @window.win.close()
Citrus.XAuthorizationController = XAuthorizationController

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -2,6 +2,5 @@ _.extend Citrus, {
getIconPath: (name) ->
name = (name || "Generic").toLowerCase().replace("account", "").replace("action", "")
path = "images/account_icons/"+name+".png"
- d(path)
return path
}
@@ -4,7 +4,6 @@
var path;
name = (name || "Generic").toLowerCase().replace("account", "").replace("action", "");
path = "images/account_icons/" + name + ".png";
- d(path);
return path;
}
});
@@ -1,4 +1,85 @@
+Ti.include('/app/views/accounts/foursquare_xauthorization_window.js')
+Ti.include('/vendor/foursquare.js')
+
class FoursquareAccount extends Citrus.Account
type: "FoursquareAccount"
+ persistableAttributes: ["location", "name", "accessToken", "accessTokenSecret"]
+ constructor: (params) ->
+ super(params)
+ @consumer = new SpazOAuth
+ 'service' : 'foursquare'
+
+ @api = new Citrus.FoursquareAPI()
+ @api.consumer = @consumer
+ @consumer.accessToken = this.accessToken
+ @consumer.accessTokenSecret = this.accessTokenSecret
+ d("Initializing FSQ account", params, this.accessToken, this.accessTokenSecret, @consumer.isAuthorized())
+ synch: ->
+ this.fireEvent("state:updating")
+ if ! this.isAuthorized()
+ Ti.API.debug("Trying to synch Twitter Account but account is not authorized!")
+ this.fireEvent("state:error")
+ return false
+ @api.getDetails(null, (data) =>
+ this.name = (data.user?.firstname + " " + data.user?.lastname) || data.user?.email
+ unless this.name
+ er("Not enough information returned from foursquare to make an account")
+ this.fireEvent("state:error")
+ return false
+ this.location = data.user?.checkin?.venue?.name
+ this.fireEvent("state:ready")
+ this.markAsSynched()
+ , (e, status, error) =>
+ Ti.API.error("Couldn't retrive account information! Status: "+status)
+ Ti.API.error("Status: "+e.status)
+ Ti.API.error("Message: "+error.message)
+ Ti.API.error("Response: "+e.responseText)
+ this.fireEvent("state:error")
+ )
+
+ isAuthorized: ->
+ return @consumer.isAuthorized()
+
+ authorize: () ->
+ d("Starting XAuth Foursquare authorization")
+ controller = {}
+ gotData = (data) =>
+ data =
+ username: data.email
+ password: data.password
+ controller.showLoading()
+ @consumer.getXauthTokens _.extend(data, {
+ onSuccess: (e) =>
+ d "Sucess getting xauth tokens"
+ controller.hideLoading()
+ this.completeAuthorization()
+ controller.destroy()
+ onError: (xhr, status, e) =>
+ er("Unable to get XAuth tokens with supplied data.")
+ d status
+ d xhr.status
+ d xhr.responseText
+ d e
+ if xhr.status == 401
+ controller.showCredentialsError()
+ else
+ controller.showCommunicationError()
+ Ti.API.error("Error finding pin in authorize UI. Canceling process.")
+ this.fireEvent("authorization:error", e)
+ this.fireEvent("authorization:complete")
+ })
+
+ canceled = (e) =>
+ this.fireEvent("authorization:error", e)
+ this.fireEvent("authorization:complete")
+
+ controller = new Citrus.XAuthorizationController(gotData, canceled, Citrus.FoursquareXAuthorizationWindow)
+
+ completeAuthorization: () ->
+ # Set up API to properly consume
+ this.accessToken = @consumer.accessToken
+ this.accessTokenSecret = @consumer.accessTokenSecret
+ @api.consumer = @consumer
+ super()
-Citrus.registerAccount FoursquareAccount
+Citrus.registerAccount FoursquareAccount

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit bea19c0

Please sign in to comment.