Class: NeverBounce::API::Request::Base Abstract
- Inherits:
-
Object
- Object
- NeverBounce::API::Request::Base
- Defined in:
- lib/never_bounce/api/request/base.rb
Overview
This class is abstract.
Direct Known Subclasses
AccountInfo, JobsCreate, JobsDelete, JobsDownload, JobsParse, JobsResults, JobsSearch, JobsStart, JobsStatus, POEConfirm, SingleCheck
Instance Attribute Summary collapse
-
#api_key ⇒ String
User’s API key.
-
#api_url ⇒ String
Custom API URL.
- #headers ⇒ Array
- #user_agent ⇒ String
Class Method Summary collapse
-
.http_method ⇒ Symbol, String
abstract
:get
,:post
or whatever. -
.path ⇒ String
abstract
Request path on server, e.g.
- .response_klass ⇒ Class abstract
Instance Method Summary collapse
-
#to_curl ⇒ Array
Build arguments for cURL OS command.
-
#to_h ⇒ Hash
abstract
Build a
Hash
representation of request data. -
#to_httparty ⇒ Array
Build argumentsfor
Httparty
invocation.
Instance Attribute Details
#api_key ⇒ String
User’s API key.
14 15 16 |
# File 'lib/never_bounce/api/request/base.rb', line 14 def api_key @api_key end |
#api_url ⇒ String
Custom API URL. Default is https://api.neverbounce.com/v4
.
19 20 21 |
# File 'lib/never_bounce/api/request/base.rb', line 19 def api_url @api_url ||= "https://api.neverbounce.com/v4" end |
#headers ⇒ Array
25 26 27 28 29 30 |
# File 'lib/never_bounce/api/request/base.rb', line 25 def headers { "Content-Type" => "application/json", "User-Agent" => user_agent, } end |
Class Method Details
.http_method ⇒ Symbol, String
This method is abstract.
:get
, :post
or whatever.
36 37 38 |
# File 'lib/never_bounce/api/request/base.rb', line 36 def self.http_method raise NotImplementedError, "Redefine `self.http_method` in your class: #{self}" end |
.path ⇒ String
This method is abstract.
Request path on server, e.g. "jobs/parse"
.
43 44 45 |
# File 'lib/never_bounce/api/request/base.rb', line 43 def self.path raise NotImplementedError, "Redefine `self.path` in your class: #{self}" end |
.response_klass ⇒ Class
This method is abstract.
49 50 51 |
# File 'lib/never_bounce/api/request/base.rb', line 49 def self.response_klass raise NotImplementedError, "Redefine `self.response_klass` in your class: #{self}" end |
Instance Method Details
#to_curl ⇒ Array
Build arguments for cURL OS command.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/never_bounce/api/request/base.rb', line 55 def to_curl # NOTE: I consider we should use long options to avoid ambiguity of ones like `-u` etc. @curl ||= begin ar = [ "--request", self.class.http_method.to_s.upcase, "--url", "#{api_url}/#{self.class.path}", ] ar += headers.reject { |k,| k == "User-Agent" }.flat_map do |k, v| ["--header", "#{k}: #{v}"] end ar += ["--data-binary", to_h.to_json] ar end end |
#to_h ⇒ Hash
This method is abstract.
Build a Hash
representation of request data.
76 77 78 |
# File 'lib/never_bounce/api/request/base.rb', line 76 def to_h raise NotImplementedError, "Redefine `to_h` in your class: #{self.class}" end |
#to_httparty ⇒ Array
Build argumentsfor Httparty
invocation.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/never_bounce/api/request/base.rb', line 82 def to_httparty [ self.class.http_method, # E.g. `:get`. "#{api_url}/#{self.class.path}", { body: to_h.to_json, headers: headers, } ] end |