Class: Luminati::Client
- Inherits:
-
Object
- Object
- Luminati::Client
- Defined in:
- lib/luminati/client.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#urls ⇒ Object
Returns the value of attribute urls.
-
#username ⇒ Object
Returns the value of attribute username.
-
#zone ⇒ Object
Returns the value of attribute zone.
Instance Method Summary collapse
- #fetch_master_proxies(limit: 10) ⇒ Object
- #fetch_master_proxy(country: nil) ⇒ Object
- #generate_user_auth(country: nil, dns_resolution: :remote, session: nil) ⇒ Object
- #get_connection(country: nil, dns_resolution: :remote, session: nil) ⇒ Object
-
#initialize(username, password, zone: :gen, port: 22225) ⇒ Client
constructor
A new instance of Client.
- #ping_master_proxies(proxies, port: self.port) ⇒ Object
- #ping_master_proxy(address, port: self.port) ⇒ Object
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 |
# 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" } end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/luminati/client.rb', line 5 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/luminati/client.rb', line 5 def port @port end |
#urls ⇒ Object
Returns the value of attribute urls.
5 6 7 |
# File 'lib/luminati/client.rb', line 5 def urls @urls end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/luminati/client.rb', line 5 def username @username end |
#zone ⇒ Object
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
46 47 48 49 50 |
# File 'lib/luminati/client.rb', line 46 def fetch_master_proxies(limit: 10) arguments = {format: :json, limit: limit} response = get_response(self.urls[:master_proxy], arguments) proxies = (response && response.body) ? response.body : nil end |
#fetch_master_proxy(country: nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/luminati/client.rb', line 38 def fetch_master_proxy(country: nil) arguments = {raw: 1} arguments.merge!(country: country) if country response = get_response(self.urls[:master_proxy], arguments) proxy = (response && response.body) ? response.body : nil end |
#generate_user_auth(country: nil, dns_resolution: :remote, session: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/luminati/client.rb', line 26 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
19 20 21 22 23 24 |
# File 'lib/luminati/client.rb', line 19 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
52 53 54 55 |
# File 'lib/luminati/client.rb', line 52 def ping_master_proxy(address, port: self.port) response = get_response("http://#{address}:#{port}/ping") return (response && response.body) ? response.body : nil end |