Class: Crowbar::Client::Util::ApiVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/crowbar/client/util/apiversion.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ ApiVersion

Returns a new instance of ApiVersion.



23
24
25
# File 'lib/crowbar/client/util/apiversion.rb', line 23

def initialize(version)
  @version = version
end

Instance Attribute Details

#versionObject

Returns the value of attribute version.



21
22
23
# File 'lib/crowbar/client/util/apiversion.rb', line 21

def version
  @version
end

Class Method Details

.defaultObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/crowbar/client/util/apiversion.rb', line 42

def default
  os_release_file = "/etc/os-release"

  if File.exist?(os_release_file)
    os_release = Hash[
      File.open(os_release_file).read.scan(/(\S+)\s*=\s*"([^"]+)/)
    ]

    return 1.0 if os_release["VERSION_ID"] == "12.1" && os_release["ID"] == "sles"
  end

  2.0
end

Instance Method Details

#headersObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/crowbar/client/util/apiversion.rb', line 27

def headers
  if version == 1.0
    {
      "Accept" => "application/json",
      "Content-Type" => "application/json"
    }
  else
    {
      "Accept" => "application/vnd.crowbar.v#{version}+json",
      "Content-Type" => "application/json"
    }
  end
end