Class: Kongfigure::Resources::Consumer

Inherits:
Base
  • Object
show all
Defined in:
lib/kongfigure/resources/consumer.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#id, #kongfigure_ignore_fields, #plugins, #unchanged, #updated

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, build_all, #display_name, #has_to_be_deleted?, #initialize, #mark_as_unchanged, #mark_as_updated, #plugin_allowed?

Constructor Details

This class inherits a constructor from Kongfigure::Resources::Base

Instance Attribute Details

#aclsObject

Returns the value of attribute acls.



3
4
5
# File 'lib/kongfigure/resources/consumer.rb', line 3

def acls
  @acls
end

#custom_idObject

Returns the value of attribute custom_id.



3
4
5
# File 'lib/kongfigure/resources/consumer.rb', line 3

def custom_id
  @custom_id
end

#key_authsObject

Returns the value of attribute key_auths.



3
4
5
# File 'lib/kongfigure/resources/consumer.rb', line 3

def key_auths
  @key_auths
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/kongfigure/resources/consumer.rb', line 3

def username
  @username
end

Class Method Details

.build(hash) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/kongfigure/resources/consumer.rb', line 5

def self.build(hash)
  consumer           = new(hash["id"], hash["kongfigure_ignore_fields"])
  consumer.username  = hash["username"]
  consumer.custom_id = hash["custom_id"]
  consumer.acls      = Kongfigure::Resources::Consumers::ACL.build_all(hash["acls"] || [])
  consumer.plugins   = Kongfigure::Resources::Plugin.build_all(hash["plugins"] || [])
  consumer.key_auths = (hash["key_auths"] || []).map do |key_auth_hash|
    Kongfigure::Resources::Consumers::KeyAuth.build(key_auth_hash)
  end
  consumer
end

Instance Method Details

#api_attributesObject



25
26
27
28
29
30
# File 'lib/kongfigure/resources/consumer.rb', line 25

def api_attributes
  {
    "username"  =>  username,
    "custom_id" => custom_id
  }.compact
end

#api_nameObject



21
22
23
# File 'lib/kongfigure/resources/consumer.rb', line 21

def api_name
  "consumers"
end

#has_acl?(acl) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/kongfigure/resources/consumer.rb', line 36

def has_acl?(acl)
  acls && acls.include?(acl)
end

#has_key_auth?(key_auth) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/kongfigure/resources/consumer.rb', line 32

def has_key_auth?(key_auth)
  key_auths && key_auths.include?(key_auth)
end

#identifierObject



17
18
19
# File 'lib/kongfigure/resources/consumer.rb', line 17

def identifier
  username
end

#to_sObject



40
41
42
# File 'lib/kongfigure/resources/consumer.rb', line 40

def to_s
  "#{username}"
end