class Oncall::DSL

Public Class Methods

new(file, reporter) click to toggle source
# File lib/oncall/dsl.rb, line 3
def initialize(file, reporter)
  @reporter = reporter
  @file = file
  @http = nil
  @headers = {}
  @params = {}
end

Public Instance Methods

to_s() click to toggle source
# File lib/oncall/dsl.rb, line 11
def to_s
  @file
end

Private Instance Methods

get(path, &block) click to toggle source
# File lib/oncall/dsl.rb, line 23
def get(path, &block)
  return @reporter.empty_call(self) unless block_given?

  @http = Oncall::HTTP.new(path, headers: @headers, params: @params)
  @http.get

  instance_exec &block
end
group(_name=nil, &block) click to toggle source
# File lib/oncall/dsl.rb, line 17
def group(_name=nil, &block)
  return @reporter.empty_group(self) unless block_given?

  instance_exec &block
end
header(key_value) click to toggle source
# File lib/oncall/dsl.rb, line 41
def header(key_value)
  key_value.each do |key, value|
    @headers[key] = value
  end
end
param(key_value) click to toggle source
# File lib/oncall/dsl.rb, line 47
def param(key_value)
  key_value.each do |key, value|
    @params[key] = value
  end
end
post(path, &block) click to toggle source
# File lib/oncall/dsl.rb, line 32
def post(path, &block)
  return reporter.empty_call(self) unless block_given?

  @http = Oncall::HTTP.new(path, headers: @headers, params: @params)
  @http.post

  instance_exec &block
end
status(expected) click to toggle source
# File lib/oncall/dsl.rb, line 58
def status(expected)
  result = @http.response_code == expected.to_s
  @reporter.status(self, result, expected)
end
validate(expected) click to toggle source
# File lib/oncall/dsl.rb, line 53
def validate(expected)
  result = JSON::Validator.validate(expected, @http.response_body)
  @reporter.json_schema(self, result, expected)
end