proxied 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29acafb1d9f1d68dd0c3992e3948516fc939fb351a521c819932417c7bc68cfb
4
- data.tar.gz: 60a91e0f65fe7a4c2468a0c02136ace0184480daa2255fcb44795f7088aea214
3
+ metadata.gz: 517de1167f3ffecb00a5928fc7a9372fb4190ac7cfa4c6ab61c9ba623c59dbb7
4
+ data.tar.gz: 4bddfb8d6887527f1319b7ed653d2519cad672b697c76e87a9658bb673bbfc88
5
5
  SHA512:
6
- metadata.gz: 5421ffe9184290f0becd77ae161d000f3a2f997fc9dd109efab7d365dfd49e8fd6e42c3aed2cb19e7e0142158be0d2ab16e545ea676a6f54a8a74bd3c683faaf
7
- data.tar.gz: 1485343312be1dc6204be61a839cfc9ff45ad35c23f94f4ea2352411922100ebad413191aee04cc26139f135a6af668e50b1da28086d325587f0bf19530a8901
6
+ metadata.gz: 7a689a4a001970b1ae2f2a7d886b4406421a4df8e887ee40386f22f6de1e97c0167c1481ae9a4e61d52a341d0624ac6d92d684700190bda3486c7cf47e589cbd
7
+ data.tar.gz: c26a67137820c580253bb7dc9e9d8ee683ea33fbccda247cd56c5b48c914a71a2d176e3dc79099a2a24d7b55f84860593afa15b860c4df183daa89f439de726c
data/.gitignore CHANGED
@@ -17,3 +17,10 @@
17
17
 
18
18
  # appraisals
