Class: MinecraftAuth::Account
- Inherits:
-
Object
- Object
- MinecraftAuth::Account
- Defined in:
- lib/minecraft_auth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client_token ⇒ Object
readonly
Returns the value of attribute client_token.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#profiles ⇒ Object
readonly
Returns the value of attribute profiles.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(username, password) ⇒ Account
constructor
A new instance of Account.
Constructor Details
#initialize(username, password) ⇒ Account
Returns a new instance of Account.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/minecraft_auth.rb', line 32 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_token ⇒ Object (readonly)
Returns the value of attribute access_token.
28 29 30 |
# File 'lib/minecraft_auth.rb', line 28 def access_token @access_token end |
#client_token ⇒ Object (readonly)
Returns the value of attribute client_token.
29 30 31 |
# File 'lib/minecraft_auth.rb', line 29 def client_token @client_token end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
27 28 29 |
# File 'lib/minecraft_auth.rb', line 27 def password @password end |
#profiles ⇒ Object (readonly)
Returns the value of attribute profiles.
30 31 32 |
# File 'lib/minecraft_auth.rb', line 30 def profiles @profiles end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
26 27 28 |
# File 'lib/minecraft_auth.rb', line 26 def username @username end |