Class: CompanionApi::Resources::Login

Inherits:
Object
  • Object
show all
Defined in:
lib/companion_api/resources/login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ Login

Returns a new instance of Login.



9
10
11
# File 'lib/companion_api/resources/login.rb', line 9

def initialize(profile)
  @profile = profile
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



5
6
7
# File 'lib/companion_api/resources/login.rb', line 5

def 
  @account
end

#characterObject

Returns the value of attribute character.



7
8
9
# File 'lib/companion_api/resources/login.rb', line 7

def character
  @character
end

#charactersObject

Returns the value of attribute characters.



6
7
8
# File 'lib/companion_api/resources/login.rb', line 6

def characters
  @characters
end

#profileObject

Returns the value of attribute profile.



4
5
6
# File 'lib/companion_api/resources/login.rb', line 4

def profile
  @profile
end

Instance Method Details

#character_statusObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/companion_api/resources/login.rb', line 90

def character_status
  req = CompanionApi::Request.new(
    uri:      @profile.get('region'),
    endpoint: '/character/login-status',
    token:    @profile.get("token"),
  )

  res = req.get!
  JSON.parse(res.body)
end

#load_characterObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/companion_api/resources/login.rb', line 75

def load_character
  req = CompanionApi::Request.new(
    uri:      @profile.get('region'),
    endpoint: '/login/character',
    token:    @profile.get("token"),
  )

  res = req.get!
  json = JSON.parse(res.body)

  @character = json

  character_status
end

#post_authObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/companion_api/resources/login.rb', line 13

def post_auth
  req = CompanionApi::Request.new(
    uri:       CompanionApi::Request::URI,
    endpoint:  '/login/auth',
    requestId: CompanionApi.uuid,
    token:     @profile.get('token'),
    query:     {
      token:      @profile.get('token'),
      uid:        @profile.get('uid'),
      request_id: CompanionApi.uuid,
    },
  )

  res = req.post!
  JSON.parse(res.body)
end

#select_character(cid) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/companion_api/resources/login.rb', line 56

def select_character(cid)
  req = CompanionApi::Request.new(
    uri:      CompanionApi::Request::URI,
    endpoint: "/login/characters/#{cid}",
    token:    @profile.get("token"),
    json:     {
      'appLocaleType' => 'EU',
    },
  )

  res = req.post!
  json = JSON.parse(res.body)

  region = json["region"].chomp("/")
  @profile.set("region", region)

  load_character
end