Skip to content
Open
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#= require facebook
#= require jquery
#= require twitter/bootstrap
#= require angular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ocarina.controller 'PlaylistNewCtrl', ['$rootScope', '$scope', '$location', 'Fac
$location.path("/playlists/#{res.data.id}")
$scope.currentUser.playlists.push(res.data)
message = "I just created a playlist for this event on PlayedBy.me. Go to the site now or at the party to add songs you want to hear!"
link = "http://localhost:4400/playlists/#{res.data.id}"
link = "http://#{Playedbyme.env.domain}/playlists/#{res.data.id}"
name = "#{fbEvent.name}'s playlist"
# TODO uncomment this when we can prompt user to post
# Facebook.postOnEvent(fbEvent.id, message, link, name)
Expand Down
50 changes: 49 additions & 1 deletion app/assets/javascripts/facebook.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
setCookie = (c_name, value, exdays) ->
exdate = new Date()
exdate.setDate exdate.getDate() + exdays
c_value = escape(value) + ((if (not (exdays?)) then "" else "; expires=" + exdate.toUTCString()))
document.cookie = c_name + "=" + c_value

getCookie = (c_name) ->
c_value = document.cookie
c_start = c_value.indexOf(" " + c_name + "=")
c_start = c_value.indexOf(c_name + "=") if c_start is -1
if c_start is -1
c_value = null
else
c_start = c_value.indexOf("=", c_start) + 1
c_end = c_value.indexOf(";", c_start)
c_end = c_value.length if c_end is -1
c_value = unescape(c_value.substring(c_start, c_end))
c_value

window.fbAsyncInit = ->
console.log "app initialized"
FB.init
appId: "#{Playedbyme.env.facebookAppId}"
channelUrl: "//#{Playedbyme.env.domain}/channel.html"
status: true # check login status
cookie: true # enable cookies to allow the server to access the session
xfbml: true # parse XFBML

FB.Event.subscribe "auth.authResponseChange", (res) ->
if res.status is "connected"
return if getCookie("user_id")
auth = res.authResponse
FB.api '/me?fields=picture,first_name,last_name,email', (res) ->
authParams =
id: res.id
first_name: res.first_name
last_name: res.last_name
email: res.email
image: res.picture.data.url
access_token: auth.accessToken
$.get "#{apiURL}/api/users/authenticate.json", authParams, (data) ->
setCookie("user_id", data.id, 1)
window.location.replace "#{Playedbyme.env.domain}?user_id=#{data.id}"
else if res.status is "not_authorized"
# if user logged in but hasn't authed app
else
# if user logged out

# load the SDK asynchronously
((d) ->
js = undefined
Expand All @@ -9,4 +57,4 @@
js.async = true
js.src = "//connect.facebook.net/en_US/all.js"
ref.parentNode.insertBefore js, ref
) document
) document, false
38 changes: 5 additions & 33 deletions app/assets/javascripts/services.js.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# API URL
@apiURL = ""
@apiURL = Playedbyme.env.apiURL

ocarinaServices = angular.module('ocarinaServices', [])

ocarinaServices.factory 'Pusher', ->
if Pusher?
pusher = new Pusher("e9eb3f912d37215f7804")
pusher = new Pusher(Playedbyme.env.pusherKey)
else
# if pusher doesn't load
subscribe: ->
Expand Down Expand Up @@ -60,34 +60,6 @@ ocarinaServices.factory 'Authentication', ['$http', ($http) ->
Authentication.deferDropbox = (user_id) ->
$http.post "/defer_dropbox_connect", user_id: user_id

window.fbAsyncInit = ->
FB.init
appId: "160916744087752"
channelUrl: "//localhost:4400/channel.html"
status: true # check login status
cookie: true # enable cookies to allow the server to access the session
xfbml: true # parse XFBML

FB.Event.subscribe "auth.authResponseChange", (res) ->
if res.status is "connected"
return if Authentication.getCookie("user_id")
auth = res.authResponse
FB.api '/me?fields=picture,first_name,last_name,email', (res) ->
authParams =
id: res.id
first_name: res.first_name
last_name: res.last_name
email: res.email
image: res.picture.data.url
access_token: auth.accessToken
$.get "#{apiURL}/api/users/authenticate.json", authParams, (data) ->
Authentication.setCookie("user_id", data.id, 1)
window.location.replace "http://localhost:4400?user_id=#{data.id}"
else if res.status is "not_authorized"
# if user logged in but hasn't authed app
else
# if user logged out

Authentication
]

Expand Down Expand Up @@ -235,8 +207,8 @@ ocarinaServices.factory 'Player', ['Audio', (Audio) ->
]

