Class: Sensibo::Real
- Inherits:
-
Object
- Object
- Sensibo::Real
- Defined in:
- lib/sensibo/real.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Real
constructor
A new instance of Real.
- #request(method, path, args = {}) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Real
Returns a new instance of Real.
4 5 6 7 8 9 10 |
# File 'lib/sensibo/real.rb', line 4 def initialize(attributes={}) @url = attributes[:url] || "https://home.sensibo.com" @api_key = attributes[:api_key] || ENV["API_KEY"] @connection = Faraday.new(url: @url, headers: { "Content-Type" => "application/json" }) do |b| b.adapter :excon end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
2 3 4 |
# File 'lib/sensibo/real.rb', line 2 def api_key @api_key end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
2 3 4 |
# File 'lib/sensibo/real.rb', line 2 def connection @connection end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
2 3 4 |
# File 'lib/sensibo/real.rb', line 2 def url @url end |
Instance Method Details
#request(method, path, args = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/sensibo/real.rb', line 12 def request(method, path, args={}) res = connection.send(method) do |req| req.url "/api/v2#{path}" req.params = { apiKey: self.api_key, fields: "*" } req.body = Oj.dump(args[:body]) if args[:body] end Oj.load(res.body) end |