Class: OpenHAB::API
- Inherits:
-
Object
- Object
- OpenHAB::API
- Defined in:
- lib/rspec/openhab/api.rb
Instance Method Summary collapse
-
#initialize(url) ⇒ API
constructor
A new instance of API.
- #item(name) ⇒ Object
- #items ⇒ Object
- #locale ⇒ Object
- #measurement_system ⇒ Object
- #version ⇒ Object
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 |
#items ⇒ Object
29 30 31 |
# File 'lib/rspec/openhab/api.rb', line 29 def items @faraday.get("items", metadata: ".*").body end |
#locale ⇒ Object
21 22 23 |
# File 'lib/rspec/openhab/api.rb', line 21 def locale root_data["locale"] end |
#measurement_system ⇒ Object
25 26 27 |
# File 'lib/rspec/openhab/api.rb', line 25 def measurement_system root_data["measurementSystem"] end |
#version ⇒ Object
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 |