Class: Cb::EmployeeTypesApi

Inherits:
Object
  • Object
show all
Defined in:
lib/cb/clients/employee_types_api.rb

Class Method Summary collapse

Class Method Details

.array_of_objects_from_hash(json_hash, my_api) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cb/clients/employee_types_api.rb', line 21

def self.array_of_objects_from_hash(json_hash, my_api)

	employee_types = []
	if json_hash.has_key?('ResponseEmployeeTypes')
      if json_hash['ResponseEmployeeTypes'].has_key?('EmployeeTypes') &&
          json_hash['ResponseEmployeeTypes']['EmployeeTypes'].present?

        if json_hash['ResponseEmployeeTypes']['EmployeeTypes']['EmployeeType'].is_a?(Array)

          json_hash['ResponseEmployeeTypes']['EmployeeTypes']['EmployeeType'].each do |et|
            employee_types << CbEmployeeType.new(et)
          end

        elsif json_hash['ResponseEmployeeTypes']['EmployeeTypes']['EmployeeType'].is_a?(Hash) && json_hash.length < 2
          employee_types << CbEmployeeType.new(json_hash['ResponseEmployeeTypes']['EmployeeTypes']['EmployeeType'])
        end

      end
      my_api.append_api_responses(employee_types, json_hash['ResponseEmployeeTypes'])
    end

    my_api.append_api_responses(employee_types, json_hash)
	
	return employee_types
end

.searchObject



6
7
8
9
10
11
# File 'lib/cb/clients/employee_types_api.rb', line 6

def self.search
	my_api = Cb::Utils::Api.new()
	json_hash = my_api.cb_get(Cb.configuration.uri_employee_types)
	
	return array_of_objects_from_hash(json_hash, my_api)
end

.search_by_host_site(hostsite) ⇒ Object



13
14
15
16
17
18
# File 'lib/cb/clients/employee_types_api.rb', line 13

def self.search_by_host_site(hostsite)
	my_api = Cb::Utils::Api.new()
	json_hash = my_api.cb_get(Cb.configuration.uri_employee_types, :query => {:CountryCode => hostsite})

	return array_of_objects_from_hash(json_hash, my_api)
end