Class: Courrier::Email::Request
- Inherits:
-
Object
- Object
- Courrier::Email::Request
- Defined in:
- lib/courrier/email/request.rb
Instance Method Summary collapse
-
#initialize(endpoint_url:, body:, provider:, headers: {}, content_type: "application/json") ⇒ Request
constructor
A new instance of Request.
- #post ⇒ Object
Constructor Details
#initialize(endpoint_url:, body:, provider:, headers: {}, content_type: "application/json") ⇒ Request
Returns a new instance of Request.
10 11 12 13 14 15 16 |
# File 'lib/courrier/email/request.rb', line 10 def initialize(endpoint_url:, body:, provider:, headers: {}, content_type: "application/json") @endpoint_url = endpoint_url @body = body @provider = provider @headers = headers @content_type = content_type end |
Instance Method Details
#post ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/courrier/email/request.rb', line 18 def post uri = URI.parse(@endpoint_url) request = Net::HTTP::Post.new(uri) headers_for request body_for request = {use_ssl: uri.scheme == "https"} begin response = Net::HTTP.start(uri.hostname, uri.port, ) { _1.request(request) } Result.new(response: response) rescue => error Result.new(error: error) end end |