Class: LaunchCraft::Auth

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

Defined Under Namespace

Classes: BadLogin, OldVersion

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#passwordObject (readonly)

Returns the value of attribute password.



35
36
37
# File 'lib/launchcraft/auth.rb', line 35

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



35
36
37
# File 'lib/launchcraft/auth.rb', line 35

def username
  @username
end

#uuidObject (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

Returns:

  • (Boolean)


41
42
43
# File 'lib/launchcraft/auth.rb', line 41

def logged?
  @logged
end

#loginObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/launchcraft/auth.rb', line 45

def 
  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