luminati 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 605a01798b13966cac5eb5163813a1efdb5ad518
4
- data.tar.gz: 5e39a3b73d23752baee3bb6f915698f5e50caf56
3
+ metadata.gz: 9adc62b4fd44c0b0e920daf365d0ccc4af9388b8
4
+ data.tar.gz: cf70c9548e92575255cd5df94710e7cd8998fee7
5
5
  SHA512:
6
- metadata.gz: 910d8e208e0e68451f752acc2329db94c083fccb6fdd5459e804188dd46ff54eed8025fbb23bf5a095937b96f1c298c76be1247377cb0ae9df6688a001c8aca2
7
- data.tar.gz: c3b3016b4ee55dabcb6b9e5ecb052db461512db235a7c31f6a374fc4a5bb8e7d3e5bf9778557a8406d525268cf7d93680c4fca15e221c3b27134b53c6651fd2b
6
+ metadata.gz: efebc81f6a72f0ca7cb1cd43121c9aaa21c9148b4554e61bc1ec96856ed742d7a6fca96c0491acc44f63dc6e301c6406493a0a6295b77f3c1b88f05aa197c463
7
+ data.tar.gz: 757cc46a7f860a163ec39e53cd93167cac9e077c37818d91fd76cbb2777f39e0e72be55f84aba56dc92c0436334921d33b3a688af238d24fd21af1088b58958d
@@ -1,5 +1,6 @@
1
1
  module Luminati
2
- VERSION = "0.0.1"
3
-
2
+ VERSION = "0.0.2"
3
+
4
+ require File.join(File.dirname(__FILE__), 'luminati/errors')
4
5
  require File.join(File.dirname(__FILE__), 'luminati/client')
5
6
  end
@@ -2,7 +2,7 @@ require 'faraday'
2
2
 
3
3
  module Luminati
4
4
  class Client
5
- attr_accessor :username, :password, :zone, :port, :urls
5
+ attr_accessor :username, :password, :zone, :port, :urls, :regexes
6
6
 
7
7
  def initialize(username, password, zone: :gen, port: 22225)
8
8
  self.username = username
@@ -14,6 +14,10 @@ module Luminati
14
14
  self.urls = {
15
15
  master_proxy: "http://client.luminati.io/api/get_super_proxy"
16
16
  }
17
+
18
+ self.regexes = {
19
+ failed_auth: /failed\sauth/i
20
+ }
17
21
  end
18
22
 
19
23
  def get_connection(country: nil, dns_resolution: :remote, session: nil)
@@ -38,20 +42,16 @@ module Luminati
38
42
  def fetch_master_proxy(country: nil)
39
43
  arguments = {raw: 1}
40
44
  arguments.merge!(country: country) if country
41
-
42
- response = get_response(self.urls[:master_proxy], arguments)
43
- proxy = (response && response.body) ? response.body : nil
45
+ proxy = get_response(self.urls[:master_proxy], arguments)
44
46
  end
45
47
 
46
48
  def fetch_master_proxies(limit: 10)
47
49
  arguments = {format: :json, limit: limit}
48
- response = get_response(self.urls[:master_proxy], arguments)
49
- proxies = (response && response.body) ? response.body : nil
50
+ proxies = get_response(self.urls[:master_proxy], arguments)
50
51
  end
51
52
 
52
53
  def ping_master_proxy(address, port: self.port)
53
54
  response = get_response("http://#{address}:#{port}/ping")
54
- return (response && response.body) ? response.body : nil
55
55
  end
56
56
 
57
57
  def ping_master_proxies(proxies, port: self.port)
@@ -70,7 +70,7 @@ module Luminati
70
70
  end
71
71
 
72
72
  def format_username(username)
73
- username = (username =~ /-zone-([a-z0-9]*)/i).nil? ? "#{username}-zone-#{self.zone}" : username
73
+ username = (username =~ /-zone-([a-z0-9]*)/i).nil? ? "#{username}-zone-#{self.zone}" : username
74
74
  end
75
75
 
76
76
  def get_response(url, arguments = {}, options = {})
@@ -78,10 +78,19 @@ module Luminati
78
78
 
79
79
  connection = build_connection(options)
80
80
  response = connection.get(url, arguments)
81
+ response = (response && response.body) ? response.body : nil
82
+
83
+ check_response_for_errors(response)
81
84
 
82
85
  return response
83
86
  end
84
87
 
88
+ def check_response_for_errors(response)
89
+ if (response && response.is_a?(String) && response.present?)
90
+ raise Luminati::FailedAuthError, "Failed to authenticate your account with Luminati.io. Please check your credentials or the contract for your account." if response =~ self.regexes[:failed_auth]
91
+ end
92
+ end
93
+
85
94
  def build_connection(options = {})
86
95
  options.merge!(:ssl => {:verify => false})
87
96
 
@@ -0,0 +1,3 @@
1
+ module Luminati
2
+ class FailedAuthError < StandardError; end
3
+ end
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'luminati'
6
- s.version = '0.0.1'
6
+ s.version = '0.0.2'
7
7
 
8
8
  s.homepage = "https://github.com/Agiley/Luminati"
9
9
  s.email = "sebastian@agiley.se"
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  Rakefile
27
27
  lib/luminati.rb
28
28
  lib/luminati/client.rb
29
+ lib/luminati/errors.rb
29
30
  luminati.gemspec
30
31
  spec/spec_helper.rb
31
32
  ]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luminati
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Johnsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-15 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -79,6 +79,7 @@ files:
79
79
  - Rakefile
80
80
  - lib/luminati.rb
81
81
  - lib/luminati/client.rb
82
+ - lib/luminati/errors.rb
82
83
  - luminati.gemspec
83
84
  - spec/spec_helper.rb
84
85
  homepage: https://github.com/Agiley/Luminati