Class: RippleKeycloak::BaseModel
- Inherits:
-
Object
- Object
- RippleKeycloak::BaseModel
- Defined in:
- lib/ripple_keycloak/base_model.rb
Class Method Summary collapse
- .all(first: nil, max: nil) ⇒ Object
- .delete(id) ⇒ Object
- .find(id) ⇒ Object
- .find_by(field:, value:) ⇒ Object
- .object_type(object_type) ⇒ Object
- .search(value) ⇒ Object
Class Method Details
.all(first: nil, max: nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/ripple_keycloak/base_model.rb', line 16 def all(first: nil, max: nil) url = "#{@object_type}?" url += "first=#{first}&" if first url += "max=#{max}" if max client.get(url).parsed_response end |
.delete(id) ⇒ Object
38 39 40 |
# File 'lib/ripple_keycloak/base_model.rb', line 38 def delete(id) client.delete("#{@object_type}/#{id}").parsed_response end |
.find(id) ⇒ Object
24 25 26 |
# File 'lib/ripple_keycloak/base_model.rb', line 24 def find(id) client.get("#{@object_type}/#{id}").parsed_response end |
.find_by(field:, value:) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ripple_keycloak/base_model.rb', line 28 def find_by(field:, value:) results = search(value) if results.is_a? Array results.each do |instance| return instance if instance[field] == value end end raise NotFoundError, "Object type: #{@object_type}, field: #{field}, value: #{value}" end |
.object_type(object_type) ⇒ Object
8 9 10 |
# File 'lib/ripple_keycloak/base_model.rb', line 8 def object_type(object_type) @object_type = object_type end |
.search(value) ⇒ Object
12 13 14 |
# File 'lib/ripple_keycloak/base_model.rb', line 12 def search(value) client.get("#{@object_type}?search=#{value}").parsed_response end |