class Bluekai::Category

Attributes

category_id_lookup[RW]

Public Instance Methods

category_create(body) click to toggle source

Public: Creates a new self-classification category

name:string - Name of the self-classification category

parent_id:integer - Unique ID of the parent node for the

self-classification category.

description:string - Description of uUser attribute

represented by this category.

analytics_excluded:string - {‘True’,‘False’} Specify whether the

self-classification category is to be excluded
from Audience Analytics reports. This property
is false by default.

navigation_only:string - {‘True’,‘False’} Specify whether the

self-classification category functions
exclusively as a parent node that cannot be
selected. This property is false by default.

mutex_children:string - {‘True’,‘False’} Specify whether to limit

the number of the category's child nodes
that can be added to an audience segment to one.
This property is false by default.

notes:string - (Optional) Enter any notes to be associated with

this self-classification category.

Example body hash = {name: ‘a new category’,

parent_id: '2342', description: 'an example category',
analytics_excluded: 'false', navigation_only: 'false',
mutex_children: 'false', notes: 'Just an API test' }

Returns: hash of created category parameters including its category_id

# File lib/bluekai/category.rb, line 100
def category_create(body)
  request('POST', '/Services/WS/classificationCategories', {}, body)
end
category_id(name_arr) click to toggle source

Public: Given the path of a category as array it

returns the Bluekai CategoryID, if category path was
not found it returns nil

name_arr:array_of_string - Self-classification category Path,

e.g., ['Self-Classification','Cake','Conversion']
for Self-Classification->Cake->Conversion

Returns: Bluekai category id

# File lib/bluekai/category.rb, line 153
def category_id(name_arr)
  @category_id_lookup ||= create_category_lookup
  category_id_lookup[name_arr.map(&:downcase)]
end
category_list(query = {}) click to toggle source

Public: Lists self classification categories in private taxonomy

name:string - Returns all self-classification categories based on the specified

name (whole or partial). The name is case-insensitive.

offset:integer - Specify the starting index from which to return

the self-classification categories.

size:integer - Specifies the maximum number of categories to be included in

the response. This filter requires the offset filter to be specified.

parent_id:integer - Returns all self-classification categories

based on the ID of the specified parent category.

sort_by:string - Enter ‘name’ or ‘id’ to sort the returned self-classification categories in

alphabetical or numerical order (based on categoryId)

sorting_order:string - Enter ‘asc’ or ‘desc’ to list the returned

self-classification categories in ascending
or descending order based on the category
name or categoryId.

Returns array of category hashes

# File lib/bluekai/category.rb, line 33
def category_list(query = {})
  query = { sort_by: 'name',
            sorting_order: 'asc' }.merge(query)
  request('GET', '/Services/WS/classificationCategories', query)[:categories]
end
category_read(query) click to toggle source

Public: returns the self-classification category

specified by the category_id

category_id:integer - MANDATORY The unique ID assigned to the

self-classification category to be retrieved

stats:string - {‘True’,‘False’} Returns the reach (estimated

number of unique users based on 30-day
inventory) for the self-classification category.

device_type:string - reach for the self-classification category

based on the specified device, which may either
be 'all', 'desktop', or 'mobile'

intl_code - returns the reach for the self-classification category

based on the specified country. The default country
is ALL. You may enter one of the following country
codes: ALL, US, AU, CA, GB, GER, ESP, NL, MX, IT,
FR, BR, AR, RU, NZ, JP, CL, CN.

Returns: A hash of Bluekai private category data

# File lib/bluekai/category.rb, line 60
def category_read(query)
  fail 'no category_id found in hash' unless query.key?(:category_id)
  category_id = query.delete(:category_id)
  request('GET', "/Services/WS/classificationCategories/#{category_id}", query)
end
category_update(category_id, body) click to toggle source

Public: Updates a given self-classification category

category_id:integer - The unique ID assigned to the self-classification

category to be updated

name:string - Name of the self-classification category

parent_id:integer - Unique ID of the parent node for the

self-classification category.

description:string - Description of uUser attribute

represented by this category.

analytics_excluded:string - {‘True’,‘False’} Specify whether the

self-classification category is to be excluded
from Audience Analytics reports. This property
is false by default.

navigation_only:string - {‘True’,‘False’} Specify whether the

self-classification category functions
exclusively as a parent node that cannot be
selected. This property is false by default.

mutex_children:string - {‘True’,‘False’} Specify whether to limit

the number of the category's child nodes
that can be added to an audience segment to one.
This property is false by default.

notes:string - (Optional) Enter any notes to be associated with

this self-classification category.

Example body hash = {category_id: 1234, name: ‘a chaged category’,

parent_id: '2342', description: 'an example category',
analytics_exclued: 'false', navigation_only: 'false',
mutex_children: 'false', notes: 'Just an API test' }

Returns: hash of updated category parameters

# File lib/bluekai/category.rb, line 141
def category_update(category_id, body)
  request('PUT', "/Services/WS/classificationCategories/#{category_id}", {}, body)
end

Private Instance Methods

construct_category_path(id, categories, path = []) click to toggle source
# File lib/bluekai/category.rb, line 162
def construct_category_path(id, categories, path = [])
  entry = categories[id]
  return path.compact unless entry && entry[:name]
  path.unshift(entry[:name])
  construct_category_path(entry[:parent_id], categories, path)
end
create_category_lookup() click to toggle source
# File lib/bluekai/category.rb, line 169
def create_category_lookup
  categories_by_id = category_list.each_with_object({}) do |category, acc|
    acc[category[:id]] = category
  end

  categories_by_id.keys.each_with_object({}) do |category_id, acc|
    key = construct_category_path(category_id, categories_by_id)
    acc[key.map(&:downcase)] = category_id
  end
end