Class: Nest::Real
- Inherits:
-
Object
- Object
- Nest::Real
- Defined in:
- lib/nest/real.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#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 11 |
# File 'lib/nest/real.rb', line 4 def initialize(attributes={}) @url = attributes[:url] || 'https://developer-api.nest.com/' @access_token = attributes[:access_token] || ENV["ACCESS_TOKEN"] @connection = Faraday.new(url: @url, headers: { "Content-Type" => "application/json" }) do |b| b.adapter :excon b. :Bearer, @access_token end end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
2 3 4 |
# File 'lib/nest/real.rb', line 2 def access_token @access_token end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
2 3 4 |
# File 'lib/nest/real.rb', line 2 def connection @connection end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
2 3 4 |
# File 'lib/nest/real.rb', line 2 def url @url end |
Instance Method Details
#request(method, path, args = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nest/real.rb', line 13 def request(method, path, args={}) res = connection.send(method) do |req| req.url path end while res.status == 307 redirect_client = Faraday.new(res.headers["Location"]) do |b| b.adapter :excon b. :Bearer, @access_token end res = redirect_client.send(method, "/") end Oj.load(res.body) end |