class HangoutsChat::Sender::HTTP

Service class to send HTTP POST requests

Public Class Methods

new(url) click to toggle source

Creates HTTP::Post object with JSON content type @param url [String] URL to send request

# File lib/hangouts_chat/http.rb, line 13
def initialize(url)
  @uri = URI(url)
  @req = Net::HTTP::Post.new(@uri)
  @req['Content-Type'] = 'application/json'
end

Public Instance Methods

post(payload) click to toggle source

Sends HTTP POST request @param payload [String] request body to send @return [Net::HTTPResponse] response object

# File lib/hangouts_chat/http.rb, line 22
def post(payload)
  @req.body = payload.to_json

  Net::HTTP.start(@uri.hostname, @uri.port, :ENV, use_ssl: true) do |http|
    http.request(@req)
  end
end