Class: EY::GateKeeper::Client::Consumer
- Inherits:
-
Rack::Client::Simple
- Object
- Rack::Client::Simple
- EY::GateKeeper::Client::Consumer
- Defined in:
- lib/ey_gatekeeper/client/consumer.rb
Instance Attribute Summary collapse
-
#impersonation_token ⇒ Object
Returns the value of attribute impersonation_token.
-
#key ⇒ Object
Returns the value of attribute key.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #build_app(options) ⇒ Object
- #effective_access_controls ⇒ Object
- #impersonate!(impersonation_token) ⇒ Object
-
#initialize(key, secret, options = {}) ⇒ Consumer
constructor
A new instance of Consumer.
- #just_me! ⇒ Object
Constructor Details
#initialize(key, secret, options = {}) ⇒ Consumer
Returns a new instance of Consumer.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 7 def initialize(key, secret, = {}) @key = key @secret = secret @endpoint = [:endpoint] @token = nil if @endpoint super(build_app(), @endpoint) else super(build_app()) end end |
Instance Attribute Details
#impersonation_token ⇒ Object
Returns the value of attribute impersonation_token.
5 6 7 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 5 def impersonation_token @impersonation_token end |
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 5 def key @key end |
#secret ⇒ Object
Returns the value of attribute secret.
5 6 7 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 5 def secret @secret end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 5 def token @token end |
Instance Method Details
#build_app(options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 47 def build_app() inner_app = .fetch(:app, Rack::Client::Handler::NetHTTP.new) token_setter = method(:token=) key_method = method(:key) secret_method = method(:secret) impersonation_token_method = method(:impersonation_token) Rack::Builder.app do |builder| builder.use EY::GateKeeper::Client::Middleware::Authentication, key_method, secret_method, token_setter, impersonation_token_method builder.run inner_app end end |
#effective_access_controls ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 38 def effective_access_controls response = get('/_effective_access_controls') if response.status == 200 && response.content_type == 'application/json' JSON.parse(response.body) # rack-client collapses the body for us else {} end end |
#impersonate!(impersonation_token) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 25 def impersonate!(impersonation_token) @impersonation_token = case impersonation_token when EY::GateKeeper::Token impersonation_token.token when String, NilClass impersonation_token end end |
#just_me! ⇒ Object
34 35 36 |
# File 'lib/ey_gatekeeper/client/consumer.rb', line 34 def just_me! impersonate!(nil) end |