Module: OEHClient::Meta::Entity

Included in:
Workspace
Defined in:
lib/oehclient/meta/entity.rb

Constant Summary collapse

ONE_PARAM_DATA =

————- Constants

"data"
ONE_PARAM_SUCCESS =
"success"
ONE_PARAM_ID =
"id"
ONE_PARAM_NAME =
"name"
ONE_PARAM_CREATED_ON =
"createdDate"
ONE_PARAM_CREATED_BY =
"createdBy"
ONE_PARAM_ITEMS =
"items"

Instance Method Summary collapse

Instance Method Details

#createObject

————- Helper Class Methods

[View source]

40
41
# File 'lib/oehclient/meta/entity.rb', line 40

def create()
end

#entity_uri_stemObject

[View source]

24
25
26
# File 'lib/oehclient/meta/entity.rb', line 24

def entity_uri_stem
	@entity_stem
end

#entity_uri_stem=(uri_stem) ⇒ Object

————- Class Attributes

[View source]

20
21
22
# File 'lib/oehclient/meta/entity.rb', line 20

def entity_uri_stem=(uri_stem)
	@entity_stem = uri_stem
end

#find_by_name(active_session, name, **args) ⇒ Object

def self.create

[View source]

43
44
45
# File 'lib/oehclient/meta/entity.rb', line 43

def find_by_name(active_session, name,  **args)
	get(active_session, {:name => ONE_PARAM_NAME, :value => name}, args)
end

#get(active_session, attribute_nvp, **args) ⇒ Object

def get_collection

[View source]

69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/oehclient/meta/entity.rb', line 69

def get(active_session, attribute_nvp, **args)
	# store the active session object for future use
	session = active_session 	if (session.nil?)
	# initialize the entity instance as a blank hash
	entity_instance = Hash.new
	# Get the collection of objects requested
	get_collection(session, **args).each do | collection_instance |
		# find the matching entry and assign the entity instance
		entity_instance = collection_instance if (collection_instance[attribute_nvp[:name]].casecmp(attribute_nvp[:value]) == 0)
	end # Each OEHClient::Meta::Entity.get_collection
	# return the copy of the entity instance data
	entity_instance
end

#get_collection(active_session, **args) ⇒ Object

————- Core Class Methods

[View source]

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

def get_collection(active_session, **args)
	# store the active session object for future use
	self.session = active_session 	if (session.nil?)
	# get the list of args
	entity_uri = (args.has_key?(:space)) ? "workspaces/#{args[:space]}/#{entity_uri_stem}" : "#{entity_uri_stem}" 
	# construct the URL for retrieving the entity
	url = "#{OEHClient::Helper::Request::ONE_PROTOCOL}#{self.session.space.host}/one/services/api/#{entity_uri}"
	# set the header information
	header = (!self.session.cookies.nil? ? {:cookies => self.session.cookies}.merge!(OEHClient::Helper::Request.default_JSON_header()) : OEHClient::Helper::Request.default_JSON_header())
	# construct the request params using the header and params (if passed)
	request_params = {:header => header}
	request_params.merge!({:params => args[:params]}) 		if (args.has_key?(:params))
	# GET the data
	collection_response = OEHClient.get(url, nil, request_params)
	# return the data object for valid requests or a blank array otherwise
	((collection_response.has_key?(:body) && collection_response[:body][ONE_PARAM_SUCCESS]) ? (collection_response[:body][ONE_PARAM_DATA].is_a?(Hash) ? collection_response[:body][ONE_PARAM_DATA][ONE_PARAM_ITEMS] : collection_response[:body][ONE_PARAM_DATA]) : [] )
end

#sessionObject

[View source]

32
33
34
# File 'lib/oehclient/meta/entity.rb', line 32

def session
	@session
end

#session=(session_instance) ⇒ Object

[View source]

28
29
30
# File 'lib/oehclient/meta/entity.rb', line 28

def session=(session_instance)
	@session = session_instance
end