Class: Qapi::Connection
- Inherits:
-
Object
- Object
- Qapi::Connection
- Defined in:
- lib/qapi/connection.rb
Class Attribute Summary collapse
-
.site ⇒ Object
Returns the value of attribute site.
-
.token_url ⇒ Object
Returns the value of attribute token_url.
Instance Method Summary collapse
- #get(path, query = nil) ⇒ Object
-
#initialize(key, secret, integration) ⇒ Connection
constructor
TODO: Make this generic and don’t use an Integration object OR we could create a value object inside Qapi.
Constructor Details
#initialize(key, secret, integration) ⇒ Connection
TODO: Make this generic and don’t use an Integration object OR we could create a value object inside Qapi
13 14 15 16 17 18 19 20 21 |
# File 'lib/qapi/connection.rb', line 13 def initialize(key, secret, integration) @integration = integration client = OAuth2::Client.new(key, secret, site: self.class.site, token_url: self.class.token_url) @access_token = OAuth2::AccessToken.new(client, integration.token, { refresh_token: integration.refresh_token, expires_at: integration.expires_at, mode: :query }) end |
Class Attribute Details
.site ⇒ Object
Returns the value of attribute site.
5 6 7 |
# File 'lib/qapi/connection.rb', line 5 def site @site end |
.token_url ⇒ Object
Returns the value of attribute token_url.
4 5 6 |
# File 'lib/qapi/connection.rb', line 4 def token_url @token_url end |
Instance Method Details
#get(path, query = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/qapi/connection.rb', line 23 def get(path, query = nil) refresh_if_required! @access_token.get(path, params: query).tap do |response| # TODO: Handle the case where the token expires raise Qapi::Error.new(response.body) unless response.status == 200 end end |