Class: TimeDoctor::Worker
- Inherits:
-
Object
- Object
- TimeDoctor::Worker
- Defined in:
- lib/timedoctor/worker.rb
Constant Summary collapse
- ENTRY =
'https://webapi.timedoctor.com/'.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #exchange(method, url, params = {}) ⇒ Object
-
#initialize(config) ⇒ Worker
constructor
A new instance of Worker.
Constructor Details
#initialize(config) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 |
# File 'lib/timedoctor/worker.rb', line 7 def initialize(config) @config = config @conn = Faraday.new(url: ENTRY) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/timedoctor/worker.rb', line 5 def config @config end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
5 6 7 |
# File 'lib/timedoctor/worker.rb', line 5 def conn @conn end |
Instance Method Details
#exchange(method, url, params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/timedoctor/worker.rb', line 12 def exchange(method, url, params = {}) raise EmptyAccessToken unless config[:access_token] params[:access_token] = config[:access_token] params[:_format] = :json response = conn.public_send method, url, params case response.status when 200 JSON.parse(response.body, symbolize_names: true) when 401 exchange(method, url, params) if Token.new(config).refresh else raise UnknownError, response end end |