Class: Kong::Consumer

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/kong/consumer.rb

Constant Summary collapse

ATTRIBUTE_NAMES =
%w(id custom_id username created_at).freeze
API_END_POINT =
'/consumers/'.freeze

Instance Attribute Summary

Attributes included from Base

#api_end_point, #attributes

Instance Method Summary collapse

Methods included from Base

#client, #create, #create_or_update, #get, included, #initialize, #method_missing, #new?, #respond_to?, #save, #update

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Kong::Base

Instance Method Details

#basic_authsArray<Kong::KeyAuth]

List KeyAuth credentials

Returns:



39
40
41
42
43
44
45
46
47
48
# File 'lib/kong/consumer.rb', line 39

def basic_auths
  apps = []
  response = client.get("#{@api_end_point}#{self.username}/basic-auth") rescue nil
  if response
    response['data'].each do |attributes|
      apps << Kong::BasicAuth.new(attributes)
    end
  end
  apps
end

#deleteObject



8
9
10
11
12
13
# File 'lib/kong/consumer.rb', line 8

def delete
  self.oauth2_tokens.each do |token|
    token.delete
  end
  super
end

#key_authsArray<Kong::KeyAuth]

List KeyAuth credentials

Returns:



53
54
55
56
57
58
59
60
61
62
# File 'lib/kong/consumer.rb', line 53

def key_auths
  apps = []
  response = client.get("#{@api_end_point}#{self.username}/key-auth") rescue nil
  if response
    response['data'].each do |attributes|
      apps << Kong::KeyAuth.new(attributes)
    end
  end
  apps
end

#oauth2_tokensArray<Kong::OAuth2Token>

List OAuth2Tokens

Returns:



67
68
69
# File 'lib/kong/consumer.rb', line 67

def oauth2_tokens
  OAuth2Token.list({ authenticated_userid: self.custom_id })
end

#oauth_appsArray<Kong::OAuthApp>

List OAuth applications

Returns:



25
26
27
28
29
30
31
32
33
34
# File 'lib/kong/consumer.rb', line 25

def oauth_apps
  apps = []
  response = client.get("#{@api_end_point}#{self.username}/oauth2") rescue nil
  if response
    response['data'].each do |attributes|
      apps << Kong::OAuthApp.new(attributes)
    end
  end
  apps
end

#pluginsArray<Kong::Plugin>

List plugins

Returns:



18
19
20
# File 'lib/kong/consumer.rb', line 18

def plugins
  Plugin.list({ consumer_id: self.id })
end