Class: Asianodds::Login

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, password) ⇒ Login

Initialize the user with a username and password



13
14
15
16
17
18
19
20
21
22
# File 'lib/asianodds/login.rb', line 13

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

  # Asianodds requests the password to be MD5 hashed
  @password_md5 = Digest::MD5.hexdigest(@password)


  self.
end

Instance Attribute Details

#ao_keyObject (readonly)

Returns the value of attribute ao_key.



10
11
12
# File 'lib/asianodds/login.rb', line 10

def ao_key
  @ao_key
end

#ao_tokenObject (readonly)

Returns the value of attribute ao_token.



10
11
12
# File 'lib/asianodds/login.rb', line 10

def ao_token
  @ao_token
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



10
11
12
# File 'lib/asianodds/login.rb', line 10

def base_url
  @base_url
end

#codeObject (readonly)

Returns the value of attribute code.



10
11
12
# File 'lib/asianodds/login.rb', line 10

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/asianodds/login.rb', line 10

def message
  @message
end

#successful_loginObject (readonly)

Returns the value of attribute successful_login.



10
11
12
# File 'lib/asianodds/login.rb', line 10

def 
  @successful_login
end

Instance Method Details

#loginObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/asianodds/login.rb', line 24

def 
  response = Faraday.get("#{BASE_API_URL}/Login?username=#{@user}&password=#{@password_md5}")
  attributes = JSON.parse(response.body)

  @code = attributes["Code"]
  @ao_token = attributes["Result"]["Token"]
  @ao_key = attributes["Result"]["Key"]
  @base_url = attributes["Result"]["Url"]
  @successful_login = attributes["Result"]["SuccessfulLogin"]
  @message = attributes["Result"]["TextMessage"]
end