class Qtc::Eds::Client
Constants
- DEFAULT_OPTIONS
Public Class Methods
new(backend_id, options = {})
click to toggle source
Initialize
@param [String] backend_id @param [Hash] options
# File lib/qtc/eds/client.rb, line 18 def initialize(backend_id, options = {}) @options = DEFAULT_OPTIONS.merge(options) @backend_id = backend_id headers = {'Enginio-Backend-Id' => @backend_id} @client = Qtc::Client.new(@options[:api_url], headers) end
Public Instance Methods
access_token=(access_token)
click to toggle source
Set access token
@param [String] access_token
# File lib/qtc/eds/client.rb, line 68 def access_token=(access_token) if !access_token.nil? @client.default_headers['Authorization'] = "Bearer #{access_token}" else @client.default_headers.delete('Authorization') end end
collection(name)
click to toggle source
Get collection
@param [String] name @return [Qtc::Eds::Collection]
# File lib/qtc/eds/client.rb, line 38 def collection(name) Qtc::Eds::Collection.new(@client, "/objects/#{name}") end
create_user_token(username, password)
click to toggle source
Create user access token
@param [String] username @param [String] password
# File lib/qtc/eds/client.rb, line 96 def create_user_token(username, password) body = { grant_type: 'password', username: username, password: password } @client.post('/auth/oauth2/token', body, {}, {'Content-Type' => 'application/x-www-form-urlencoded'}) end
current_user()
click to toggle source
# File lib/qtc/eds/client.rb, line 58 def current_user if @client.default_headers['Authorization'] @client.get('/user') end end
http_client()
click to toggle source
Get Qtc::Client
instance
@return [Qtc::Client]
# File lib/qtc/eds/client.rb, line 29 def http_client @client end
revoke_user_token(token)
click to toggle source
Revoke user access token
@param [String] token
# File lib/qtc/eds/client.rb, line 109 def revoke_user_token(token) body = { token: token } @client.post('/auth/oauth2/revoke', body, {}, {'Content-Type' => 'application/x-www-form-urlencoded'}) end
usergroups()
click to toggle source
Get usergroup collection
@return [Qtc::Eds::UsergroupCollection]
# File lib/qtc/eds/client.rb, line 54 def usergroups Qtc::Eds::UsergroupCollection.new(@client) end
users()
click to toggle source
Get user collection
@return [Qtc::Eds::UserCollection]
# File lib/qtc/eds/client.rb, line 46 def users Qtc::Eds::UserCollection.new(@client) end
with_access_token(access_token, &block)
click to toggle source
Call block with given access token
@param [String] access_token @param []
# File lib/qtc/eds/client.rb, line 81 def with_access_token(access_token, &block) prev_auth = @client.default_headers['Authorization'].dup @client.default_headers['Authorization'] = "Bearer #{access_token}" result = call(&block) @client.default_headers['Authorization'] = prev_auth result ensure @client.default_headers['Authorization'] = prev_auth if prev_auth end