Class: Cb::CategoryApi

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

Class Method Summary collapse

Class Method Details

.searchObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cb/clients/category_api.rb', line 5

def self.search
  my_api = Cb::Utils::Api.new()
  cb_response = my_api.cb_get(Cb.configuration.uri_job_category_search)
  json_hash = JSON.parse(cb_response.response.body)

  categoryList = []
  json_hash["ResponseCategories"]["Categories"]["Category"].each do |cat|
    categoryList << CbCategory.new(cat)
  end
  return categoryList
end

.search_by_host_site(host_site) ⇒ Object



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

def self.search_by_host_site(host_site)
  my_api = Cb::Utils::Api.new()
  cb_response = my_api.cb_get(Cb.configuration.uri_job_category_search, :query => {:CountryCode => host_site})
  json_hash = JSON.parse(cb_response.response.body)

  categoryList = []
  unless json_hash.empty?
    if json_hash["ResponseCategories"]["Categories"]["Category"].is_a?(Array)
      json_hash["ResponseCategories"]["Categories"]["Category"].each do |cat|
        categoryList << CbCategory.new(cat)
      end
    elsif json_hash["ResponseCategories"]["Categories"]["Category"].is_a?(Hash) && json_hash.length < 2
      categoryList << CbCategory.new(json_hash["ResponseCategories"]["Categories"]["Category"])
    end
  end

  return categoryList
end