Class: LaunchCraft::Auth
- Inherits:
-
Object
- Object
- LaunchCraft::Auth
- Defined in:
- lib/launchcraft/auth.rb
Defined Under Namespace
Classes: BadLogin, OldVersion
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
-
#initialize(username, password = nil) ⇒ Auth
constructor
A new instance of Auth.
- #logged? ⇒ Boolean
- #login ⇒ Object
Constructor Details
#initialize(username, password = nil) ⇒ Auth
Returns a new instance of Auth.
37 38 39 |
# File 'lib/launchcraft/auth.rb', line 37 def initialize (username, password=nil) @username, @password, @uuid, @logged = username, password, nil, false end |
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
35 36 37 |
# File 'lib/launchcraft/auth.rb', line 35 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
35 36 37 |
# File 'lib/launchcraft/auth.rb', line 35 def username @username end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
35 36 37 |
# File 'lib/launchcraft/auth.rb', line 35 def uuid @uuid end |
Instance Method Details
#logged? ⇒ Boolean
41 42 43 |
# File 'lib/launchcraft/auth.rb', line 41 def logged? @logged end |
#login ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/launchcraft/auth.rb', line 45 def login post(Config['url.login'], "version=13&user=#{CGI.escape(@username)}&password=#{CGI.escape(@password)}", { 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Language' => 'en-US' }).tap {|b| if (@logged = !!(b =~ /^.+?:.+?:(.+?):(.+?):?$/)) @username, @uuid = $1, $2 elsif b =~ /old/i raise OldVersion else raise BadLogin end } self end |