Class: PlayerHandler

Inherits:
RubyPitaya::HandlerBase show all
Defined in:
lib/rubypitaya/app-template/app/handlers/player_handler.rb

Instance Attribute Summary

Attributes inherited from RubyPitaya::HandlerBase

#config, #log, #objects, #params, #postman, #services, #session, #setup

Instance Method Summary collapse

Methods inherited from RubyPitaya::HandlerBase

authenticated_action_name?, #initialize, non_authenticated_actions, objects, #set_attributes

Constructor Details

This class inherits a constructor from RubyPitaya::HandlerBase

Instance Method Details

#authenticateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rubypitaya/app-template/app/handlers/player_handler.rb', line 50

def authenticate
  user_id = @params[:userId]

  player = Player.find_by_user_id(user_id)
  player = bll.create_new_player(@setup, @config) if player.nil?

  @session.uid = player.user_id

  bind_session_response = @postman.bind_session(@session)

  unless bind_session_response.dig(:error, :code).nil?
    raise RubyPitaya::RouteError.new(StatusCodes::CODE_AUTHENTICATION_ERROR, 'Error to authenticate')
  end

  response = {
    code: StatusCodes::CODE_OK,
    data: player.to_hash,
  }
end

#getInfoObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/rubypitaya/app-template/app/handlers/player_handler.rb', line 70

def getInfo
  user_id = @session.uid

  player = Player.find_by_user_id(user_id)

  response = {
    code: StatusCodes::CODE_OK,
    data: player.to_hash,
  }
end