Class: Sensibo::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/sensibo/real.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject (readonly)

Returns the value of attribute api_key.



2
3
4
# File 'lib/sensibo/real.rb', line 2

def api_key
  @api_key
end

#connectionObject (readonly)

Returns the value of attribute connection.



2
3
4
# File 'lib/sensibo/real.rb', line 2

def connection
  @connection
end

#urlObject (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