Class: MinecraftAuth::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/minecraft_auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Account

Returns a new instance of Account.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/minecraft_auth.rb', line 20

def initialize(username, password)
  @username = username
  @password = password

  response = HTTParty.post("#{PROTOCOL}#{BASE_URL}#{ENDPOINT}",
    :body => {
        :"agent" => {
        :"name" => "Minecraft",
        :"version" => 1
      },
      :"username" => "#{@username}",
      :"password" => "#{@password}"
    }.to_json,
    :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
  )
  # No Error
  if not response['error']
    @access_token = response['accessToken']
    @client_token = response['clientToken']
    raw_profiles = response['availableProfiles']
    raw_selected = response['selectedProfile']
    @profiles = Array.new
    raw_profiles.each do |profile|
      selected = raw_selected['name'] == profile['name'] and raw_selected['id'] == profile['id']
      @profiles << Profile.new(profile['name'], profile['id'], selected)
    end
  # Error in response  
  else
    raise AccountError, response["errorMessage"]
  end
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



16
17
18
# File 'lib/minecraft_auth.rb', line 16

def access_token
  @access_token
end

#client_tokenObject (readonly)

Returns the value of attribute client_token.



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

def client_token
  @client_token
end

#passwordObject (readonly)

Returns the value of attribute password.



15
16
17
# File 'lib/minecraft_auth.rb', line 15

def password
  @password
end

#profilesObject (readonly)

Returns the value of attribute profiles.



18
19
20
# File 'lib/minecraft_auth.rb', line 18

def profiles
  @profiles
end

#usernameObject (readonly)

Returns the value of attribute username.



14
15
16
# File 'lib/minecraft_auth.rb', line 14

def username
  @username
end