Sha256: 8c964c202bffd9439a2dfab26e091e8fc342f884fb213a577a0ca04c628ca1b0

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require 'kaltura'

module KalturaBox
  module Category
    module ClassMethods

      def list
        client = KalturaBox::Client.update_session
        category = Kaltura::KalturaCategoryService.new(client)
        category_list = category.list
        category_list.objects
      end

      def update_all_categories!
        list.each do |category|
          self.create(
            name: category.name,
            full_name: category.full_name,
            description: category.description,
            ref_id: category.id,
            entries_count: category.entries_count
          )
        end
      end

      def add(name, description, destroy_after_create = false)
        client = KalturaBox::Client.update_session
        category_svc = Kaltura::KalturaCategoryService.new(client)

        new_category = Kaltura::KalturaCategory.new
        new_category.name = name
        new_category.description = description

        if category = category_svc.add(new_category)
          @cat_obj = self.create(
            name: category.name,
            full_name: category.full_name,
            description: category.description,
            ref_id: category.id,
            entries_count: category.entries_count
          )
          category_svc.delete(@cat_obj.ref_id) if destroy_after_create
        end

        @cat_obj
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kaltura_box-0.0.3 lib/kaltura_box/category/class_methods.rb
kaltura_box-0.0.2 lib/kaltura_box/category/class_methods.rb
kaltura_box-0.0.1 lib/kaltura_box/category/class_methods.rb