Class: OpenHAB::API

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/openhab/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ API

Returns a new instance of API.



7
8
9
10
11
12
13
# File 'lib/rspec/openhab/api.rb', line 7

def initialize(url)
  @faraday = Faraday.new(url) do |f|
    f.response :raise_error
    f.response :json
    f.path_prefix = "/rest/"
  end
end

Instance Method Details

#item(name) ⇒ Object



33
34
35
36
37
# File 'lib/rspec/openhab/api.rb', line 33

def item(name)
  @faraday.get("items/#{name}").body
rescue Faraday::ResourceNotFound
  nil
end

#itemsObject



29
30
31
# File 'lib/rspec/openhab/api.rb', line 29

def items
  @faraday.get("items", metadata: ".*").body
end

#localeObject



21
22
23
# File 'lib/rspec/openhab/api.rb', line 21

def locale
  root_data["locale"]
end

#measurement_systemObject



25
26
27
# File 'lib/rspec/openhab/api.rb', line 25

def measurement_system
  root_data["measurementSystem"]
end

#versionObject



15
16
17
18
19
# File 'lib/rspec/openhab/api.rb', line 15

def version
  version = root_data.dig("runtimeInfo", "version")
  version = "#{version}-SNAPSHOT" if root_data.dig("runtimeInfo", "buildString")&.start_with?("Build #")
  version
end