Class: ProxyCrawl::LeadsAPI
- Inherits:
-
Object
- Object
- ProxyCrawl::LeadsAPI
- Defined in:
- lib/proxycrawl/leads_api.rb
Constant Summary collapse
- INVALID_TOKEN =
'Token is required'- INVALID_DOMAIN =
'Domain is required'
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#remaining_requests ⇒ Object
readonly
Returns the value of attribute remaining_requests.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #get(domain) ⇒ Object
-
#initialize(options = {}) ⇒ LeadsAPI
constructor
A new instance of LeadsAPI.
- #post ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ LeadsAPI
Returns a new instance of LeadsAPI.
14 15 16 17 18 19 |
# File 'lib/proxycrawl/leads_api.rb', line 14 def initialize( = {}) raise INVALID_TOKEN if [:token].nil? || [:token].empty? @token = [:token] @timeout = [:timeout] || 120 end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/proxycrawl/leads_api.rb', line 9 def body @body end |
#remaining_requests ⇒ Object (readonly)
Returns the value of attribute remaining_requests.
9 10 11 |
# File 'lib/proxycrawl/leads_api.rb', line 9 def remaining_requests @remaining_requests end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
9 10 11 |
# File 'lib/proxycrawl/leads_api.rb', line 9 def status_code @status_code end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
9 10 11 |
# File 'lib/proxycrawl/leads_api.rb', line 9 def success @success end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/proxycrawl/leads_api.rb', line 9 def timeout @timeout end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/proxycrawl/leads_api.rb', line 9 def token @token end |
Instance Method Details
#get(domain) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/proxycrawl/leads_api.rb', line 21 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 }) req = Net::HTTP::Get.new(uri) = { read_timeout: timeout, use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE } response = Net::HTTP.start(uri.hostname, uri.port, ) { |http| http.request(req) } @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 ⇒ Object
46 47 48 |
# File 'lib/proxycrawl/leads_api.rb', line 46 def post raise 'Only GET is allowed for the LeadsAPI' end |