Class: Oncall::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/oncall/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, **opts) ⇒ HTTP

Returns a new instance of HTTP.



5
6
7
8
9
10
11
# 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

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



3
4
5
# File 'lib/oncall/http.rb', line 3

def headers
  @headers
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/oncall/http.rb', line 3

def params
  @params
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/oncall/http.rb', line 3

def path
  @path
end

Instance Method Details

#getObject



13
14
15
16
# File 'lib/oncall/http.rb', line 13

def get
  request = Net::HTTP::Get.new(uri)
  @response = @client.request(request)
end

#postObject



18
19
20
21
# File 'lib/oncall/http.rb', line 18

def post
  request = Net::HTTP::Post.new(uri)
  @response = @client.request(request)
end

#response_bodyObject



23
24
25
# File 'lib/oncall/http.rb', line 23

def response_body
  @response.body
end

#response_codeObject



27
28
29
# File 'lib/oncall/http.rb', line 27

def response_code
  @response.code
end