Class: JetEmail::Request
- Inherits:
-
Object
- Object
- JetEmail::Request
- Defined in:
- lib/jetemail/request.rb
Constant Summary collapse
- BASE_URL =
ENV["JETEMAIL_BASE_URL"] || "https://api.jetemail.com"
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
-
#initialize(path = "", body = {}, verb = "post") ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(path = "", body = {}, verb = "post") ⇒ Request
Returns a new instance of Request.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jetemail/request.rb', line 9 def initialize(path = "", body = {}, verb = "post") raise JetEmail::Error.new("API key is not set") if JetEmail.api_key.nil? api_key = JetEmail.api_key api_key = api_key.call if api_key.is_a?(Proc) @path = path @body = body @verb = verb @headers = { "Content-Type" => "application/json", "Accept" => "application/json", "User-Agent" => "jetemail-ruby:#{JetEmail::VERSION}", "Authorization" => "Bearer #{api_key}" } end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/jetemail/request.rb', line 7 def body @body end |
#verb ⇒ Object
Returns the value of attribute verb.
7 8 9 |
# File 'lib/jetemail/request.rb', line 7 def verb @verb end |
Instance Method Details
#perform ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/jetemail/request.rb', line 26 def perform = resp = HTTParty.send(@verb.to_sym, "#{BASE_URL}/#{@path}", ) data = parse_response(resp) handle_error!(data, resp) if error_response?(resp) data end |