Class: Rusic::Uploaders::CustomAttributes

Inherits:
Base
  • Object
show all
Defined in:
lib/rusic/uploaders/custom_attributes.rb

Instance Attribute Summary

Attributes inherited from Base

#api_host, #api_key, #file, #theme

Instance Method Summary collapse

Methods inherited from Base

#initialize, #upload_file

Constructor Details

This class inherits a constructor from Rusic::Uploaders::Base

Instance Method Details

#paramsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rusic/uploaders/custom_attributes.rb', line 11

def params
  parameters = {
    custom_attribute_collections: []
  }
  attribute_collections.each do |attribute_collection_key, attribute_collection|
    custom_attribute_collection = {
      key: attribute_collection_key,
      title: attribute_collection["title"],
      help_title: attribute_collection.fetch('help_title', nil),
      help_body: attribute_collection.fetch('help_body', nil),
      custom_attributes: [],
    }
    attribute_collection["attributes"].each do |attribute_key, attribute|
      custom_attribute_collection[:custom_attributes] << {
        'key' => attribute_key,
        'value' => attribute.fetch('value'),
        'help_text' => attribute.fetch('help_text', ''),
        'input_type' => attribute.fetch('type', 'string'),
        'select_options' => attribute.fetch('select_options', nil),
      }
    end
    parameters[:custom_attribute_collections] << custom_attribute_collection
  end
  parameters
end

#performObject



7
8
9
# File 'lib/rusic/uploaders/custom_attributes.rb', line 7

def perform
  client["themes/#{theme}/custom_attribute_collections"].post(params.to_json, content_type: :json)
end