Class: Luminati::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/luminati/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, zone: :gen, port: 22225) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/luminati/client.rb', line 7

def initialize(username, password, zone: :gen, port: 22225)
  self.username   =   username
  self.password   =   password
  
  self.zone       =   zone
  self.port       =   port
  
  self.urls       =   {
    master_proxy: "http://client.luminati.io/api/get_super_proxy"
  }
  
  self.regexes    =   {
    failed_auth: /failed\sauth/i
  }
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/luminati/client.rb', line 5

def password
  @password
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/luminati/client.rb', line 5

def port
  @port
end

#regexesObject

Returns the value of attribute regexes.



5
6
7
# File 'lib/luminati/client.rb', line 5

def regexes
  @regexes
end

#urlsObject

Returns the value of attribute urls.



5
6
7
# File 'lib/luminati/client.rb', line 5

def urls
  @urls
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/luminati/client.rb', line 5

def username
  @username
end

#zoneObject

Returns the value of attribute zone.



5
6
7
# File 'lib/luminati/client.rb', line 5

def zone
  @zone
end

Instance Method Details

#fetch_master_proxies(limit: 10) ⇒ Object



48
49
50
51
# File 'lib/luminati/client.rb', line 48

def fetch_master_proxies(limit: 10)
  arguments       =   {format: :json, limit: limit}
  proxies         =   get_response(self.urls[:master_proxy], arguments)
end

#fetch_master_proxy(country: nil) ⇒ Object



42
43
44
45
46
# File 'lib/luminati/client.rb', line 42

def fetch_master_proxy(country: nil)
  arguments       =   {raw:  1}
  arguments.merge!(country: country) if country
  proxy           =   get_response(self.urls[:master_proxy], arguments)
end

#generate_user_auth(country: nil, dns_resolution: :remote, session: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/luminati/client.rb', line 30

def generate_user_auth(country: nil, dns_resolution: :remote, session: nil)
  country                 =   (country && country.to_s.present?) ? "-country-#{country}" : ""
  zoned                   =   "-zone-#{self.zone}"
  dns_resolution          =   "-dns-#{dns_resolution}"
  session_id              =   (session && session.to_s.present?) ? session : generate_session_id
  session                 =   "-session-#{session_id}"
  
  user                    =   "#{self.username}#{zoned}#{country}#{dns_resolution}#{session}"
  
  return {username: user, session_id: session_id}
end

#get_connection(country: nil, dns_resolution: :remote, session: nil) ⇒ Object



23
24
25
26
27
28
# File 'lib/luminati/client.rb', line 23

def get_connection(country: nil, dns_resolution: :remote, session: nil)
  ip_address              =   self.fetch_master_proxy
  user_auth               =   self.generate_user_auth(country: country, dns_resolution: dns_resolution, session: session)
  
  return {ip_address: ip_address, port: self.port, password: self.password}.merge(user_auth)
end

#ping_master_proxies(proxies, port: self.port) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/luminati/client.rb', line 57

def ping_master_proxies(proxies, port: self.port)
  data            =   {}

  proxies.each do |proxy|
    data[proxy]   =   self.ping_master_proxy(proxy, port)
  end if proxies && proxies.any?
  
  return data
end

#ping_master_proxy(address, port: self.port) ⇒ Object



53
54
55
# File 'lib/luminati/client.rb', line 53

def ping_master_proxy(address, port: self.port)
  response        =   get_response("http://#{address}:#{port}/ping")
end