Class: Qapi::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/qapi/connection.rb

Class Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • integration (Integration)

    model



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

.siteObject

Returns the value of attribute site.



5
6
7
# File 'lib/qapi/connection.rb', line 5

def site
  @site
end

.token_urlObject

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