Class: ApiBomb::Path::Single

Inherits:
Object
  • Object
show all
Defined in:
lib/api_bomb/path.rb

Constant Summary collapse

HTTP_METHODS =
[:get, :post, :put, :patch, :delete, :head].freeze

Instance Method Summary collapse

Constructor Details

#initialize(path:, action: :get, options: {}) ⇒ Single

Returns a new instance of Single.



20
21
22
23
24
25
# File 'lib/api_bomb/path.rb', line 20

def initialize(path:, action: :get, options: {})
  @path = path
  @action = action
  @action = :get if not HTTP_METHODS.include?(action.downcase.to_sym)
  @options = ApiBomb::LambdaHash.new(options)
end

Instance Method Details

#actionObject



60
61
62
63
# File 'lib/api_bomb/path.rb', line 60

def action
  return @action.call if @action.respond_to? :call
  return @action
end

#optionsObject



65
66
67
# File 'lib/api_bomb/path.rb', line 65

def options
  @options
end

#params_reportObject



45
46
47
48
49
50
51
52
53
# File 'lib/api_bomb/path.rb', line 45

def params_report
  return '' unless options[:params]

  if options.is_lambda?
    " with random params like: #{ApiBomb::LambdaHash.hasharize(options)[:params]}"
  else
    " with params: #{options[:params]}"
  end
end

#pathObject



55
56
57
58
# File 'lib/api_bomb/path.rb', line 55

def path
  return @path.call if @path.respond_to? :call
  return @path
end

#path_report(base_url = '') ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/api_bomb/path.rb', line 35

def path_report(base_url = '')
  base_url = options[:base_url] if options[:base_url]

  if @path.respond_to? :call
    "testing random paths like #{action.to_s.upcase} #{URI::join(base_url, path)}"
  else
    "testing path #{action.to_s.upcase} #{URI::join(base_url, path)}"
  end
end

#pickObject



27
28
29
# File 'lib/api_bomb/path.rb', line 27

def pick
  return self
end

#report(base_url) ⇒ Object



31
32
33
# File 'lib/api_bomb/path.rb', line 31

def report(base_url)
  path_report(base_url) + params_report
end