class ProxyCrawl::LeadsAPI

Constants

INVALID_DOMAIN
INVALID_TOKEN

Attributes

body[R]
remaining_requests[R]
status_code[R]
success[R]
token[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/proxycrawl/leads_api.rb, line 14
def initialize(options = {})
  raise INVALID_TOKEN if options[:token].nil? || options[:token].empty?

  @token = options[:token]
end

Public Instance Methods

get(domain) click to toggle source
# File lib/proxycrawl/leads_api.rb, line 20
def get(domain)
  raise INVALID_DOMAIN if domain.empty?

  uri = URI('https://api.proxycrawl.com/leads')
  uri.query = URI.encode_www_form({ token: token, domain: domain })

  response = Net::HTTP.get_response(uri)
  @status_code = response.code.to_i
  @body = response.body

  json_body = JSON.parse(response.body)
  @success = json_body['success']
  @remaining_requests = json_body['remaining_requests'].to_i

  self
end
post() click to toggle source
# File lib/proxycrawl/leads_api.rb, line 37
def post
  raise 'Only GET is allowed for the LeadsAPI'
end