Class: Play::App

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/play/app.rb,
lib/play/app/api.rb

Instance Method Summary collapse

Instance Method Details

#api_authenticateObject



107
108
109
110
111
112
113
# File 'lib/play/app/api.rb', line 107

def api_authenticate
  if api_user
    true
  else
    halt error("You must supply a valid `user_login` in your requests.")
  end
end

#api_userObject



102
103
104
105
# File 'lib/play/app/api.rb', line 102

def api_user
  Play::User.(params[:user_login]) ||
  Play::User.find_by_alias(params[:user_login])
end

#current_userObject



17
18
19
# File 'lib/play/app.rb', line 17

def current_user
  session['user_id'].blank? ? nil : User.find_by_id(session['user_id'])
end

#error(msg) ⇒ Object



115
116
117
# File 'lib/play/app/api.rb', line 115

def error(msg)
  { :error => msg }.to_json
end

#music_response(song) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/play/app/api.rb', line 119

def music_response(song)
  {
    'artist_name' => song.artist_name,
    'song_title'  => song.title,
    'album_name'  => song.album_name
  }.to_json
end