Class: EY::GateKeeper::Client::Consumer

Inherits:
Rack::Client::Simple
  • Object
show all
Defined in:
lib/ey_gatekeeper/client/consumer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @key = key
  @secret = secret
  @endpoint = options[:endpoint]
  @token = nil

  if @endpoint
    super(build_app(options), @endpoint)
  else
    super(build_app(options))
  end
end

Instance Attribute Details

#impersonation_tokenObject

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

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/ey_gatekeeper/client/consumer.rb', line 5

def key
  @key
end

#secretObject

Returns the value of attribute secret.



5
6
7
# File 'lib/ey_gatekeeper/client/consumer.rb', line 5

def secret
  @secret
end

#tokenObject

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(options)
  inner_app = options.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_controlsObject



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