Class: Oncall::DSL::Call
- Inherits:
-
Object
- Object
- Oncall::DSL::Call
- Defined in:
- lib/oncall/dsl/call.rb
Instance Method Summary collapse
- #get(path, &block) ⇒ Object
- #header(hash) ⇒ Object
-
#initialize ⇒ Call
constructor
A new instance of Call.
- #param(hash) ⇒ Object
Constructor Details
#initialize ⇒ Call
Returns a new instance of Call.
6 7 8 9 10 11 |
# File 'lib/oncall/dsl/call.rb', line 6 def initialize @config = Oncall::Core.config @http = Net::HTTP.new(@config.domain, @config.port) @headers = { 'User-Agent' => "oncall/#{Oncall::VERSION}" } @params = {} end |
Instance Method Details
#get(path, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/oncall/dsl/call.rb', line 25 def get(path, &block) uri = Oncall::HTTP.uri(path, @params) request = Net::HTTP::Get.new(uri) @headers.each do |key, value| request[key] = value end response = @http.request(request) assertion = Oncall::DSL::Assertion.new(response, 'GET', path) assertion.instance_exec(&block) end |
#header(hash) ⇒ Object
13 14 15 16 17 |
# File 'lib/oncall/dsl/call.rb', line 13 def header(hash) hash.each do |key, value| @headers[key] = value end end |
#param(hash) ⇒ Object
19 20 21 22 23 |
# File 'lib/oncall/dsl/call.rb', line 19 def param(hash) hash.each do |key, value| @params[key] = value end end |