19
19
  /gemfiles/*.lock
20
+
21
+ # RVM
22
+ .ruby-version
23
+ .ruby-gemset
24
+
25
+ # DS_Store
26
+ .DS_Store
data/Gemfile.lock CHANGED
@@ -2,8 +2,8 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  proxied (0.1.0)
5
- faraday (~> 0.15.2)
6
- net-ssh (~> 5.0.2)
5
+ faraday (>= 0.14)
6
+ net-ssh (>= 4.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -24,6 +24,15 @@ Or install it yourself as:
24
24
 
25
25
  $ gem install proxied
26
26
 
27
+ Generate the initializer for your Rails app:
28
+
29
+ $ rails generate proxied:install MODEL
30
+
31
+ Generate the migration and model:
32
+
33
+ $ rails generate proxied MODEL
34
+
35
+
27
36
  ## Usage
28
37
 
29
38
  - TODO -
@@ -3,8 +3,8 @@
3
3
  class ProxiedCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
4
4
  def change
5
5
  create_table :<%= table_name %><%= primary_key_type %> do |t|
6
- t.string :host, null: false
7
- t.integer :port, null: false
6
+ t.string :host, null: false, index: true
7
+ t.integer :port, null: false, index: true
8
8
  t.string :username
9
9
  t.string :password
10
10
 
@@ -12,6 +12,9 @@ class ProxiedCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migra
12
12
  t.string :proxy_type, null: false, default: 'public', index: true
13
13
  t.string :category
14
14
 
15
+ t.string :country, index: true
16
+ t.string :city, index: true
17
+
15
18
  t.datetime :last_checked_at, index: true
16
19
 
17
20
  t.boolean :valid_proxy, null: false, default: false, index: true
@@ -31,6 +31,9 @@ module Mongoid
31
31
  field :proxy_type, type: String, default: :public
32
32
  field :category, type: String
33
33
 
34
+ field :country, type: String
35
+ field :city, type: String
36
+
34
37
  field :valid_proxy, type: Boolean, default: false
35
38
  field :successful_attempts, type: Integer, default: 0
36
39
  field :failed_attempts, type: Integer, default: 0
@@ -1,26 +1,8 @@
1
1
  ::Proxied.configure do |config|
2
- config.proxy_class = <%= class_name.camelize.to_s %> # Must be set to the ActiveRecord or Mongoid model that will be used for managing proxies
2
+ config.proxy_class = "<%= class_name.camelize.to_s %>" # Must be set to the ActiveRecord or Mongoid model that will be used for managing proxies
3
3
 
4
4
  config.minimum_successful_attempts = 1
5
5
  config.maximum_failed_attempts = 10
6
6
 
7
- config.faraday = {
8
- adapter: :net_http,
9
- user_agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Safari/605.1.15",
10
- verbose: false
11
- }
12
-
13
- config.http_test = {
14
- url: "http://www.google.com/robots.txt",
15
- timeout: 10,
16
- }
17
-
18
- config.socks_test = {
19
- hostname: "whois.verisign-grs.com",
20
- port: 43,
21
- query: "=google.com",
22
- timeout: 10
23
- }
24
-
25
- config.logger = defined?(Rails) ? -> (message) { Rails.logger.info(message) } : -> (message) { puts(message) }
7
+ config.job_queue = :proxies
26
8
  end
data/lib/proxied.rb CHANGED
@@ -1,3 +1,21 @@
1
+ module Proxied
2
+ class << self
3
+ attr_writer :configuration
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= ::Proxied::Configuration.new
8
+ end
9
+
10
+ def self.reset
11
+ @configuration = ::Proxied::Configuration.new
12
+ end
13
+
14
+ def self.configure
15
+ yield(configuration)
16
+ end
17
+ end
18
+
1
19
  # Gems
2
20
  require "faraday"
3
21
  require "net/ssh/proxy/socks5"
@@ -23,21 +41,3 @@ if defined?(Sidekiq)
23
41
  end
24
42
 
25
43
  require "proxied/railtie" if defined?(Rails)
26
-
27
- module Proxied
28
- class << self
29
- attr_writer :configuration
30
- end
31
-
32
- def self.configuration
33
- @configuration ||= ::Proxied::Configuration.new
34
- end
35
-
36
- def self.reset
37
- @configuration = ::Proxied::Configuration.new
38
- end
39
-
40
- def self.configure
41
- yield(configuration)
42
- end
43
- end
@@ -9,8 +9,8 @@ module Proxied
9
9
  self.limit = limit
10
10
  end
11
11
 
12
- def check_proxies(protocol: :all, proxy_type: :all, mode: :synchronous)
13
- proxies = ::Proxied.configuration.proxy_class.should_be_checked(
12
+ def check_proxies(protocol: :all, proxy_type: :all, mode: :synchronous, update: true)
13
+ proxies = ::Proxied.configuration.proxy_class.constantize.should_be_checked(
14
14
  protocol: protocol,
15
15
  proxy_type: proxy_type,
16
16
  date: Time.now,
@@ -24,7 +24,7 @@ module Proxied
24
24
  proxies.each do |proxy|
25
25
  case mode
26
26
  when :synchronous
27
- check_proxy(proxy)
27
+ check_proxy(proxy, update: update)
28
28
  when :sidekiq
29
29
  ::Proxied::Jobs::CheckProxyJob.perform_async(proxy.id.to_s)
30
30
  end
@@ -4,6 +4,7 @@ module Proxied
4
4
  attr_accessor :minimum_successful_attempts, :maximum_failed_attempts
5
5
  attr_accessor :faraday
6
6
  attr_accessor :http_test, :socks_test
7
+ attr_accessor :job_queue
7
8
  attr_accessor :logger
8
9
 
9
10
  def initialize
@@ -30,6 +31,8 @@ module Proxied
30
31
  timeout: 10
31
32
  }
32
33
 
34
+ self.job_queue = :proxies
35
+
33
36
  self.logger = defined?(Rails) ? -> (message) { Rails.logger.info(message) } : -> (message) { puts(message) }
34
37
  end
35
38
 
@@ -2,10 +2,10 @@ module Proxied
2
2
  module Jobs
3
3
  class CheckProxiesJob
4
4
  include ::Sidekiq::Worker
5
- sidekiq_options queue: :proxies
5
+ sidekiq_options queue: ::Proxied.configuration.job_queue
6
6
 
7
7
  def perform(protocol = :all, proxy_type = :all, mode = :synchronous)
8
- ::Proxied::Checker.new.check_proxies(protocol: protocol.to_sym, proxy_type: proxy_type.to_sym, mode: mode.to_sym)
8
+ ::Proxied::Checker.new.check_proxies(protocol: protocol.to_sym, proxy_type: proxy_type.to_sym, mode: mode.to_sym, update: true)
9
9
  end
10
10
  end
11
11
  end
@@ -2,15 +2,14 @@ module Proxied
2
2
  module Jobs
3
3
  class CheckProxyJob
4
4
  include ::Sidekiq::Worker
5
- sidekiq_options queue: :proxies
5
+ sidekiq_options queue: ::Proxied.configuration.job_queue
6
6
 
7
7
  def perform(proxy_id)
8
8
  proxy_object = ::Proxy.where(id: proxy_id).first
9
9
 
10
10
  if proxy_object
11
11
  checker = ::Proxied::Checker.new
12
- checker.check_proxy(proxy_object)
13
- checker.update_proxies
12
+ checker.check_proxy(proxy_object, update: true)
14
13
  end
15
14
  end
16
15
  end
@@ -0,0 +1,45 @@
1
+ module Proxied
2
+ class Seeder
3
+
4
+ # Expected format:
5
+ # {
6
+ # host
7
+ # port
8
+ # protocol (http,socks)
9
+ # proxy_type (private,public)
10
+ # category
11
+ # username
12
+ # password
13
+ # }
14
+
15
+ def import(proxies)
16
+ proxies.each do |proxy_item|
17
+ query = {
18
+ host: proxy_item[:ip_address]&.to_s&.strip,
19
+ port: proxy_item[:port]&.to_s&.strip&.to_i
20
+ }
21
+
22
+ parsed = {
23
+ protocol: proxy_item.fetch(:protocol, "http")&.to_s&.strip&.downcase,
24
+ proxy_type: proxy_item.fetch(:type, :private)&.to_s&.strip,
25
+ category: proxy_item.fetch(:category, nil)&.to_s&.strip&.downcase,
26
+ username: proxy_item.fetch(:username, nil)&.to_s&.strip,
27
+ password: proxy_item.fetch(:password, nil)&.to_s&.strip
28
+ }.merge(query)
29
+
30
+ proxy = ::Proxied.configuration.proxy_class.constantize.where(query).first || ::Proxied.configuration.proxy_class.constantize.new
31
+
32
+ parsed.each do |key, value|
33
+ proxy.send("#{key}=", value)
34
+ end
35
+
36
+ proxy.last_checked_at = Time.now
37
+ proxy.valid_proxy = true
38
+ proxy.successful_attempts = 1
39
+
40
+ proxy.save
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -4,10 +4,10 @@ module Proxied
4
4
  module ProxyMethods
5
5
 
6
6
  def self.included(base)
7
- base.send :extend ::Proxied::Shared::ClassMethods
8
- base.send :extend, ClassMethods
7
+ base.extend(::Proxied::Shared::ClassMethods)
8
+ base.extend(ClassMethods)
9
9
 
10
- base.send :include ::Proxied::Shared::InstanceMethods
10
+ base.include(::Proxied::Shared::InstanceMethods)
11
11
  end
12
12
 
13
13
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module Proxied
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/proxied.gemspec CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_dependency "faraday", "~> 0.15.2"
27
- spec.add_dependency "net-ssh", "~> 5.0.2"
26
+ spec.add_dependency "faraday", ">= 0.14"
27
+ spec.add_dependency "net-ssh", ">= 4.0"
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.16.2"
30
30
  spec.add_development_dependency "rake", "~> 12.3.1"
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-29 00:00:00.000000000 Z
11
+ date: 2018-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.15.2
19
+ version: '0.14'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.15.2
26
+ version: '0.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: net-ssh
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.0.2
33
+ version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.0.2
40
+ version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -268,8 +268,6 @@ extra_rdoc_files: []
268
268
  files:
269
269
  - ".gitignore"
270
270
  - ".rspec"
271
- - ".ruby-gemset"
272
- - ".ruby-version"
273
271
  - ".travis.yml"
274
272
  - Appraisals
275
273
  - CODE_OF_CONDUCT.md
@@ -283,7 +281,6 @@ files:
283
281
  - gemfiles/.bundle/config
284
282
  - gemfiles/activerecord5.gemfile
285
283
  - gemfiles/mongoid7.gemfile
286
- - lib/.DS_Store
287
284
  - lib/generators/active_record/proxied_generator.rb
288
285
  - lib/generators/active_record/templates/migration.rb
289
286
  - lib/generators/mongoid/proxied_generator.rb
@@ -292,7 +289,6 @@ files:
292
289
  - lib/generators/proxied/proxied_generator.rb
293
290
  - lib/generators/templates/proxied.rb
294
291
  - lib/proxied.rb
295
- - lib/proxied/.DS_Store
296
292
  - lib/proxied/checker.rb
297
293
  - lib/proxied/configuration.rb
298
294
  - lib/proxied/jobs/check_proxies_job.rb
@@ -300,6 +296,7 @@ files:
300
296
  - lib/proxied/logger.rb
301
297
  - lib/proxied/nosql/proxy_methods.rb
302
298
  - lib/proxied/railtie.rb
299
+ - lib/proxied/seeder.rb
303
300
  - lib/proxied/shared.rb
304
301
  - lib/proxied/sql/proxy_methods.rb
305
302
  - lib/proxied/version.rb
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- proxied
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.6.0-preview2
data/lib/.DS_Store DELETED
Binary file
Binary file