Class: Zerobounce::Request
- Inherits:
-
BaseRequest
- Object
- BaseRequest
- Zerobounce::Request
- Defined in:
- lib/zerobounce/request.rb
Overview
Sends the HTTP request.
Class Method Summary collapse
- .bulk_get(path, params, content_type = 'application/json') ⇒ Object
-
.bulk_getfile(path, params) ⇒ Object
Bulk getfile only: treats non-2xx and JSON error payloads (including HTTP 200) as failures.
- .bulk_post(path, params, content_type = 'application/json', filepath = nil) ⇒ Object
- .get(path, params, content_type = 'application/json') ⇒ Object
Methods inherited from BaseRequest
__root_without_trailing_slashes__, __safe_file_path__, _get, _post
Class Method Details
.bulk_get(path, params, content_type = 'application/json') ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/zerobounce/request.rb', line 32 def self.bulk_get(path, params, content_type='application/json') response = self._get(Zerobounce.configuration.bulk_api_root_url, path, params, content_type) if response.headers[:content_type] == 'application/json' response_body = response.body response_body_json = JSON.parse(response_body) raise (response_body_json['error']) if response_body_json.key?('error') raise (response_body_json['errors'][0]['error']) \ if response_body_json.key?('errors') and \ response_body_json['errors'].length > 0 return response_body_json else content = StringIO.new(response.body) content.set_encoding_by_bom return content.string end end |
.bulk_getfile(path, params) ⇒ Object
Bulk getfile only: treats non-2xx and JSON error payloads (including HTTP 200) as failures.
52 53 54 55 |
# File 'lib/zerobounce/request.rb', line 52 def self.bulk_getfile(path, params) response = self._get(Zerobounce.configuration.bulk_api_root_url, path, params, 'application/json') GetFileHelper.process_getfile_response(response) end |
.bulk_post(path, params, content_type = 'application/json', filepath = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/zerobounce/request.rb', line 57 def self.bulk_post(path, params, content_type='application/json', filepath=nil) response = self._post(Zerobounce.configuration.bulk_api_root_url, path, params, \ content_type, filepath) if response.headers[:content_type] == 'application/json' response_body = response.body response_body_json = JSON.parse(response_body) raise (response_body_json['error']) if response_body_json.key?('error') raise (response_body_json['errors'][0]['error']) \ if response_body_json.key?('errors') and \ response_body_json['errors'].length > 0 return response_body_json end return response.body end |
.get(path, params, content_type = 'application/json') ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/zerobounce/request.rb', line 12 def self.get(path, params, content_type='application/json') response = self._get(Zerobounce.configuration.api_root_url, path, params, content_type) if response.headers[:content_type] == 'application/json' response_body = response.body response_body_json = JSON.parse(response_body) raise (response_body_json['error']) if response_body_json.key?('error') raise (response_body_json['Message']) \ if response_body_json.key?('Message') and \ response_body_json.length == 1 raise (response_body_json['errors'][0]['error']) \ if response_body_json.key?('errors') and \ response_body_json['errors'].length > 0 return response_body_json else return response end end |