class PostmanMta::ApiRequest
Attributes
callback[R]
options[R]
path[R]
request_type[R]
Public Class Methods
new(request_type, path, options = {})
click to toggle source
# File lib/postman_mta/api_request.rb, line 10 def initialize(request_type, path, options = {}) @callback = PostmanMta.before_request_hook @request_type = request_type @path = path @options = options end
Public Instance Methods
full_path()
click to toggle source
# File lib/postman_mta/api_request.rb, line 22 def full_path @full_path ||= PostmanMta.api_endpoint + path end
perform()
click to toggle source
# File lib/postman_mta/api_request.rb, line 18 def perform self.class.send(request_type.downcase, path, request_options) end
uri()
click to toggle source
# File lib/postman_mta/api_request.rb, line 26 def uri @uri ||= URI(full_path) end
Private Instance Methods
auth_headers()
click to toggle source
# File lib/postman_mta/api_request.rb, line 36 def auth_headers PostmanMta::Utils::SignedRequest.new(request_method: request_type.upcase, path: uri.request_uri).headers end
merge_with_custom_options()
click to toggle source
# File lib/postman_mta/api_request.rb, line 40 def merge_with_custom_options return options unless callback custom_options = callback.call return options unless custom_options.is_a?(Hash) options[:body] = (options[:body] || {}).merge(custom_options) options end
request_options()
click to toggle source
# File lib/postman_mta/api_request.rb, line 32 def request_options { headers: auth_headers, format: :json }.merge(merge_with_custom_options) end