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
- #version ⇒ Object
Constructor Details
#initialize(url) ⇒ API
7 8 9 10 11 12 13 14 15 |
# File 'lib/rspec/openhab/api.rb', line 7 def initialize(url) @faraday = Faraday.new(url) do |f| f.request :retry f.response :raise_error f.response :json f.adapter :net_http_persistent f.path_prefix = "/rest/" end end |
Instance Method Details
#item(name) ⇒ Object
28 29 30 31 32 |
# File 'lib/rspec/openhab/api.rb', line 28 def item(name) @faraday.get("items/#{name}").body rescue Faraday::ResourceNotFound nil end |
#items ⇒ Object
24 25 26 |
# File 'lib/rspec/openhab/api.rb', line 24 def items @faraday.get("items").body end |
#version ⇒ Object
17 18 19 20 21 22 |
# File 'lib/rspec/openhab/api.rb', line 17 def version body = @faraday.get.body version = body.dig("runtimeInfo", "version") version = "#{version}-SNAPSHOT" if body.dig("runtimeInfo", "buildString")&.start_with?("Build #") version end |