class Oncall::HTTP
Attributes
headers[RW]
params[RW]
path[RW]
Public Class Methods
new(path, **opts)
click to toggle source
# File lib/oncall/http.rb, line 5 def initialize(path, **opts) @path = path @client = Net::HTTP.new(Oncall.options.host, Oncall.options.port) @headers = opts[:headers] || { 'User-Agent' => "#{Oncall::SCRIPT}/#{Oncall::VERSION}" } @params = opts[:params] || {} @query = opts[:query] || {} end
Public Instance Methods
get()
click to toggle source
# File lib/oncall/http.rb, line 13 def get request = Net::HTTP::Get.new(uri) @response = @client.request(request) end
post()
click to toggle source
# File lib/oncall/http.rb, line 18 def post request = Net::HTTP::Post.new(uri) @response = @client.request(request) end
response_body()
click to toggle source
# File lib/oncall/http.rb, line 23 def response_body @response.body end
response_code()
click to toggle source
# File lib/oncall/http.rb, line 27 def response_code @response.code end
Private Instance Methods
uri()
click to toggle source
# File lib/oncall/http.rb, line 33 def uri parts = path.split('/') return '/' if parts.empty? parts.each_with_index do |part, index| if part.start_with?(':') part[0] = '' parts[index] = params[part.to_sym] end end parts.join('/') end