Class: Contacts::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/contacts/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(login, password) ⇒ Base
Returns a new instance of Base.
15
16
17
18
19
20
|
# File 'lib/contacts/base.rb', line 15
def initialize(login, password)
@login = login
@password = password
@connections = {}
connect
end
|
Instance Method Details
#connect ⇒ Object
22
23
24
25
|
# File 'lib/contacts/base.rb', line 22
def connect
raise AuthenticationError, "Login and password must not be nil, login: #{@login.inspect}, password: #{@password.inspect}" if @login.nil? || @login.empty? || @password.nil? || @password.empty?
real_connect
end
|
#connected? ⇒ Boolean
27
28
29
|
# File 'lib/contacts/base.rb', line 27
def connected?
@cookies && !@cookies.empty?
end
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/contacts/base.rb', line 31
def contacts(options = {})
return @contacts if @contacts
if connected?
url = URI.parse(contact_list_url)
http = open_http(url)
resp, data = http.get("#{url.path}?#{url.query}",
"Cookie" => @cookies
)
if resp.code_type != Net::HTTPOK
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
end
parse(data, options)
end
end
|
#login ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/contacts/base.rb', line 48
def login
@attempt ||= 0
@attempt += 1
if @attempt == 1
@login
else
if @login.include?("@#{domain}")
@login.sub("@#{domain}","")
else
"#{@login}@#{domain}"
end
end
end
|
#password ⇒ Object
63
64
65
|
# File 'lib/contacts/base.rb', line 63
def password
@password
end
|