Class: EntityHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/BaseClass/EntityHandler.rb

Overview

An EntityHandler is the equivalent of a method centralizer for a corresponding endpoint (such as /v1/entities).

Functional naming conventions and equivalents: create(fields) <=> ‘Create a new Entity` all(fields) <=> `List all Entities` find(id) <=> `Retrieve an existing Entity` delete(id) <=> `Delete an Entity` update(id, fields) <=> `Update an Entity`

Instance Method Summary collapse

Constructor Details

#initialize(origin) ⇒ EntityHandler

Constructs an EntityHandler instance

Keyword arguments: origin Client – Originating client reference



19
20
21
# File 'lib/BaseClass/EntityHandler.rb', line 19

def initialize(origin)
	@origin = origin # Reference to originating Client instance
end

Instance Method Details

#all(filters = nil) ⇒ Object

Function definition for listing all entities. Base function checks for invalid parameters.

Keyword arguments: filters Hash – (optional) Filters to apply to restrict listing. Currently supported: limit, page

Exceptions: SDKInvalidArgException if provided filters param is not a hash. SDKInvalidArgException if invalid filter value found in filters hash.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/BaseClass/EntityHandler.rb', line 51

def all(filters = nil)
	if !filters
		filters = {}
	end

	if !filters.is_a? Hash
		raise SDKInvalidArgException, '`filters` must be a hash'
	else
		filters.each do |k,|
			if !['include', 'limit', 'page'].include? k
				raise SDKInvalidArgException, 'unsupported ' + k + ' for `filters`'
			end
		end
	end

end

#create(fields) ⇒ Object

Function definition for creating a new entity. Base function checks for invalid parameters.

Keyword arguments: fields Hash – Non-empty hash consisting of entity data to send for adding

Exceptions: SDKInvalidArgException if provided fields param is not a hash. SDKInvalidArgException if provided fields param is empty.



33
34
35
36
37
38
39
# File 'lib/BaseClass/EntityHandler.rb', line 33

def create(fields)
	if !fields.is_a? Hash
		raise SDKInvalidArgException, '`fields` must be a hash'
	elsif fields.length.zero?
		raise SDKInvalidArgException, '`fields` must be non-empty'
	end
end

#delete(id) ⇒ Object

Function definition for deleting an existing entity. Base function checks for invalid parameters.

Keyword arguments: id Fixnum – ID field of entity to delete in the entity collection

Exceptions: SDKInvalidArgException if provided id param is not an integer.



92
93
94
95
96
# File 'lib/BaseClass/EntityHandler.rb', line 92

def delete(id)
	if !id.is_a? Fixnum
		raise SDKInvalidArgException, '`id` must be of type Fixnum'
	end
end

#find(id) ⇒ Object

Function definition for retrieving an existing entity. Base function checks for invalid parameters.

Keyword arguments: id Fixnum – ID field to look for in the entity collection

Exceptions: SDKInvalidArgException if provided id param is not an integer.



77
78
79
80
81
# File 'lib/BaseClass/EntityHandler.rb', line 77

def find(id)
	if !id.is_a? Fixnum
		raise SDKInvalidArgException, '`id` must be of type Fixnum'
	end
end

#update(id, fields) ⇒ Object

Function definition for updating an existing entity. Base function checks for invalid parameters.

Keyword arguments: id Fixnum – ID field of entity to update in the entity collection fields Hash – Non-empty dictionary consisting of entity data to send for update

Exceptions: SDKInvalidArgException if provided id param is not an integer. SDKInvalidArgException if provided fields param is not a hash. SDKInvalidArgException if provided fields param is empty.



110
111
112
113
114
115
116
117
118
# File 'lib/BaseClass/EntityHandler.rb', line 110

def update(id, fields)
	if !id.is_a? Fixnum
		raise SDKInvalidArgException, '`id` must be of type Fixnum'
	elsif !fields.is_a? Hash
		raise SDKInvalidArgException, '`fields` must be a hash'
	elsif fields.length.zero?
		raise SDKInvalidArgException, '`fields` must be non-empty'
	end
end