2012-09-02 02:03:19 +04:00
|
|
|
class BeatHaven.Models.VK extends Backbone.Model
|
|
|
|
|
|
|
|
session_length: 3600 # seconds
|
|
|
|
Music: null
|
2012-09-09 17:48:24 +04:00
|
|
|
BITMASK: 8
|
2012-09-02 02:03:19 +04:00
|
|
|
|
|
|
|
popup: ->
|
|
|
|
alert(1)
|
|
|
|
|
|
|
|
init: ->
|
|
|
|
@Music = new VkMusic()
|
|
|
|
BH.log "Initializing Vkontakte API ..."
|
|
|
|
window.VK.init(apiId: VK_APP_ID)
|
|
|
|
BH.VK.auth()
|
|
|
|
# VK.Widgets.Like("vk-like", {type: "mini", height: 20, pageUrl: "http://beathaven.org/", text: "Like"})
|
|
|
|
|
2012-09-09 17:48:24 +04:00
|
|
|
auth: (callback) ->
|
2012-09-02 02:03:19 +04:00
|
|
|
BH.log "Requesting new Vkontakte session ..."
|
|
|
|
window.VK.Auth.getLoginStatus (response) ->
|
|
|
|
BH.VK.auth_info(response)
|
2012-09-09 17:48:24 +04:00
|
|
|
callback() if callback?
|
2012-09-02 02:03:19 +04:00
|
|
|
false
|
2012-09-09 17:48:24 +04:00
|
|
|
, window.BH.VK.BITMASK
|
2012-09-02 02:03:19 +04:00
|
|
|
false
|
|
|
|
|
|
|
|
auth_info: (response) ->
|
|
|
|
if typeof response isnt "undefined" and response.session?
|
|
|
|
BH.User.set(vk_session: response.session)
|
|
|
|
BH.User.auth()
|
|
|
|
|
|
|
|
if response.session.expire?
|
|
|
|
expire_in = response.session.expire * 1000 - new Date().getTime()
|
|
|
|
# time is an illusion...
|
|
|
|
expire_in = @session_length * 1000
|
|
|
|
BH.log "Session will expire in #{Math.round(expire_in / 1000)} seconds"
|
|
|
|
setTimeout ->
|
|
|
|
BH.log "Session expired"
|
|
|
|
BH.VK.auth()
|
|
|
|
, expire_in + 1000
|
|
|
|
else
|
|
|
|
BH.log "Not authorized"
|
|
|
|
|
2012-09-09 17:48:24 +04:00
|
|
|
|
2012-09-02 02:03:19 +04:00
|
|
|
set_favorites: ->
|
|
|
|
window.VK.Api.call "audio.get", uid: BH.User.vk_id(), (response) ->
|
|
|
|
BH.User.set_favorites(response.response)
|