Class: Ubiquity::Envoi::API::Utilities

Inherits:
Client
  • Object
show all
Defined in:
lib/ubiquity/envoi/api/utilities.rb

Instance Attribute Summary

Attributes inherited from Client

#http_client, #logger, #request, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

#content, #content_create, #content_details, #content_field_details, #content_fieldset_details, #content_fieldsets, #content_type_details, #content_types, #file_get, #http, #initialize, #media_file_add_file, #media_file_create, #media_file_delete, #media_file_files_get, #media_file_get, #media_file_secured_get, #media_file_transcode, #media_file_transcode_parameters_get, #media_file_transcoders_get, #media_file_update, #media_files_detailed_get, #media_files_get, #paginator, #process_request, #process_request_using_class, #project_get, #projects_get, #storages_get, #user_create, #who

Constructor Details

This class inherits a constructor from Ubiquity::Envoi::API::Client

Class Method Details

.content_fieldset_to_metadata_map(content_fieldset_details, options = { }) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ubiquity/envoi/api/utilities.rb', line 124

def self.(content_fieldset_details, options = { })
  fieldset_form = content_fieldset_details['form'] || [ ]
   = { }

  key_field_by = options[:key_field_by] || 'label'

  fieldset_group = { }
  fieldset_form.each do |fsf|
    fieldset_group_id = fsf['id']
    fieldset_group_name = fsf['name']

    fieldset_group[fieldset_group_id] = fsf

    field_group_fields = fsf['fields']
    field_group_fields.each do |field|
      field_label = field['label']
      field_name = field['name']
      field_required = field['required']
      field_details = field['field']
      field_type = field_details['type']

      md_map_field_key = field[key_field_by]

      [md_map_field_key] = {
        :field_name => field_name, :group_name => fieldset_group_name, :field_type => field_type,
        :field_required => field_required, :field_label => field_label
      }
    end
  end

  return 
end

Instance Method Details

#content_details_metadata_simplify(content_details, options = { }) ⇒ Object



8
9
10
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/ubiquity/envoi/api/utilities.rb', line 8

def (content_details, options = { })
   = { }

  groups = content_details['groups'] || [ ]
  groups.each do |group|
    group_label = group['label']
     = { }
    values = group['values']
    values.each do |value|

      value_label = value['label']
      value_value = value['value']
      # display_value = value['display_value']
      #
      # value_field = value['field']
      # value_field_id = value_field['id']
      # value_field_uri = value_field['uri']

      md_key = value_label
      md_value = value_value

      [md_key] = md_value
    end
    [group_label] = 
  end

  
end

#content_field_group_by(metadata_field_group, options = { }) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ubiquity/envoi/api/utilities.rb', line 55

def content_field_group_by(, options = { })
  if .is_a?(Array)
    return .map { |mfg| content_field_group_by(mfg, options) }
  end
  md_field_type = options[:metadata_field_type] || 'label' # label, id | field_uri

  md_out = { }

   = ['values'] || [ ]

  .each do |md_field|
    # md_field_id = md_field['id']
    # md_field_label = md_field['label']
    md_field_value = md_field['value']
    md_field_def = md_field['field']
    # md_field_def_type = md_field_def['type']

    md_field_key = case md_field_type
                     when 'id', 'label'
                       md_field[md_field_type]
                     when 'field_uri'
                       md_field_def['uri']
                   end

    # puts %("#{md_field_id}" => "#{md_field_value}",)
    # md_map[md_field_id] = { md_field_label => { :field_id => md_field_id, :group_id => metadata_fieldgroup_id, :field_type => md_field_def_type } }
    md_out[md_field_key] = md_field_value
  end

  md_out
end

#content_fieldset_get_by_name(args = { }, options = { }) ⇒ Object



37
38
39
40
41
42
# File 'lib/ubiquity/envoi/api/utilities.rb', line 37

def content_fieldset_get_by_name(args = { }, options = { })
  _name = args[:name]
  _response = content_fieldsets
  _results = _response['results']
  _results.find { |fs| fs['name'] == _name }
end

#content_type_by_name(args = { }, options = { }) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/ubiquity/envoi/api/utilities.rb', line 44

def content_type_by_name(args = { }, options = { })
  # return args.map { |a| content_type_by_name(a, options) } if args.is_a?(Array)

  # _args = Requests::BaseRequest.process_parameters([ { :name => :name } ], args)
  _args ||= args
  _name = _args[:name]
  _response = content_types_get
  _results = _response['results']
  _results.find { |ct| ct['name'] == _name }
end

#metadata_by(args = { }, options = { }) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ubiquity/envoi/api/utilities.rb', line 87

def (args = { }, options = { })
  entity = args[:entity] || args[:asset] || args[:project]
   = args[:metadata] || entity['metadata'] || { }
  md_field_type = args[:metadata_field_type] || 'label' # label, id | field_uri

  md_out = { }


  # metadata_fieldset_id = metadata_fieldset['fieldset_id']
   = ['values'] || { }
  # metadata_fieldgroup = metadata_fieldset_values || { }
  # metadata_fieldgroup_id = metadata_fieldgroup['fieldgroup_id']
   = ['values'] || [ ]

  .each do |md_field|
    # md_field_id = md_field['id']
    # md_field_label = md_field['label']
    md_field_value = md_field['value']
    md_field_def = md_field['field']
    # md_field_def_type = md_field_def['type']

    md_field_key = case md_field_type
                     when 'id', 'label'
                       md_field[md_field_type]
                     when 'field_uri'
                       md_field_def['uri']
                   end

    # puts %("#{md_field_id}" => "#{md_field_value}",)
    # md_map[md_field_id] = { md_field_label => { :field_id => md_field_id, :group_id => metadata_fieldgroup_id, :field_type => md_field_def_type } }
    md_out[md_field_key] = md_field_value
  end

  md_out
end