Class: Bouncer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bouncer-client/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bouncer_url) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
# File 'lib/bouncer-client/client.rb', line 10

def initialize bouncer_url
  @conn = Faraday.new(url: bouncer_url, headers: { accept: 'application/json' }) do |faraday|
    faraday.response :json, :content_type => /\bjson$/
    faraday.request  :json
    faraday.use Faraday::Response::RaiseError
    faraday.adapter  Faraday.default_adapter
    faraday.headers['Content-Type'] = 'application/json'
  end
end

Class Method Details

.currentObject



5
6
7
8
# File 'lib/bouncer-client/client.rb', line 5

def self.current
  raise "Missing BOUNCER_URL environment" unless ENV['BOUNCER_URL']
  @client ||= Bouncer::Client.new ENV['BOUNCER_URL']
end

Instance Method Details

#jwt(token) ⇒ Object



20
21
22
# File 'lib/bouncer-client/client.rb', line 20

def jwt token
  @conn.authorization :JWT, token
end

#meObject



28
29
30
# File 'lib/bouncer-client/client.rb', line 28

def me
  @conn.get('/me')
end

#token(token) ⇒ Object



24
25
26
# File 'lib/bouncer-client/client.rb', line 24

def token token
  @conn.authorization :Bearer, token
end

#token_infoObject



36
37
38
# File 'lib/bouncer-client/client.rb', line 36

def token_info
  @conn.get('/oauth/token/info')
end

#user(id) ⇒ Object



32
33
34
# File 'lib/bouncer-client/client.rb', line 32

def user id
  @conn.get("/users/#{id}")
end