luminati 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +39 -0
- data/LICENSE +22 -0
- data/README.md +5 -0
- data/Rakefile +86 -0
- data/lib/luminati.rb +5 -0
- data/lib/luminati/client.rb +98 -0
- data/luminati.gemspec +36 -0
- data/spec/spec_helper.rb +26 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 605a01798b13966cac5eb5163813a1efdb5ad518
|
4
|
+
data.tar.gz: 5e39a3b73d23752baee3bb6f915698f5e50caf56
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 910d8e208e0e68451f752acc2329db94c083fccb6fdd5459e804188dd46ff54eed8025fbb23bf5a095937b96f1c298c76be1247377cb0ae9df6688a001c8aca2
|
7
|
+
data.tar.gz: c3b3016b4ee55dabcb6b9e5ecb052db461512db235a7c31f6a374fc4a5bb8e7d3e5bf9778557a8406d525268cf7d93680c4fca15e221c3b27134b53c6651fd2b
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
Luminati (0.0.1)
|
5
|
+
faraday (>= 0.9)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
faraday (0.9.1)
|
12
|
+
multipart-post (>= 1.2, < 3)
|
13
|
+
metaclass (0.0.4)
|
14
|
+
mocha (1.1.0)
|
15
|
+
metaclass (~> 0.0.1)
|
16
|
+
multipart-post (2.0.0)
|
17
|
+
rake (10.4.2)
|
18
|
+
rspec (3.2.0)
|
19
|
+
rspec-core (~> 3.2.0)
|
20
|
+
rspec-expectations (~> 3.2.0)
|
21
|
+
rspec-mocks (~> 3.2.0)
|
22
|
+
rspec-core (3.2.0)
|
23
|
+
rspec-support (~> 3.2.0)
|
24
|
+
rspec-expectations (3.2.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.2.0)
|
27
|
+
rspec-mocks (3.2.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.2.0)
|
30
|
+
rspec-support (3.2.1)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
Luminati!
|
37
|
+
mocha
|
38
|
+
rake
|
39
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Sebastian Johnsson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
## helper functions
|
2
|
+
|
3
|
+
def name
|
4
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
5
|
+
end
|
6
|
+
|
7
|
+
def version
|
8
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
9
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
10
|
+
end
|
11
|
+
|
12
|
+
def gemspec_file
|
13
|
+
"#{name}.gemspec"
|
14
|
+
end
|
15
|
+
|
16
|
+
def gem_file
|
17
|
+
"#{name}-#{version}.gem"
|
18
|
+
end
|
19
|
+
|
20
|
+
def replace_header(head, header_name)
|
21
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
# Rspec 2.0
|
26
|
+
require 'rspec/core/rake_task'
|
27
|
+
|
28
|
+
desc 'Default: run specs'
|
29
|
+
task :default => :spec
|
30
|
+
RSpec::Core::RakeTask.new do |t|
|
31
|
+
t.pattern = "spec/**/*_spec.rb"
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new('rcov') do |t|
|
35
|
+
t.pattern = "spec/**/*_spec.rb"
|
36
|
+
t.rcov = true
|
37
|
+
t.rcov_opts = ['--exclude', 'spec']
|
38
|
+
end
|
39
|
+
|
40
|
+
rescue LoadError
|
41
|
+
puts "Rspec not available. Install it with: gem install rspec"
|
42
|
+
end
|
43
|
+
|
44
|
+
## release management tasks
|
45
|
+
|
46
|
+
desc "Commit, create tag v#{version} and build and push #{gem_file} to Rubygems"
|
47
|
+
task :release => :build do
|
48
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
49
|
+
sh "git tag v#{version}"
|
50
|
+
sh "git push"
|
51
|
+
sh "git push origin v#{version}"
|
52
|
+
sh "gem push pkg/#{gem_file}"
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "Build #{gem_file} into the pkg directory"
|
56
|
+
task :build => :gemspec do
|
57
|
+
sh "mkdir -p pkg"
|
58
|
+
sh "gem build #{gemspec_file}"
|
59
|
+
sh "mv #{gem_file} pkg"
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "Generate #{gemspec_file}"
|
63
|
+
task :gemspec do
|
64
|
+
# read spec file and split out manifest section
|
65
|
+
spec = File.read(gemspec_file)
|
66
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
67
|
+
|
68
|
+
# replace name version and date
|
69
|
+
replace_header(head, :name)
|
70
|
+
replace_header(head, :version)
|
71
|
+
|
72
|
+
# determine file list from git ls-files
|
73
|
+
files = `git ls-files`.
|
74
|
+
split("\n").
|
75
|
+
sort.
|
76
|
+
reject { |file| file =~ /^\./ }.
|
77
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
78
|
+
map { |file| " #{file}" }.
|
79
|
+
join("\n")
|
80
|
+
|
81
|
+
# piece file back together and write
|
82
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
83
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
84
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
85
|
+
puts "Updated #{gemspec_file}"
|
86
|
+
end
|
data/lib/luminati.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Luminati
|
4
|
+
class Client
|
5
|
+
attr_accessor :username, :password, :zone, :port, :urls
|
6
|
+
|
7
|
+
def initialize(username, password, zone: :gen, port: 22225)
|
8
|
+
self.username = username
|
9
|
+
self.password = password
|
10
|
+
|
11
|
+
self.zone = zone
|
12
|
+
self.port = port
|
13
|
+
|
14
|
+
self.urls = {
|
15
|
+
master_proxy: "http://client.luminati.io/api/get_super_proxy"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_connection(country: nil, dns_resolution: :remote, session: nil)
|
20
|
+
ip_address = self.fetch_master_proxy
|
21
|
+
user_auth = self.generate_user_auth(country: country, dns_resolution: dns_resolution, session: session)
|
22
|
+
|
23
|
+
return {ip_address: ip_address, port: self.port, password: self.password}.merge(user_auth)
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_user_auth(country: nil, dns_resolution: :remote, session: nil)
|
27
|
+
country = (country && country.to_s.present?) ? "-country-#{country}" : ""
|
28
|
+
zoned = "-zone-#{self.zone}"
|
29
|
+
dns_resolution = "-dns-#{dns_resolution}"
|
30
|
+
session_id = (session && session.to_s.present?) ? session : generate_session_id
|
31
|
+
session = "-session-#{session_id}"
|
32
|
+
|
33
|
+
user = "#{self.username}#{zoned}#{country}#{dns_resolution}#{session}"
|
34
|
+
|
35
|
+
return {username: user, session_id: session_id}
|
36
|
+
end
|
37
|
+
|
38
|
+
def fetch_master_proxy(country: nil)
|
39
|
+
arguments = {raw: 1}
|
40
|
+
arguments.merge!(country: country) if country
|
41
|
+
|
42
|
+
response = get_response(self.urls[:master_proxy], arguments)
|
43
|
+
proxy = (response && response.body) ? response.body : nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def fetch_master_proxies(limit: 10)
|
47
|
+
arguments = {format: :json, limit: limit}
|
48
|
+
response = get_response(self.urls[:master_proxy], arguments)
|
49
|
+
proxies = (response && response.body) ? response.body : nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def ping_master_proxy(address, port: self.port)
|
53
|
+
response = get_response("http://#{address}:#{port}/ping")
|
54
|
+
return (response && response.body) ? response.body : nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def ping_master_proxies(proxies, port: self.port)
|
58
|
+
data = {}
|
59
|
+
|
60
|
+
proxies.each do |proxy|
|
61
|
+
data[proxy] = self.ping_master_proxy(proxy, port)
|
62
|
+
end if proxies && proxies.any?
|
63
|
+
|
64
|
+
return data
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def generate_session_id
|
69
|
+
Digest::SHA1.hexdigest([Time.now, rand].join)
|
70
|
+
end
|
71
|
+
|
72
|
+
def format_username(username)
|
73
|
+
username = (username =~ /-zone-([a-z0-9]*)/i).nil? ? "#{username}-zone-#{self.zone}" : username
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_response(url, arguments = {}, options = {})
|
77
|
+
arguments.merge!(user: format_username(self.username), key: self.password)
|
78
|
+
|
79
|
+
connection = build_connection(options)
|
80
|
+
response = connection.get(url, arguments)
|
81
|
+
|
82
|
+
return response
|
83
|
+
end
|
84
|
+
|
85
|
+
def build_connection(options = {})
|
86
|
+
options.merge!(:ssl => {:verify => false})
|
87
|
+
|
88
|
+
connection = Faraday.new(options) do |builder|
|
89
|
+
builder.request :retry, max: 3, exceptions: ['StandardError', 'Timeout::Error']
|
90
|
+
builder.response :json, content_type: /\bjson$/
|
91
|
+
builder.adapter Faraday.default_adapter
|
92
|
+
end
|
93
|
+
|
94
|
+
return connection
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
data/luminati.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
3
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
|
4
|
+
|
5
|
+
s.name = 'luminati'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
|
8
|
+
s.homepage = "https://github.com/Agiley/Luminati"
|
9
|
+
s.email = "sebastian@agiley.se"
|
10
|
+
s.authors = ["Sebastian Johnsson"]
|
11
|
+
s.description = "Ruby-wrapper for communicating with the Luminati.io-network."
|
12
|
+
s.summary = "Ruby-wrapper for communicating with the Luminati.io-network."
|
13
|
+
|
14
|
+
s.add_dependency "faraday", ">= 0.9"
|
15
|
+
|
16
|
+
s.add_development_dependency 'rake'
|
17
|
+
s.add_development_dependency 'rspec'
|
18
|
+
s.add_development_dependency 'mocha'
|
19
|
+
|
20
|
+
# = MANIFEST =
|
21
|
+
s.files = %w[
|
22
|
+
Gemfile
|
23
|
+
Gemfile.lock
|
24
|
+
LICENSE
|
25
|
+
README.md
|
26
|
+
Rakefile
|
27
|
+
lib/luminati.rb
|
28
|
+
lib/luminati/client.rb
|
29
|
+
luminati.gemspec
|
30
|
+
spec/spec_helper.rb
|
31
|
+
]
|
32
|
+
# = MANIFEST =
|
33
|
+
|
34
|
+
s.test_files = s.files.select { |path| path =~ %r{^spec/*/.+\.rb} }
|
35
|
+
end
|
36
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$LOAD_PATH << "." unless $LOAD_PATH.include?(".")
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "rubygems"
|
5
|
+
require "bundler"
|
6
|
+
|
7
|
+
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
|
8
|
+
raise RuntimeError, "Your bundler version is too old." +
|
9
|
+
"Run `gem install bundler` to upgrade."
|
10
|
+
end
|
11
|
+
|
12
|
+
# Set up load paths for all bundled gems
|
13
|
+
Bundler.setup
|
14
|
+
rescue Bundler::GemNotFound
|
15
|
+
raise RuntimeError, "Bundler couldn't find some gems." +
|
16
|
+
"Did you run \`bundlee install\`?"
|
17
|
+
end
|
18
|
+
|
19
|
+
#require "active_record"
|
20
|
+
Bundler.require
|
21
|
+
|
22
|
+
require File.expand_path('../../lib/luminati', __FILE__)
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.mock_with :mocha
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: luminati
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Johnsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mocha
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruby-wrapper for communicating with the Luminati.io-network.
|
70
|
+
email: sebastian@agiley.se
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/luminati.rb
|
81
|
+
- lib/luminati/client.rb
|
82
|
+
- luminati.gemspec
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
homepage: https://github.com/Agiley/Luminati
|
85
|
+
licenses: []
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.3.5
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.4.5
|
104
|
+
signing_key:
|
105
|
+
specification_version: 2
|
106
|
+
summary: Ruby-wrapper for communicating with the Luminati.io-network.
|
107
|
+
test_files:
|
108
|
+
- spec/spec_helper.rb
|