ocarinaServices.factory 'Facebook', ['$http', ($http) ->
api_url = "http://facebook.com"
app_id = '227387824081363'
api_url = "http://facebook.com"
app_id = Playedbyme.env.facebookAppId

Facebook = (data) ->
angular.extend(this, data)
Expand All @@ -253,7 +225,7 @@ ocarinaServices.factory 'Facebook', ['$http', ($http) ->
Facebook.sendDialog = (playlist_id) ->
FB.ui
method: "send"
link: "http://played-by-me.herokuapp.com/playlists/#{playlist_id}"
link: "http://#{Playedbyme.env.domain}/playlists/#{playlist_id}"

Facebook.getUsersFavoriteArtists = (id, callback) ->
FB.api "/#{id}/music", (res) ->
Expand Down
23 changes: 9 additions & 14 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,16 @@
%title= content_for?(:title) ? yield(:title) : "Playedby.me"
= stylesheet_link_tag "application", media: "all"
= csrf_meta_tags

:javascript
(function(d) {
var id, js, ref;
js = void 0;
id = "facebook-jssdk";
ref = d.getElementsByTagName("script")[0];
if (d.getElementById(id)) {
return;
var Playedbyme = {
env: {
apiURL: "",
domain: window.location.origin,
facebookAppId: "160916744087752",
pusherKey: "#{Rails.configuration.pusher_key}"
}
js = d.createElement("script");
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
return ref.parentNode.insertBefore(js, ref);
})(document);

};

%body.ng-cloak{ ng_controller: 'UserCtrl' }
.logged-out{ ocarina_if: "!auth.loggedIn", ng_include:"'/partials/logged_out'" }
Expand All @@ -37,6 +31,7 @@
= javascript_include_tag "http://js.pusher.com/2.1/pusher.min.js"
= javascript_include_tag "http://connect.soundcloud.com/sdk.js"
= javascript_include_tag "application"

:javascript
SC.initialize({
client_id: "3d6e76640c62f42c02cb78d2c53d0db9"
Expand Down
4 changes: 2 additions & 2 deletions app/views/partials/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
%a{ng_href: "", target: "_blank" } Our Blog
%a{ng_href: "/contact" } Contact
%a{ng_href: "/about" } About Us
%a.legal{ng_href: "//localhost:4400/partials/legal/tos", target: "_blank" } Terms
%a.legal{ng_href: "//localhost:4400/partials/legal/privacy", target: "_blank" } Privacy
%a.legal{ng_href: "//#{Rails.configuration.domain}/partials/legal/tos", target: "_blank" } Terms
%a.legal{ng_href: "//#{Rails.configuration.domain}/partials/legal/privacy", target: "_blank" } Privacy
10 changes: 9 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@
config.smtp_password = ENV['SMTP_PASSWORD'] || 'jarpadarp'

# API URLs
config.api_url = ENV['API_URL'] || 'http://localhost:4400'
config.web_url = ENV['WEB_URL'] || 'http://localhost:4400'
config.mobile_web_url = ENV['MOBILE_WEB_URL'] || 'http://localhost:8000'

# API ID/Secret Keys
config.facebook_app_id = ENV['FACEBOOK_APP_ID'] || raise_for('FACEBOOK_APP_ID')
config.pusher_key = ENV['PUSHER_KEY'] || raise_for('PUSHER_APP_ID')

# Other
config.domain = ENV['DOMAIN'] || 'localhost:4400'

##
# CORS support
config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors", :debug => true, :logger => Rails.logger do
allow do
origins Rails.configuration.mobile_web_url
origins Rails.configuration.mobile_web_url, Rails.configuration.api_url

resource '/api/*',
headers: :any,
Expand Down
14 changes: 11 additions & 3 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,30 @@ def raise_for(str)

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
#

# Email Options
config.smtp_user_name = ENV['SMTP_USER_NAME'] || raise_for('SMTP_USER_NAME')
config.smtp_password = ENV['SMTP_PASSWORD'] || raise_for('SMTP_PASSWORD')

# API URLs
config.api_url = ENV['API_URL'] || raise_for('API_URL')
config.web_url = ENV['WEB_URL'] || raise_for('WEB_URL')
config.mobile_web_url = ENV['MOBILE_WEB_URL'] || raise_for('MOBILE_WEB_URL')

# API ID/Secret Keys
config.facebook_app_id = ENV['FACEBOOK_APP_ID'] || raise_for('FACEBOOK_APP_ID')
config.pusher_key = ENV['PUSHER_KEY'] || raise_for('PUSHER_APP_ID')

# Other
config.domain = ENV['DOMAIN'] || raise_for('DOMAIN')

##
# CORS support
config.middleware.insert_before "ActionDispatch::Static", "Rack::Cors" do
allow do
origins Rails.configuration.mobile_web_url
origins Rails.configuration.mobile_web_url, "http://techstars.playedby.me", "http://yc.playedby.me"

resource '/api/*',
resource '/api/*',
headers: :any,
methods: [:get, :post]
end
Expand Down