Class: Cb::Clients::Category

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

Class Method Summary collapse

Methods inherited from Base

cb_client, headers

Class Method Details

.searchObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cb/clients/category.rb', line 16

def self.search
  json_hash = cb_client.cb_get(Cb.configuration.uri_job_category_search)
  categoryList = []

  if json_hash.key?('ResponseCategories')
    if json_hash['ResponseCategories'].key?('Categories')
      json_hash['ResponseCategories']['Categories']['Category'].each do |cat|
        categoryList << Models::Category.new(cat)
      end
    end

    cb_client.append_api_responses(categoryList, json_hash['ResponseCategories'])
  end

  cb_client.append_api_responses(categoryList, json_hash)
end

.search_by_host_site(host_site) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cb/clients/category.rb', line 33

def self.search_by_host_site(host_site)
  json_hash = cb_client.cb_get(Cb.configuration.uri_job_category_search, query: { CountryCode: host_site })
  categoryList = []

  if json_hash.key?('ResponseCategories')
    if json_hash['ResponseCategories'].key?('Categories')
      if json_hash['ResponseCategories']['Categories']['Category'].is_a?(Array)
        json_hash['ResponseCategories']['Categories']['Category'].each do |cat|
          categoryList << Models::Category.new(cat)
        end
      elsif json_hash['ResponseCategories']['Categories']['Category'].is_a?(Hash) && json_hash.length < 2
        categoryList << Models::Category.new(json_hash['ResponseCategories']['Categories']['Category'])
      end
    end

    cb_client.append_api_responses(categoryList, json_hash['ResponseCategories'])
  end

  cb_client.append_api_responses(categoryList, json_hash)
end