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.



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

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,
    invalid_params: /invalid\sparams/i
  }
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#regexesObject

Returns the value of attribute regexes.



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

def regexes
  @regexes
end

#urlsObject

Returns the value of attribute urls.



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

def urls
  @urls
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

#zoneObject

Returns the value of attribute zone.



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

def zone
  @zone
end

Instance Method Details

#fetch_master_proxies(limit: 10) ⇒ Object



50
51
52
53
# File 'lib/luminati/client.rb', line 50

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



44
45
46
47
48
# File 'lib/luminati/client.rb', line 44

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



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

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



25
26
27
28
29
30
# File 'lib/luminati/client.rb', line 25

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



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

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



55
56
57
# File 'lib/luminati/client.rb', line 55

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