class Serverspec::Type::ApiBase

Public Class Methods

new(name = nil, options = {}) click to toggle source
Calls superclass method
# File lib/serverspec_extra_types/types/api_base.rb, line 10
def initialize(name = nil, options = {})
  super(name, options)
  @insecure = options[:insecure]
  @redirects = options[:follow_redirects]
  @host = options[:host]
end

Public Instance Methods

[](key) click to toggle source
# File lib/serverspec_extra_types/types/api_base.rb, line 17
def [](key)
  value = inspection
  key.split('.').each do |k|
    is_index = k.start_with?('[') && k.end_with?(']')
    value = value[is_index ? k[1..-2].to_i : k]
  end
  value
end
inspection() click to toggle source
# File lib/serverspec_extra_types/types/api_base.rb, line 30
def inspection
  @inspection ||= ::MultiJson.load(get_inspection.stdout)
end
url() click to toggle source
# File lib/serverspec_extra_types/types/api_base.rb, line 26
def url
  @url_base
end

Private Instance Methods

curl_command() click to toggle source
# File lib/serverspec_extra_types/types/api_base.rb, line 40
def curl_command
  "curl #{extra_args} #{@host ? '--header "Host: '+@host+'"' : '' } -s #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
end
extra_args() click to toggle source
# File lib/serverspec_extra_types/types/api_base.rb, line 36
def extra_args
  ''
end
get_inspection() click to toggle source

rubocop:disable Naming/AccessorMethodName

# File lib/serverspec_extra_types/types/api_base.rb, line 45
def get_inspection
  command = curl_command
  @get_inspection ||= @runner.run_command(command)
end