Skip to content

Ruby proxy fetcher, retries request until completed, provides user agent🚀🚀

License

Notifications You must be signed in to change notification settings

sebyx07/active_proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActiveProxy

Alt text Gem Version

Easy to use ruby proxy fetcher with support for multiple http clients. Has auto retry🚀, fetch 🤖user agent

gem 'active_proxy'

Examples

HTTParty

    cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)

    ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
      
      options = proxy.format_proxy_httparty
      options[:timeout] = 2
      options[:headers] = {
          "Accept" => "application/json",
          "User-Agent" => proxy.user_agent
      }

      result = HTTParty.get("https://api.ipify.org?format=json", options).body
      p JSON.parse(result)
      
    end

Http.rb

    cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)

    ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
      
      proxy_arguments = proxy.format_proxy_http
      headers = {
        "Accept" => "application/json",
        "User-Agent" => proxy.user_agent
      }

      result = HTTP.via(*proxy_arguments)
                   .headers(headers)
                   .timeout(write: 2, connect: 1, read: 1)
                   .get("https://api.ipify.org?format=json")
                   .body

      p JSON.parse(result)      
      
    end

Typhoeus

    cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)

    ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
      
      options = proxy.format_proxy_typhoeus
      options[:timeout] = 2
      options[:followlocation] = true
      options[:headers] = {
        "Accept" => "application/json",
        "User-Agent" => proxy.user_agent
      }
      options[:method] = :get

      result = Typhoeus::Request.new("https://api.ipify.org?format=json", options).run.body

      p JSON.parse(result)     
       
    end

custom client

    cache = ActiveSupport::Cache::MemoryStore.new(size: 10.megabytes)

    ActiveProxy.call("ipify", cache) do |proxy| # for rails: ActiveProxy.call("ipify", Rails.cache) do |proxy|
      
      options = proxy.current_proxy
      # then you access the options[:address] and options[:port]
    end

Custom options

User agent

When calling .user_agent you can pass params, check https://github.com/asconix/user-agent-randomizer

Limit retries

Current limit is 10.

Because proxies are unreliable, set a higher number

    ActiveProxy.call("ipify", cache, {max_retries: 100}) do
    
    end

Proxy list

Current configuration is { filters: { maxtime: "200" } }

You can check what configuration you can pass https://github.com/nbulaj/proxy_fetcher

    ActiveProxy.call("ipify", cache, {proxy_manager_options: { filters: { maxtime: "100" } }}) do
    
    end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_proxy.

License

The gem is available as open source under the terms of the MIT License.

About

Ruby proxy fetcher, retries request until completed, provides user agent🚀🚀

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published