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

#aclsArray<Kong::Acl>

List Acls

Returns:



78
79
80
81
82
83
84
85
86
87
# File 'lib/kong/consumer.rb', line 78

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

#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.id}/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

#jwtsArray<Kong::JWT>

List JWTs

Returns:



92
93
94
95
96
97
98
99
100
101
# File 'lib/kong/consumer.rb', line 92

def jwts
  apps = []
  response = client.get("#{@api_end_point}#{self.id}/jwt") rescue nil
  if response
    response['data'].each do |attributes|
      apps << Kong::JWT.new(attributes)
    end
  end
  apps
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.id}/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
70
71
72
73
# File 'lib/kong/consumer.rb', line 67

def oauth2_tokens
  if self.custom_id
    OAuth2Token.list({ authenticated_userid: self.custom_id })
  else
    []
  end
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.id}/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