Class: Contacts19::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/contacts19/base.rb

Direct Known Subclasses

Aol, Gmail, Hotmail, Mailru, Plaxo, Yahoo

Instance Method Summary collapse

Constructor Details

#initialize(login, password, options = {}) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
19
20
21
# File 'lib/contacts19/base.rb', line 14

def initialize(, password, options={})
  @login = 
  @password = password
  @captcha_token = options[:captcha_token]
  @captcha_response = options[:captcha_response]
  @connections = {}
  connect
end

Instance Method Details

#connectObject



23
24
25
26
# File 'lib/contacts19/base.rb', line 23

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/contacts19/base.rb', line 28

def connected?
  @cookies && !@cookies.empty?
end

#contacts(options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/contacts19/base.rb', line 32

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

#loginObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/contacts19/base.rb', line 49

def 
  @attempt ||= 0
  @attempt += 1
        
  if @attempt == 1
    @login
  else
    if @login.include?("@#{domain}")
      @login.sub("@#{domain}","")
    else
      "#{@login}@#{domain}"
    end
  end
end

#passwordObject



64
65
66
# File 'lib/contacts19/base.rb', line 64

def password
  @password
end

#skip_gzip?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/contacts19/base.rb', line 68

def skip_gzip?
  false
end