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.
-
#api_version ⇒ 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
.
19 20 21 |
# File 'lib/never_bounce/api/request/base.rb', line 19 def api_url @api_url ||= "https://api.neverbounce.com" end |
#api_version ⇒ String
Custom API URL. Default is https://api.neverbounce.com
.
25 26 27 |
# File 'lib/never_bounce/api/request/base.rb', line 25 def api_version @api_version ||= "v4.2" end |
#headers ⇒ Array
31 32 33 34 35 36 |
# File 'lib/never_bounce/api/request/base.rb', line 31 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.
42 43 44 |
# File 'lib/never_bounce/api/request/base.rb', line 42 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"
.
49 50 51 |
# File 'lib/never_bounce/api/request/base.rb', line 49 def self.path raise NotImplementedError, "Redefine `self.path` in your class: #{self}" end |
.response_klass ⇒ Class
This method is abstract.
55 56 57 |
# File 'lib/never_bounce/api/request/base.rb', line 55 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.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/never_bounce/api/request/base.rb', line 61 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}/#{api_version}/#{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.
82 83 84 |
# File 'lib/never_bounce/api/request/base.rb', line 82 def to_h raise NotImplementedError, "Redefine `to_h` in your class: #{self.class}" end |
#to_httparty ⇒ Array
Build argumentsfor Httparty
invocation.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/never_bounce/api/request/base.rb', line 88 def to_httparty [ self.class.http_method, # E.g. `:get`. "#{api_url}/#{api_version}/#{self.class.path}", { body: to_h.to_json, headers: headers, } ] end |