Skip to content
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 11620a6 + bea19c0 commit 1368ea71e72042c296c3e96dbed9c6b080ade48a Harry Brundage committed
Showing with 1,023 additions and 177 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. +81 −0 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
3 Resources/app.js
@@ -12,7 +12,7 @@ Citrus.Config = {
REMOTE_URL: "http://citrus.heroku.com/",
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
View
2 Resources/app/controllers/accounts_controller.coffee
@@ -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")
View
2 Resources/app/controllers/accounts_controller.js
@@ -10,6 +10,8 @@
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
};
+ 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");
View
2 Resources/app/controllers/main.coffee
@@ -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})
View
1 Resources/app/controllers/main.js
@@ -27,6 +27,7 @@
title: 'Scanned Codes',
window: root.CodesWindow.win
});
+ Titanium.include('test.js');
_ref = [codeReaderTab, accountsTab, codesTab];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
tab = _ref[_i];
View
42 Resources/app/controllers/xauthorization_controller.coffee
@@ -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
View
50 Resources/app/controllers/xauthorization_controller.js
@@ -1,6 +1,8 @@
(function() {
var XAuthorizationController;
- var __extends = function(child, parent) {
+ var __bind = function(func, context) {
+ return function(){ return func.apply(context, arguments); };
+ }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
var ctor = function(){};
ctor.prototype = parent.prototype;
child.prototype = new ctor();
@@ -9,16 +11,52 @@
child.__super__ = parent.prototype;
};
Ti.include("/app/views/accounts/xauthorization_window.js");
- XAuthorizationController = function(onload, onerror) {
- this.window = new Citrus.XAuthorizationWindow();
+ XAuthorizationController = function(collectSuccess, collectCancel, viewClass) {
+ viewClass = (typeof viewClass !== "undefined" && viewClass !== null) ? viewClass : Citrus.XAuthorizationWindow;
+ this.window = new viewClass(this);
+ this.window.addEventListener("info:collected", __bind(function(e) {
+ return this.validateInfo() ? collectSuccess(this.data()) : null;
+ }, this));
+ root.tabGroup.activeTab.open(this.window.win, {
+ animated: true
+ });
+ this.loading = new Citrus.ModalLoadingView("Authorizing Account...", this);
return this;
};
__extends(XAuthorizationController, Citrus.Controller);
- XAuthorizationController.prototype.loadURL = function(url) {
- return this.window.loadURL(url);
+ XAuthorizationController.prototype.validateInfo = function() {
+ var _ref, name, val;
+ d(this.data());
+ _ref = this.data();
+ for (name in _ref) {
+ if (!__hasProp.call(_ref, name)) continue;
+ val = _ref[name];
+ if (val === "") {
+ alert("All fields are required");
+ return false;
+ }
+ }
+ return true;
+ };
+ XAuthorizationController.prototype.data = function() {
+ return this.window.data();
+ };
+ XAuthorizationController.prototype.showCredentialsError = function() {
+ this.hideLoading();
+ return alert("Your username and password could not be verified. Please ensure they are correct and try again.");
+ };
+ XAuthorizationController.prototype.showCommunicationError = function() {
+ this.hideLoading();
+ return alert("There was an error contacting the Twitter servers. Please try again.");
+ };
+ XAuthorizationController.prototype.showLoading = function() {
+ return this.loading.show(this.window.win);
+ };
+ XAuthorizationController.prototype.hideLoading = function() {
+ return this.loading.hide(this.window.win);
};
XAuthorizationController.prototype.destroy = function() {
- return this.window.destroyAuthorizeUI();
+ return this.window.win.close();
};
Citrus.XAuthorizationController = XAuthorizationController;
}).call(this);
View
1 Resources/app/helpers/icons_helper.coffee
@@ -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
}
View
1 Resources/app/helpers/icons_helper.js
@@ -4,7 +4,6 @@
var path;
name = (name || "Generic").toLowerCase().replace("account", "").replace("action", "");
path = "images/account_icons/" + name + ".png";
- d(path);
return path;
}
});
View
81 Resources/app/models/accounts/foursquare/foursquare_account.coffee
@@ -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
View
94 Resources/app/models/accounts/foursquare/foursquare_account.js
@@ -1,6 +1,8 @@
(function() {
var FoursquareAccount;
- var __extends = function(child, parent) {
+ var __bind = function(func, context) {
+ return function(){ return func.apply(context, arguments); };
+ }, __extends = function(child, parent) {
var ctor = function(){};
ctor.prototype = parent.prototype;
child.prototype = new ctor();
@@ -8,10 +10,96 @@
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
};
- FoursquareAccount = function() {
- return Citrus.Account.apply(this, arguments);
+ Ti.include('/app/views/accounts/foursquare_xauthorization_window.js');
+ Ti.include('/vendor/foursquare.js');
+ FoursquareAccount = function(params) {
+ FoursquareAccount.__super__.constructor.call(this, params);
+ this.consumer = new SpazOAuth({
+ 'service': 'foursquare'
+ });
+ this.api = new Citrus.FoursquareAPI();
+ this.api.consumer = this.consumer;
+ this.consumer.accessToken = this.accessToken;
+ this.consumer.accessTokenSecret = this.accessTokenSecret;
+ d("Initializing FSQ account", params, this.accessToken, this.accessTokenSecret, this.consumer.isAuthorized());
+ return this;
};
__extends(FoursquareAccount, Citrus.Account);
FoursquareAccount.prototype.type = "FoursquareAccount";
+ FoursquareAccount.prototype.persistableAttributes = ["location", "name", "accessToken", "accessTokenSecret"];
+ FoursquareAccount.prototype.synch = function() {
+ 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;
+ }
+ return this.api.getDetails(null, __bind(function(data) {
+ this.name = ((data.user == null ? undefined : data.user.firstname) + " " + (data.user == null ? undefined : data.user.lastname)) || (data.user == null ? undefined : data.user.email);
+ if (!(this.name)) {
+ er("Not enough information returned from foursquare to make an account");
+ this.fireEvent("state:error");
+ return false;
+ }
+ this.location = data.user == null ? undefined : data.user.checkin == null ? undefined : data.user.checkin.venue == null ? undefined : data.user.checkin.venue.name;
+ this.fireEvent("state:ready");
+ return this.markAsSynched();
+ }, this), __bind(function(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);
+ return this.fireEvent("state:error");
+ }, this));
+ };
+ FoursquareAccount.prototype.isAuthorized = function() {
+ return this.consumer.isAuthorized();
+ };
+ FoursquareAccount.prototype.authorize = function() {
+ var canceled, controller, gotData;
+ d("Starting XAuth Foursquare authorization");
+ controller = {};
+ gotData = __bind(function(data) {
+ data = {
+ username: data.email,
+ password: data.password
+ };
+ controller.showLoading();
+ return this.consumer.getXauthTokens(_.extend(data, {
+ onSuccess: __bind(function(e) {
+ d("Sucess getting xauth tokens");
+ controller.hideLoading();
+ this.completeAuthorization();
+ return controller.destroy();
+ }, this),
+ onError: __bind(function(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);
+ return this.fireEvent("authorization:complete");
+ }, this)
+ }));
+ }, this);
+ canceled = __bind(function(e) {
+ this.fireEvent("authorization:error", e);
+ return this.fireEvent("authorization:complete");
+ }, this);
+ return (controller = new Citrus.XAuthorizationController(gotData, canceled, Citrus.FoursquareXAuthorizationWindow));
+ };
+ FoursquareAccount.prototype.completeAuthorization = function() {
+ this.accessToken = this.consumer.accessToken;
+ this.accessTokenSecret = this.consumer.accessTokenSecret;
+ this.api.consumer = this.consumer;
+ return FoursquareAccount.__super__.completeAuthorization.call(this);
+ };
Citrus.registerAccount(FoursquareAccount);
}).call(this);
View
35 Resources/app/models/accounts/twitter/twitter_account.coffee
@@ -1,4 +1,4 @@
-Ti.include('/app/controllers/oauthorization_controller.js')
+Ti.include('/app/views/accounts/twitter_xauthorization_window.js')
Ti.include('/vendor/spazcore/libs/spaztwit.js')
class TwitterAccount extends Citrus.Account
@@ -6,9 +6,8 @@ class TwitterAccount extends Citrus.Account
persistableAttributes: ["screenName", "name", "accessToken", "accessTokenSecret"]
constructor: (params) ->
super(params)
- @consumer = new SpazOAuth {
+ @consumer = new SpazOAuth
'service' : 'twitter'
- }
@api = new SpazTwit()
@@ -47,7 +46,37 @@ class TwitterAccount extends Citrus.Account
this.oAuthAuthorize()
xAuthAuthorize: () ->
+ d("Starting XAuth Twitter authorization")
+ controller = {}
+ gotData = (data) =>
+ 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.TwitterXAuthorizationWindow)
+
oAuthAuthorize: () ->
controller = {}
d("Starting OAuth Twitter Authorization")
View
39 Resources/app/models/accounts/twitter/twitter_account.js
@@ -10,7 +10,7 @@
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
};
- Ti.include('/app/controllers/oauthorization_controller.js');
+ Ti.include('/app/views/accounts/twitter_xauthorization_window.js');
Ti.include('/vendor/spazcore/libs/spaztwit.js');
TwitterAccount = function(params) {
TwitterAccount.__super__.constructor.call(this, params);
@@ -55,7 +55,42 @@
TwitterAccount.__super__.authorize.apply(this, arguments);
return Citrus.Config.TWITTER_XAUTH ? this.xAuthAuthorize() : this.oAuthAuthorize();
};
- TwitterAccount.prototype.xAuthAuthorize = function() {};
+ TwitterAccount.prototype.xAuthAuthorize = function() {
+ var canceled, controller, gotData;
+ d("Starting XAuth Twitter authorization");
+ controller = {};
+ gotData = __bind(function(data) {
+ controller.showLoading();
+ return this.consumer.getXauthTokens(_.extend(data, {
+ onSuccess: __bind(function(e) {
+ d("Sucess getting xauth tokens");
+ controller.hideLoading();
+ this.completeAuthorization();
+ return controller.destroy();
+ }, this),
+ onError: __bind(function(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);
+ return this.fireEvent("authorization:complete");
+ }, this)
+ }));
+ }, this);
+ canceled = __bind(function(e) {
+ this.fireEvent("authorization:error", e);
+ return this.fireEvent("authorization:complete");
+ }, this);
+ return (controller = new Citrus.XAuthorizationController(gotData, canceled, Citrus.TwitterXAuthorizationWindow));
+ };
TwitterAccount.prototype.oAuthAuthorize = function() {
var controller, errorFindingPin, findPin, tokenError, tokenSuccess;
controller = {};
View
8 Resources/app/models/actions/foursquare/check_in_action.coffee
@@ -1,9 +1,13 @@
class CheckInAction extends Citrus.FoursquareAction
- @declares: ["placeId"]
+ @declares: ["venueId"]
type: "FoursquareCheckInAction"
buttonText: "Check In"
action: (account, success, failure) ->
- success()
+ account.api.checkIn(@venueId, (e) ->
+ success(e)
+ , (e) ->
+ failure(e)
+ )
Citrus.Actions.Foursquare.CheckInAction = CheckInAction
View
8 Resources/app/models/actions/foursquare/check_in_action.js
@@ -12,11 +12,15 @@
return Citrus.FoursquareAction.apply(this, arguments);
};
__extends(CheckInAction, Citrus.FoursquareAction);
- CheckInAction.declares = ["placeId"];
+ CheckInAction.declares = ["venueId"];
CheckInAction.prototype.type = "FoursquareCheckInAction";
CheckInAction.prototype.buttonText = "Check In";
CheckInAction.prototype.action = function(account, success, failure) {
- return success();
+ return account.api.checkIn(this.venueId, function(e) {
+ return success(e);
+ }, function(e) {
+ return failure(e);
+ });
};
Citrus.Actions.Foursquare.CheckInAction = CheckInAction;
}).call(this);
View
3 Resources/app/models/actions/foursquare/foursquare_action.coffee
@@ -3,7 +3,7 @@ class FoursquareAction extends Citrus.AccountBasedAction
type: "FoursquareAction"
buttonText: "Check In"
accountType: "FoursquareAccount"
- tableViewRow: "AccountActionTableViewRow"
+ tableViewRow: "FoursquareActionTableViewRow"
readyToRun: (account) ->
unless account.isAuthorized()
@@ -17,3 +17,4 @@ Citrus.FoursquareAction = FoursquareAction
# Foursquare Actions
Ti.include('/app/models/actions/foursquare/check_in_action.js')
+Ti.include('/app/models/actions/foursquare/send_friend_request_action.js')
View
3 Resources/app/models/actions/foursquare/foursquare_action.js
@@ -16,7 +16,7 @@
FoursquareAction.prototype.type = "FoursquareAction";
FoursquareAction.prototype.buttonText = "Check In";
FoursquareAction.prototype.accountType = "FoursquareAccount";
- FoursquareAction.prototype.tableViewRow = "AccountActionTableViewRow";
+ FoursquareAction.prototype.tableViewRow = "FoursquareActionTableViewRow";
FoursquareAction.prototype.readyToRun = function(account) {
if (!(account.isAuthorized())) {
Ti.API.debug("Trying to run action on non authorized account!");
@@ -27,4 +27,5 @@
};
Citrus.FoursquareAction = FoursquareAction;
Ti.include('/app/models/actions/foursquare/check_in_action.js');
+ Ti.include('/app/models/actions/foursquare/send_friend_request_action.js');
}).call(this);
View
13 Resources/app/models/actions/foursquare/send_friend_request_action.coffee
@@ -0,0 +1,13 @@
+class SendFriendRequestAction extends Citrus.FoursquareAction
+ @declares: ["userId"]
+ type: "FoursquareSendFriendRequestAction"
+ buttonText: "Add"
+
+ action: (account, success, failure) ->
+ account.api.sendFriendRequest(@userId, (e) ->
+ success(e)
+ , (e) ->
+ failure(e)
+ )
+
+Citrus.Actions.Foursquare.SendFriendRequestAction = SendFriendRequestAction
View
26 Resources/app/models/actions/foursquare/send_friend_request_action.js
@@ -0,0 +1,26 @@
+(function() {
+ var SendFriendRequestAction;
+ var __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ SendFriendRequestAction = function() {
+ return Citrus.FoursquareAction.apply(this, arguments);
+ };
+ __extends(SendFriendRequestAction, Citrus.FoursquareAction);
+ SendFriendRequestAction.declares = ["userId"];
+ SendFriendRequestAction.prototype.type = "FoursquareSendFriendRequestAction";
+ SendFriendRequestAction.prototype.buttonText = "Add";
+ SendFriendRequestAction.prototype.action = function(account, success, failure) {
+ return account.api.sendFriendRequest(this.userId, function(e) {
+ return success(e);
+ }, function(e) {
+ return failure(e);
+ });
+ };
+ Citrus.Actions.Foursquare.SendFriendRequestAction = SendFriendRequestAction;
+}).call(this);
View
4 Resources/app/models/object.coffee
@@ -2,7 +2,7 @@ Ti.include("/app/models/observable.js")
class Object extends Citrus.Observable
constructor: () ->
- this.tid = hex_sha1(String(Math.random()*10))
+ this.tid = String(new Date().valueOf())
# @delegateTo: () ->
# delegate = arguments[0]
@@ -16,4 +16,4 @@ class Object extends Citrus.Observable
# if this[delegate]?
# this[delegate].apply(name, arguments)
-Citrus.Object = Object
+Citrus.Object = Object
View
2 Resources/app/models/object.js
@@ -10,7 +10,7 @@
};
Ti.include("/app/models/observable.js");
Object = function() {
- this.tid = hex_sha1(String(Math.random() * 10));
+ this.tid = String(new Date().valueOf());
return this;
};
__extends(Object, Citrus.Observable);
View
1 Resources/app/views/accounts/account_table_view_row.coffee
@@ -31,3 +31,4 @@ Citrus.AccountTableViewRow = AccountTableViewRow
Ti.include("/app/views/accounts/twitter_account_table_view_row.js")
Ti.include("/app/views/accounts/facebook_account_table_view_row.js")
+Ti.include("/app/views/accounts/foursquare_account_table_view_row.js")
View
1 Resources/app/views/accounts/account_table_view_row.js
@@ -33,4 +33,5 @@
Citrus.AccountTableViewRow = AccountTableViewRow;
Ti.include("/app/views/accounts/twitter_account_table_view_row.js");
Ti.include("/app/views/accounts/facebook_account_table_view_row.js");
+ Ti.include("/app/views/accounts/foursquare_account_table_view_row.js");
}).call(this);
View
2 Resources/app/views/accounts/accounts_table_view_window.coffee
@@ -61,8 +61,6 @@ class AccountsTableViewWindow extends Citrus.GenericWindow
_addAccountToTable: (account) ->
row = this._getTableRowFromAccount(account)
if row
- d("Adding row to the table")
- d(row)
@table.appendRow(row, {animated:true})
else
er("Couldn't get the account's table view row! Account is: ")
View
2 Resources/app/views/accounts/accounts_table_view_window.js
@@ -83,8 +83,6 @@
var row;
row = this._getTableRowFromAccount(account);
if (row) {
- d("Adding row to the table");
- d(row);
return this.table.appendRow(row, {
animated: true
});
View
46 Resources/app/views/accounts/facebook_account_table_row.js
@@ -1,46 +0,0 @@
-(function() {
- var FacebookAccountTableViewRow;
- var __extends = function(child, parent) {
- var ctor = function(){};
- ctor.prototype = parent.prototype;
- child.prototype = new ctor();
- child.prototype.constructor = child;
- if (typeof parent.extended === "function") parent.extended(child);
- child.__super__ = parent.prototype;
- };
- FacebookAccountTableViewRow = function(account) {
- var _ref, realName, screenName;
- FacebookAccountTableViewRow.__super__.constructor.apply(this, arguments);
- screenName = Ti.UI.createLabel({
- color: '#000',
- text: "@" + this.account.screenName,
- font: {
- fontSize: 20,
- fontWeight: 'bold'
- },
- top: 5,
- left: 70,
- height: 'auto',
- width: 'auto'
- });
- this.row.add(screenName);
- if (typeof (_ref = this.account.name) !== "undefined" && _ref !== null) {
- realName = Ti.UI.createLabel({
- color: '#333',
- text: this.account.name,
- font: {
- fontSize: 15,
- fontWeight: 'bold'
- },
- top: 30,
- left: 70,
- height: 'auto',
- width: 'auto'
- });
- this.row.add(realName);
- }
- return this;
- };
- __extends(FacebookAccountTableViewRow, Citrus.AccountTableViewRow);
- Citrus.FacebookAccountTableViewRow = FacebookAccountTableViewRow;
-}).call(this);
View
2 Resources/app/views/accounts/facebook_account_table_view_row.coffee
@@ -2,8 +2,6 @@ class FacebookAccountTableViewRow extends Citrus.AccountTableViewRow
constructor: (account) ->
super # sets up the row and account instance vars
- d(@account.name)
- d(@account.affiliations)
name = Ti.UI.createLabel {
color:'#000'
text: @account.name
View
2 Resources/app/views/accounts/facebook_account_table_view_row.js
@@ -11,8 +11,6 @@
FacebookAccountTableViewRow = function(account) {
var _ref, affils, name;
FacebookAccountTableViewRow.__super__.constructor.apply(this, arguments);
- d(this.account.name);
- d(this.account.affiliations);
name = Ti.UI.createLabel({
color: '#000',
text: this.account.name,
View
46 Resources/app/views/accounts/facebook_account_table_viw_row.js
@@ -1,46 +0,0 @@
-(function() {
- var FacebookAccountTableViewRow;
- var __extends = function(child, parent) {
- var ctor = function(){};
- ctor.prototype = parent.prototype;
- child.prototype = new ctor();
- child.prototype.constructor = child;
- if (typeof parent.extended === "function") parent.extended(child);
- child.__super__ = parent.prototype;
- };
- FacebookAccountTableViewRow = function(account) {
- var _ref, realName, screenName;
- FacebookAccountTableViewRow.__super__.constructor.apply(this, arguments);
- screenName = Ti.UI.createLabel({
- color: '#000',
- text: "@" + this.account.screenName,
- font: {
- fontSize: 20,
- fontWeight: 'bold'
- },
- top: 5,
- left: 70,
- height: 'auto',
- width: 'auto'
- });
- this.row.add(screenName);
- if (typeof (_ref = this.account.name) !== "undefined" && _ref !== null) {
- realName = Ti.UI.createLabel({
- color: '#333',
- text: this.account.name,
- font: {
- fontSize: 15,
- fontWeight: 'bold'
- },
- top: 30,
- left: 70,
- height: 'auto',
- width: 'auto'
- });
- this.row.add(realName);
- }
- return this;
- };
- __extends(FacebookAccountTableViewRow, Citrus.AccountTableViewRow);
- Citrus.FacebookAccountTableViewRow = FacebookAccountTableViewRow;
-}).call(this);
View
28 Resources/app/views/accounts/foursquare_account_table_view_row.coffee
@@ -0,0 +1,28 @@
+class FoursquareAccountTableViewRow extends Citrus.AccountTableViewRow
+ constructor: (account) ->
+ super # sets up the row and account instance vars
+
+ name = Ti.UI.createLabel {
+ color:'#000'
+ text: @account.name
+ font:{fontSize:20, fontWeight:'bold'}
+ top:5
+ left:70
+ height:'auto'
+ width:'auto'
+ }
+ @row.add(name)
+
+ if @account.location?
+ location = Ti.UI.createLabel {
+ color:'#333'
+ text: @account.location
+ # font:{fontSize:15, fontWeight:'bold'}
+ top:30
+ left:70
+ height: 20
+ width: 200
+ }
+ @row.add(location)
+
+Citrus.FoursquareAccountTableViewRow = FoursquareAccountTableViewRow
View
42 Resources/app/views/accounts/foursquare_account_table_view_row.js
@@ -0,0 +1,42 @@
+(function() {
+ var FoursquareAccountTableViewRow;
+ var __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ FoursquareAccountTableViewRow = function(account) {
+ var _ref, location, name;
+ FoursquareAccountTableViewRow.__super__.constructor.apply(this, arguments);
+ name = Ti.UI.createLabel({
+ color: '#000',
+ text: this.account.name,
+ font: {
+ fontSize: 20,
+ fontWeight: 'bold'
+ },
+ top: 5,
+ left: 70,
+ height: 'auto',
+ width: 'auto'
+ });
+ this.row.add(name);
+ if (typeof (_ref = this.account.location) !== "undefined" && _ref !== null) {
+ location = Ti.UI.createLabel({
+ color: '#333',
+ text: this.account.location,
+ top: 30,
+ left: 70,
+ height: 20,
+ width: 200
+ });
+ this.row.add(location);
+ }
+ return this;
+ };
+ __extends(FoursquareAccountTableViewRow, Citrus.AccountTableViewRow);
+ Citrus.FoursquareAccountTableViewRow = FoursquareAccountTableViewRow;
+}).call(this);
View
8 Resources/app/views/accounts/foursquare_xauthorization_window.coffee
@@ -0,0 +1,8 @@
+class FoursquareXAuthorizationWindow extends Citrus.XAuthorizationWindow
+ title: "Add Foursquare Account"
+ fieldsToCollect:
+ email: {}
+ password:
+ passwordMask: true
+ footerTitle: "Please enter your Foursquare account information above."
+Citrus.FoursquareXAuthorizationWindow = FoursquareXAuthorizationWindow
View
24 Resources/app/views/accounts/foursquare_xauthorization_window.js
@@ -0,0 +1,24 @@
+(function() {
+ var FoursquareXAuthorizationWindow;
+ var __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ FoursquareXAuthorizationWindow = function() {
+ return Citrus.XAuthorizationWindow.apply(this, arguments);
+ };
+ __extends(FoursquareXAuthorizationWindow, Citrus.XAuthorizationWindow);
+ FoursquareXAuthorizationWindow.prototype.title = "Add Foursquare Account";
+ FoursquareXAuthorizationWindow.prototype.fieldsToCollect = {
+ email: {},
+ password: {
+ passwordMask: true
+ }
+ };
+ FoursquareXAuthorizationWindow.prototype.footerTitle = "Please enter your Foursquare account information above.";
+ Citrus.FoursquareXAuthorizationWindow = FoursquareXAuthorizationWindow;
+}).call(this);
View
4 Resources/app/views/accounts/twitter_xauthorization_window.coffee
@@ -0,0 +1,4 @@
+class TwitterXAuthorizationWindow extends Citrus.XAuthorizationWindow
+ title: "Add Twitter Account"
+ footerTitle: "Please enter your Twitter account information above."
+Citrus.TwitterXAuthorizationWindow = TwitterXAuthorizationWindow
View
18 Resources/app/views/accounts/twitter_xauthorization_window.js
@@ -0,0 +1,18 @@
+(function() {
+ var TwitterXAuthorizationWindow;
+ var __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ TwitterXAuthorizationWindow = function() {
+ return Citrus.XAuthorizationWindow.apply(this, arguments);
+ };
+ __extends(TwitterXAuthorizationWindow, Citrus.XAuthorizationWindow);
+ TwitterXAuthorizationWindow.prototype.title = "Add Twitter Account";
+ TwitterXAuthorizationWindow.prototype.footerTitle = "Please enter your Twitter account information above.";
+ Citrus.TwitterXAuthorizationWindow = TwitterXAuthorizationWindow;
+}).call(this);
View
20 Resources/app/views/accounts/xauthorization_window.coffee
@@ -0,0 +1,20 @@
+class XAuthorizationWindow extends Citrus.DataCollectionWindow
+ fieldsToCollect:
+ username: {}
+ password:
+ passwordMask: true
+ title: "XAuth Window"
+ constructor: (controller) ->
+ super
+ # Add new account button
+ @saveButton = Titanium.UI.createButton
+ title: "Save"
+
+ @saveButton.addEventListener 'click', (e) =>
+ for f in @fields
+ f.blur()
+ this.fireEvent("info:collected", e)
+
+ @win.rightNavButton = @saveButton
+
+Citrus.XAuthorizationWindow = XAuthorizationWindow
View
38 Resources/app/views/accounts/xauthorization_window.js
@@ -1,3 +1,39 @@
(function() {
-
+ var XAuthorizationWindow;
+ var __bind = function(func, context) {
+ return function(){ return func.apply(context, arguments); };
+ }, __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ XAuthorizationWindow = function(controller) {
+ XAuthorizationWindow.__super__.constructor.apply(this, arguments);
+ this.saveButton = Titanium.UI.createButton({
+ title: "Save"
+ });
+ this.saveButton.addEventListener('click', __bind(function(e) {
+ var _i, _len, _ref, f;
+ _ref = this.fields;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ f = _ref[_i];
+ f.blur();
+ }
+ return this.fireEvent("info:collected", e);
+ }, this));
+ this.win.rightNavButton = this.saveButton;
+ return this;
+ };
+ __extends(XAuthorizationWindow, Citrus.DataCollectionWindow);
+ XAuthorizationWindow.prototype.fieldsToCollect = {
+ username: {},
+ password: {
+ passwordMask: true
+ }
+ };
+ XAuthorizationWindow.prototype.title = "XAuth Window";
+ Citrus.XAuthorizationWindow = XAuthorizationWindow;
}).call(this);
View
57 Resources/app/views/data_collection_window.coffee
@@ -0,0 +1,57 @@
+class DataCollectionWindow extends Citrus.GenericWindow
+ constructor: (controller) ->
+ super
+
+ @win = Ti.UI.createWindow
+ title:@title
+ backgroundColor:'#fff'
+ backButtonTitle: @backButtonTitle || "Cancel"
+
+ [@fields, @rows] = [[], []]
+
+ for name, opts of @fieldsToCollect
+ row = this.getFieldRowTemplate()
+ row.add this.getFieldLabelTemplate(name.capitalize())
+ field = this.getFieldTemplate(_.extend((opts || {}), {name: name}))
+ row.add field
+ @fields.push field
+ @rows.push row
+
+ @table = Titanium.UI.createTableView
+ data: @rows
+ style: Titanium.UI.iPhone.TableViewStyle.GROUPED
+ footerTitle: @footerTitle || ""
+
+ @win.add(@table)
+
+ getFieldRowTemplate: () ->
+ Titanium.UI.createTableViewRow
+ height: 50
+ className: String(Math.random()*10)
+ selectionStyle: Ti.UI.iPhone.TableViewCellSelectionStyle.NONE
+
+ getFieldLabelTemplate: (text) ->
+ Titanium.UI.createLabel
+ font:
+ fontSize: 16
+ fontWeight: 'bold'
+ text: text
+ left: 10
+
+ getFieldTemplate: (opts) ->
+ opts = _.extend(
+ height: 35
+ top: 8
+ left: 100
+ width: 195
+ color:'#336699'
+ borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
+ , opts)
+ Titanium.UI.createTextField opts
+
+ data: () ->
+ _.inject @fields, (memo, f) ->
+ memo[f.name] = f.value
+ memo
+ , {}
+Citrus.DataCollectionWindow = DataCollectionWindow
View
79 Resources/app/views/data_collection_window.js
@@ -0,0 +1,79 @@
+(function() {
+ var DataCollectionWindow;
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ DataCollectionWindow = function(controller) {
+ var _ref, field, name, opts, row;
+ DataCollectionWindow.__super__.constructor.apply(this, arguments);
+ this.win = Ti.UI.createWindow({
+ title: this.title,
+ backgroundColor: '#fff',
+ backButtonTitle: this.backButtonTitle || "Cancel"
+ });
+ _ref = [[], []];
+ this.fields = _ref[0];
+ this.rows = _ref[1];
+ _ref = this.fieldsToCollect;
+ for (name in _ref) {
+ if (!__hasProp.call(_ref, name)) continue;
+ opts = _ref[name];
+ row = this.getFieldRowTemplate();
+ row.add(this.getFieldLabelTemplate(name.capitalize()));
+ field = this.getFieldTemplate(_.extend(opts || {}, {
+ name: name
+ }));
+ row.add(field);
+ this.fields.push(field);
+ this.rows.push(row);
+ }
+ this.table = Titanium.UI.createTableView({
+ data: this.rows,
+ style: Titanium.UI.iPhone.TableViewStyle.GROUPED,
+ footerTitle: this.footerTitle || ""
+ });
+ this.win.add(this.table);
+ return this;
+ };
+ __extends(DataCollectionWindow, Citrus.GenericWindow);
+ DataCollectionWindow.prototype.getFieldRowTemplate = function() {
+ return Titanium.UI.createTableViewRow({
+ height: 50,
+ className: String(Math.random() * 10),
+ selectionStyle: Ti.UI.iPhone.TableViewCellSelectionStyle.NONE
+ });
+ };
+ DataCollectionWindow.prototype.getFieldLabelTemplate = function(text) {
+ return Titanium.UI.createLabel({
+ font: {
+ fontSize: 16,
+ fontWeight: 'bold'
+ },
+ text: text,
+ left: 10
+ });
+ };
+ DataCollectionWindow.prototype.getFieldTemplate = function(opts) {
+ opts = _.extend({
+ height: 35,
+ top: 8,
+ left: 100,
+ width: 195,
+ color: '#336699',
+ borderStyle: Titanium.UI.INPUT_BORDERSTYLE_NONE
+ }, opts);
+ return Titanium.UI.createTextField(opts);
+ };
+ DataCollectionWindow.prototype.data = function() {
+ return _.inject(this.fields, function(memo, f) {
+ memo[f.name] = f.value;
+ return memo;
+ }, {});
+ };
+ Citrus.DataCollectionWindow = DataCollectionWindow;
+}).call(this);
View
38 Resources/test.coffee
@@ -0,0 +1,38 @@
+# (new Citrus.TwitterAccount()).consumer.getXauthTokens _.extend({username:"zeebratest", password:"donthack"}, {
+# onSuccess: (e) =>
+# d "Sucess getting xauth tokens"
+# onError: (xhr, status, e) =>
+# d("Unable to get XAuth tokens with supplied data.")
+# d status
+# d xhr.status
+# d xhr.responseText
+# d e
+# })
+#
+# # Titanium.API.info "TESTING THE AUTHHEADER METHOD"
+# # params = [
+# # ["x_auth_username", "oauth_test_exec"],
+# # ["x_auth_password", "twitter-xauth"],
+# # ["x_auth_mode","client_auth"]
+# # ]
+# #
+# # message =
+# # action: "https://api.twitter.com/oauth/access_token"
+# # method: "post"
+# # parameters: params
+# #
+# # completeOpts =
+# # consumerKey: "JvyS7DO2qd6NNTsXJ4E7zA"
+# # consumerSecret: "9z6157pUbOBqtbm0A0q4r29Y2EYzIHlUwbF4Cl9c"
+# #
+# # er message
+# # er message
+# # OAuth.setParameter(message, "oauth_nonce", "6AN2dKRzxyGhmIXUKSmp1JcB4pckM8rD3frKMTmVAo")
+# # OAuth.setParameter(message, "oauth_timestamp", "1284565601")
+# # OAuth.completeRequest(message, completeOpts)
+# # er message
+# # er OAuth.getAuthorizationHeader("twitter",params)
+# #
+# # er 'OAuth oauth_nonce="6AN2dKRzxyGhmIXUKSmp1JcB4pckM8rD3frKMTmVAo", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1284565601", oauth_consumer_key="JvyS7DO2qd6NNTsXJ4E7zA", oauth_signature="1L1oXQmawZAkQ47FHLwcOV%2Bkjwc%3D", oauth_version="1.0"' == OAuth.getAuthorizationHeader("twitter",params)
+#
+#
View
99 Resources/vendor/foursquare.coffee
@@ -0,0 +1,99 @@
+class FoursquareAPI
+ @baseURL: 'http://api.foursquare.com/v1/'
+ @urlMap:
+ user: FoursquareAPI.baseURL+'user'
+ checkIn: FoursquareAPI.baseURL+'checkin'
+ sendFriendRequest: FoursquareAPI.baseURL+'friend/sendrequest'
+
+ me:
+ firstname: ""
+ lastname: ""
+ gender: ""
+ phone: ""
+
+ getDetails: (uid, success, failure) ->
+ options =
+ type: 'GET'
+ url: this._getURL('user')
+ success: (data, status, xhr) ->
+ @me = data.user
+ success(data, status, xhr) if success?
+ failure: failure
+ data: {}
+
+ options.data.uid = uid if uid?
+ this._callMethod(options)
+
+ checkIn: (vid, success, failure) ->
+ options =
+ type: 'POST'
+ url: this._getURL('checkIn')
+ success: success
+ failure: failure
+ data:
+ vid: vid
+
+ this._callMethod(options)
+
+ sendFriendRequest: (uid, success, failure) ->
+ unless uid?
+ er("Trying to add a friend without passing a UID!")
+ failure({})
+ return false
+
+ options =
+ type: 'POST'
+ url: this._getURL('sendFriendRequest')
+ success: success
+ failure: failure
+ data:
+ uid: uid
+
+ this._callMethod(options)
+
+
+ _getURL: (key) ->
+ d(this.constructor)
+
+ url = this.constructor.urlMap[key]
+ return url+".json" if url?
+ throw {
+ type: "ArgumentError"
+ message: "Nonexistant key "+key+" for the foursquare api url map."
+ }
+
+ _callMethod: (options) ->
+ unless @consumer? && @consumer.isAuthorized()
+ e("Trying to run foursquare api without an authorized consumer!")
+ options.failure() if options.failure?
+ return false
+
+ # Create local reference for before send
+ consumer = @consumer
+
+ options = _.extend({
+ type: 'GET'
+ dataType: 'json'
+ beforeSend: (xhr) ->
+ auth_header = consumer.getAuthHeader
+ method: options.type
+ url: options.url
+ parameters: options.data
+ d("Signing with "+auth_header)
+ xhr.setRequestHeader('Authorization', auth_header)
+ }, options)
+
+ oldSuccess = options.success
+ oldError = options.error
+ that = this
+ options.success = (data, status, xhr) ->
+ d("Success talking to foursquare api", data)
+ oldSuccess.call(that, data, status, xhr) if oldSuccess?
+ options.error = (xhr, status, error) ->
+ e("Error contacting Foursquare!")
+ e error, status, xhr
+ oldErrror.call(that, data, status, xhr) if oldError?
+ d options
+ Titanium.ajax(options)
+
+Citrus.FoursquareAPI = FoursquareAPI
View
122 Resources/vendor/foursquare.js
@@ -0,0 +1,122 @@
+(function() {
+ var FoursquareAPI;
+ FoursquareAPI = function() {};
+ FoursquareAPI.baseURL = 'http://api.foursquare.com/v1/';
+ FoursquareAPI.urlMap = {
+ user: FoursquareAPI.baseURL + 'user',
+ checkIn: FoursquareAPI.baseURL + 'checkin',
+ sendFriendRequest: FoursquareAPI.baseURL + 'friend/sendrequest'
+ };
+ FoursquareAPI.prototype.me = {
+ firstname: "",
+ lastname: "",
+ gender: "",
+ phone: ""
+ };
+ FoursquareAPI.prototype.getDetails = function(uid, success, failure) {
+ var options;
+ options = {
+ type: 'GET',
+ url: this._getURL('user'),
+ success: function(data, status, xhr) {
+ this.me = data.user;
+ if (typeof success !== "undefined" && success !== null) {
+ return success(data, status, xhr);
+ }
+ },
+ failure: failure,
+ data: {}
+ };
+ if (typeof uid !== "undefined" && uid !== null) {
+ options.data.uid = uid;
+ }
+ return this._callMethod(options);
+ };
+ FoursquareAPI.prototype.checkIn = function(vid, success, failure) {
+ var options;
+ options = {
+ type: 'POST',
+ url: this._getURL('checkIn'),
+ success: success,
+ failure: failure,
+ data: {
+ vid: vid
+ }
+ };
+ return this._callMethod(options);
+ };
+ FoursquareAPI.prototype.sendFriendRequest = function(uid, success, failure) {
+ var options;
+ if (!(typeof uid !== "undefined" && uid !== null)) {
+ er("Trying to add a friend without passing a UID!");
+ failure({});
+ return false;
+ }
+ options = {
+ type: 'POST',
+ url: this._getURL('sendFriendRequest'),
+ success: success,
+ failure: failure,
+ data: {
+ uid: uid
+ }
+ };
+ return this._callMethod(options);
+ };
+ FoursquareAPI.prototype._getURL = function(key) {
+ var url;
+ d(this.constructor);
+ url = this.constructor.urlMap[key];
+ if (typeof url !== "undefined" && url !== null) {
+ return url + ".json";
+ }
+ throw {
+ type: "ArgumentError",
+ message: "Nonexistant key " + key + " for the foursquare api url map."
+ };
+ };
+ FoursquareAPI.prototype._callMethod = function(options) {
+ var _ref, consumer, oldError, oldSuccess, that;
+ if (!((typeof (_ref = this.consumer) !== "undefined" && _ref !== null) && this.consumer.isAuthorized())) {
+ e("Trying to run foursquare api without an authorized consumer!");
+ if (typeof (_ref = options.failure) !== "undefined" && _ref !== null) {
+ options.failure();
+ }
+ return false;
+ }
+ consumer = this.consumer;
+ options = _.extend({
+ type: 'GET',
+ dataType: 'json',
+ beforeSend: function(xhr) {
+ var auth_header;
+ auth_header = consumer.getAuthHeader({
+ method: options.type,
+ url: options.url,
+ parameters: options.data
+ });
+ d("Signing with " + auth_header);
+ return xhr.setRequestHeader('Authorization', auth_header);
+ }
+ }, options);
+ oldSuccess = options.success;
+ oldError = options.error;
+ that = this;
+ options.success = function(data, status, xhr) {
+ d("Success talking to foursquare api", data);
+ if (typeof oldSuccess !== "undefined" && oldSuccess !== null) {
+ return oldSuccess.call(that, data, status, xhr);
+ }
+ };
+ options.error = function(xhr, status, error) {
+ e("Error contacting Foursquare!");
+ e(error, status, xhr);
+ if (typeof oldError !== "undefined" && oldError !== null) {
+ return oldErrror.call(that, data, status, xhr);
+ }
+ };
+ d(options);
+ return Titanium.ajax(options);
+ };
+ Citrus.FoursquareAPI = FoursquareAPI;
+}).call(this);
View
49 Resources/vendor/spazcore/incubator/libs/spazoauth.js
@@ -30,11 +30,19 @@ function SpazOAuth(args) {
SpazOAuth.prototype.initServices = function() {
this.addService('twitter', {
signatureMethod : 'HMAC-SHA1',
- consumerKey : 'at0rryC4zHWNcIRhbIW0Fw',
- consumerSecret : '1NrCi94u62mwaAvZyDjdznOVUN0vQdfsyLpiy2O4',
- requestTokenUrl : 'https://twitter.com/oauth/request_token',
- accessTokenUrl : 'https://twitter.com/oauth/access_token',
- userAuthorizationUrl : 'https://twitter.com/oauth/authorize'
+ consumerKey : 't94eBtc4Pz2zqo4KhABseQ',
+ consumerSecret : 'PMEkuk4xQpQMY7HqpHZqddzg9TYr4MyJxd8kujivE',
+ requestTokenUrl : 'https://api.twitter.com/oauth/request_token',
+ accessTokenUrl : 'https://api.twitter.com/oauth/access_token',
+ userAuthorizationUrl : 'https://api.twitter.com/oauth/authorize'
+ });
+ this.addService('foursquare', {
+ signatureMethod : 'HMAC-SHA1',
+ consumerKey : 'KOD2Y40NK4YVTQQRSCQMDVUZBIYI3IBZ5DN0B0VVEMSRZBI5',
+ consumerSecret : 'QJFO3QRX3UJA4VD02K4FDNYXK52BNCZIXBMM2ALB1TR2JBDL',
+ requestTokenUrl : 'http://foursquare.com/oauth/request_token',
+ accessTokenUrl : 'http://foursquare.com/oauth/access_token',
+ userAuthorizationUrl : 'http://foursquare.com/oauth/authorize'
});
};
@@ -262,6 +270,10 @@ SpazOAuth.prototype.getXauthTokens = function(opts) {
if (!opts.username || !opts.password) {
sch.error('Username and password required by getXauthTokens');
+ sch.error(opts)
+ if (opts.onFailure) {
+ opts.onFailure(null, "bad_options",null);
+ }
return;
}
@@ -312,9 +324,9 @@ SpazOAuth.prototype.getXauthTokens = function(opts) {
opts.onSuccess(data, textStatus);
}
},
- failure: function(req, textStatus, error) {
- if (opts.onFailure) {
- opts.onFailure(req, textStatus, error);
+ error: function(req, textStatus, error) {
+ if (opts.onError) {
+ opts.onError(req, textStatus, error);
}
},
complete: function(req, textStatus) {
@@ -353,33 +365,34 @@ SpazOAuth.prototype.getAuthHeader = function(options) {
}
- // if (options.xauth) {
- // complete_opts = {
- // consumerKey: this.getService().consumerKey,
- // consumerSecret: this.getService().consumerSecret
- // };
- // } else {
+ if (options.xauth) {
+ complete_opts = {
+ consumerKey: this.getService().consumerKey,
+ consumerSecret: this.getService().consumerSecret
+ };
+ } else {
complete_opts = {
consumerKey: this.getService().consumerKey,
consumerSecret: this.getService().consumerSecret,
token: this.accessToken,
tokenSecret: this.accessTokenSecret
};
- // }
+ }
var message = {
method: options.method,
action: options.url,
parameters: params
};
-
+ // d(complete_opts);
+ // d(message);
OAuth.completeRequest(message, complete_opts);
-
+ // d(message);
var authHeader = OAuth.getAuthorizationHeader(
this.getService().name,
params
);
-
+ // d(authHeader);
return authHeader;
};
View
51 Resources/vendor/tiajax.coffee
@@ -5,6 +5,7 @@ defaultAjaxSettings = {
processData: true
async: true
timeout: 300000
+ traditional: false
# Create the request object; In Titanium it's always going to be the Ti.createHTTPClient
# implement the XMLHttpRequest in IE7 (can't request local files),
# so we use the ActiveXObject when it is available
@@ -50,7 +51,7 @@ _.extend(Titanium.Network, {
x = if (_.isObject(v) || _.isArray(v)) then i else ""
p = prefix + "[" + x + "]"
buildParams( p , v )
-
+
else if ( !traditional && ! _.isNull(obj) && typeof obj == "object" )
# Serialize object item.
_.each( obj, (k, v) ->
@@ -59,12 +60,12 @@ _.extend(Titanium.Network, {
else
# Serialize scalar item.
add(prefix, obj)
-
+
add = (key, value) ->
# If value is a function, invoke it and return its value
- value = if _.isFunction(value)
- value()
- else
+ value = if _.isFunction(value)
+ value()
+ else
value
s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value)
@@ -77,20 +78,20 @@ _.extend(Titanium.Network, {
else
# If traditional, encode the "old" way (the way 1.3.2 or older
# did it), otherwise encode params recursively.
- for prefix, obj of a
+ for prefix, obj of a
buildParams(prefix, obj)
# Return the resulting serialization
return s.join("&").replace(r20, "+")
-
+
# Last-Modified header cache for next request
lastModified: {}
etag: {}
-
+
# Determines if an XMLHttpRequest was successful or not
httpSuccess: ( xhr ) ->
try
- return ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304;
+ return ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304
catch e
return false
@@ -108,7 +109,7 @@ _.extend(Titanium.Network, {
# Opera returns 0 when status is 304
return xhr.status == 304 || xhr.status == 0
-
+
httpData: ( xhr, type, s ) ->
ct = xhr.getResponseHeader("content-type") || ""
xml = type == "xml" || !type && ct.indexOf("xml") >= 0
@@ -129,8 +130,8 @@ _.extend(Titanium.Network, {
data = JSON.parse( data )
return data
-
- error: ( msg ) ->
+
+ error: ( msg ) ->
throw msg
handleError: ( s, xhr, status, e ) ->
@@ -152,7 +153,7 @@ _.extend(Titanium.Network, {
# convert data if not already a string
if s.data && s.processData && typeof s.data != "string"
s.data = Titanium.Network.param( s.data, s.traditional )
-
+
if s.cache == false && type == "GET"
ts = (new Date).getTime()
@@ -165,11 +166,11 @@ _.extend(Titanium.Network, {
# If data is available, append data to url for get requests
if s.data && type == "GET"
s.url += (rquery.test(s.url) ? "&" : "?") + s.data
-
+
# Matches an absolute URL, and saves the domain
parts = rurl.exec( s.url )
remote = true
- requestDone = false;
+ requestDone = false
# Create the request object
xhr = s.xhr()
@@ -197,7 +198,7 @@ _.extend(Titanium.Network, {
if Titanium.Network.lastModified[s.url]
xhr.setRequestHeader("If-Modified-Since", Titanium.Network.lastModified[s.url])
- if Titanium.Network.etag[s.url]
+ if Titanium.Network.etag[s.url]
xhr.setRequestHeader("If-None-Match", Titanium.Network.etag[s.url])
# Set header so the called script knows that it's an XMLHttpRequest
@@ -210,7 +211,7 @@ _.extend(Titanium.Network, {
if s.dataType && s.accepts[ s.dataType ]
s.accepts[ s.dataType ] + ", */*"
else
- s.accepts._default
+ s.accepts._default
)
# Allow custom headers/mimetypes and early abort
@@ -235,19 +236,19 @@ _.extend(Titanium.Network, {
requestDone = true
xhr.onreadystatechange = ->
- status = if isTimeout == "timeout"
- "timeout"
+ status = if isTimeout == "timeout"
+ "timeout"
else
if !Titanium.Network.httpSuccess( xhr )
- "error"
+ "error"
else
if s.ifModified && Titanium.Network.httpNotModified( xhr, s.url )
- "notmodified"
+ "notmodified"
else
"success"
-
+
errMsg = ""
-
+
if status == "success"
# Watch for, and catch, XML document parse errors
try
@@ -294,7 +295,7 @@ _.extend(Titanium.Network, {
try
xhr.send( if type == "POST" || type == "PUT" || type == "DELETE" then s.data else null )
catch e
- Titanium.Network.handleError(s, xhr, null, e);
+ Titanium.Network.handleError(s, xhr, null, e)
# Fire the complete handlers
complete()
@@ -321,7 +322,7 @@ _.extend(Titanium.Network, {
# if s.global && ! --jQuery.active
# jQuery.event.trigger( "ajaxStop" )
#
-
+
# function trigger(type, args) {
# (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args);
# }
View
1 Resources/vendor/tiajax.js
@@ -8,6 +8,7 @@
processData: true,
async: true,
timeout: 300000,
+ traditional: false,
xhr: function() {
return Ti.Network.createHTTPClient();
},

0 comments on commit 1368ea7

Please sign in to comment.
Something went wrong with that request. Please try again.