Module: Keycloak::Admin::Resource

Included in:
Clients, Groups, Realms, Users
Defined in:
lib/keycloak/admin/resource.rb,
lib/keycloak/admin/resource/pagination.rb

Overview

Abstract class for Keycloak::Admin resources with common methods.

  • #all

  • #create

  • #count

  • #delete

  • #find_by, alias #lookup

  • #find_by_id, alias #get

  • #update, alias #edit

Defined Under Namespace

Modules: Pagination

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agent=(value) ⇒ Object (writeonly)

Sets the attribute agent

Parameters:

  • value

    the value to set the attribute agent to.



18
19
20
# File 'lib/keycloak/admin/resource.rb', line 18

def agent=(value)
  @agent = value
end

Instance Method Details

#allObject

List all resource objects.



22
23
24
25
26
# File 'lib/keycloak/admin/resource.rb', line 22

def all
  objects = @agent.get(resource)

  objects.map { |object| mash(object) }
end

#create(attributes) ⇒ Object

Create a new resource object.



30
31
32
33
34
# File 'lib/keycloak/admin/resource.rb', line 30

def create(attributes)
  @agent.post(resource, params: { body: attributes.to_json })

  true
end

#delete(id) ⇒ Object

Delete a resource object by id.



38
39
40
41
42
# File 'lib/keycloak/admin/resource.rb', line 38

def delete(id)
  @agent.delete("#{resource}/#{id}")

  true
end

#find_by(lookup) ⇒ Object Also known as: lookup

Find resource objects by attributes, name and value.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/keycloak/admin/resource.rb', line 46

def find_by(lookup)
  objects = all

  lookup.each do |key, value|
    objects = objects.select do |object|
      match_value?(object, key, value)
    end
    break if !objects
  end

  objects || []
end

#find_by_id(id) ⇒ Object Also known as: get

Find a resource object by id.



62
63
64
65
66
# File 'lib/keycloak/admin/resource.rb', line 62

def find_by_id(id)
  object = @agent.get("#{resource}/#{id}")

  mash(object)
end

#update(id, attributes) ⇒ Object Also known as: edit

Update a resource object by id.



71
72
73
74
75
# File 'lib/keycloak/admin/resource.rb', line 71

def update(id, attributes)
  @agent.put("#{resource}/#{id}", params: { body: attributes.to_json })

  true
end