Class: OpenHAB::API
- Inherits:
-
Object
- Object
- OpenHAB::API
- Defined in:
- lib/rspec/openhab/api.rb
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #channel_types ⇒ Object
-
#initialize(url, token = nil) ⇒ API
constructor
A new instance of API.
- #item(name) ⇒ Object
- #items ⇒ Object
- #locale ⇒ Object
- #measurement_system ⇒ Object
- #thing_types ⇒ Object
- #things ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(url, token = nil) ⇒ API
7 8 9 10 11 12 13 14 |
# File 'lib/rspec/openhab/api.rb', line 7 def initialize(url, token = nil) @faraday = Faraday.new(url) do |f| f.response :raise_error f.response :json f.path_prefix = "/rest/" f.headers = { "X-OPENHAB-TOKEN" => token } if token end end |
Instance Method Details
#authenticated? ⇒ Boolean
52 53 54 |
# File 'lib/rspec/openhab/api.rb', line 52 def authenticated? @faraday.headers.key?("X-OPENHAB-TOKEN") end |
#channel_types ⇒ Object
40 41 42 |
# File 'lib/rspec/openhab/api.rb', line 40 def channel_types @faraday.get("channel-types").body end |
#item(name) ⇒ Object
34 35 36 37 38 |
# File 'lib/rspec/openhab/api.rb', line 34 def item(name) @faraday.get("items/#{name}").body rescue Faraday::ResourceNotFound nil end |
#items ⇒ Object
30 31 32 |
# File 'lib/rspec/openhab/api.rb', line 30 def items @faraday.get("items", metadata: ".*").body end |
#locale ⇒ Object
22 23 24 |
# File 'lib/rspec/openhab/api.rb', line 22 def locale root_data["locale"] end |
#measurement_system ⇒ Object
26 27 28 |
# File 'lib/rspec/openhab/api.rb', line 26 def measurement_system root_data["measurementSystem"] end |
#thing_types ⇒ Object
44 45 46 |
# File 'lib/rspec/openhab/api.rb', line 44 def thing_types @faraday.get("thing-types").body end |
#things ⇒ Object
48 49 50 |
# File 'lib/rspec/openhab/api.rb', line 48 def things @faraday.get("things").body end |
#version ⇒ Object
16 17 18 19 20 |
# File 'lib/rspec/openhab/api.rb', line 16 def version version = root_data.dig("runtimeInfo", "version") version = "#{version}-SNAPSHOT" if root_data.dig("runtimeInfo", "buildString")&.start_with?("Build #") version end |