Class: Ubiquity::Iconik::API::Utilities
- Defined in:
- lib/ubiquity/iconik/api/utilities.rb
Instance Attribute Summary
Attributes inherited from Client
#http_client, #logger, #request, #response
Instance Method Summary collapse
- #asset_add_using_file_path(args = {}, options = {}) ⇒ Hash
- #asset_metadata_set_extended(args = {}, options = {}) ⇒ Hash
-
#symbolize_keys(value, recursive = true) ⇒ Object
Converts hash keys to symbols.
Methods inherited from Client
#asset_analyze, #asset_create, #asset_delete, #asset_download_url_get, #asset_file_create, #asset_file_get, #asset_file_keyframes_create, #asset_file_set_create, #asset_file_update, #asset_files_get, #asset_format_create, #asset_format_file_sets_get, #asset_format_file_sets_sources_get, #asset_format_get_by_name, #asset_formats_get, #asset_keyframes_get, #asset_metadata_set, #assets_get, #assets_reindex, #auth_login_simple, #auth_token_get, #auth_token_refresh, #collection_content_add, #collection_contents_get, #collection_create, #collection_delete, #collection_get, #collection_replace, #collection_update, #collections_get, #collections_reindex, #error, #file_set_files_get, #http, #initialize, #metadata_field_create, #paginator, #process_request, #process_request_using_class, #storage_create, #storage_files_get, #storages_get, #success?, #token, #token=, #transcode
Constructor Details
This class inherits a constructor from Ubiquity::Iconik::API::Client
Instance Method Details
#asset_add_using_file_path(args = {}, options = {}) ⇒ Hash
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 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 86 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ubiquity/iconik/api/utilities.rb', line 38 def asset_add_using_file_path(args = {}, = {}) _args = symbolize_keys(args, false) create_keyframes = _args.fetch(:create_keyframes, true) file_path = _args[:file_path] raise ArgumentError, ':file_path is a required argument.' unless file_path file_dir = File.dirname(file_path) if file_dir == '.' file_dir = '' elsif file_dir.start_with?('./') file_dir = file_dir[2..-1] elsif file_dir.start_with?('/') file_dir = file_dir[1..-1] end file_name = File.basename(file_path) file_size = _args[:file_size] || 1024 file_type = 'FILE' = _args[:metadata] # Determine Storage storage_id = _args[:storage_id] raise ArgumentError, ':storage_id is a required argument.' unless storage_id asset_id = _args[:asset_id] unless asset_id # Create Asset asset_create_args = { :title => file_name } asset = asset_create(asset_create_args) asset_id = asset['id'] raise 'Error Creating Asset.' unless asset_id end format_id = _args[:format_id] unless format_id # Create Asset Format asset_format_create_args = { :asset_id => asset_id } format = asset_format_create(asset_format_create_args) format_id = format['id'] raise 'Error Creating Format.' unless format_id end file_set_id = _args[:file_set_id] unless file_set_id # Create Asset File Set asset_file_set_create_args = { :asset_id => asset_id, :storage_id => storage_id, :format_id => format_id, :name => file_name, :base_dir => file_dir, :component_ids => [], } file_set = asset_file_set_create(asset_file_set_create_args) file_set_id = file_set['id'] raise 'Error Creating File Set.' unless file_set_id end # Create Asset File file_status = _args[:file_status] || 'CLOSED' file_create_and_modify_time = Time.now.to_s asset_file_create_args = { :asset_id => asset_id, :storage_id => storage_id, :format_id => format_id, :file_set_id => file_set_id, :name => file_name, :original_name => file_name, :directory_path => file_dir, :size => file_size, :type => file_type, :status => file_status, :file_date_created => file_create_and_modify_time, :file_date_modified => file_create_and_modify_time, :metadata => {}, } file = asset_file_create(asset_file_create_args) file_id = file['id'] if file.is_a?(Hash) raise "Error Creating File. #{file}" unless file && file_id asset_file_keyframes_create(:asset_id => asset_id, :file_id => file_id) if create_keyframes if unless .empty? [:asset_id] = asset_id = () end end { :asset => asset, :format => format, :file_set => file_set, :file => file, :metadata_set => } end |
#asset_metadata_set_extended(args = {}, options = {}) ⇒ Hash
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/ubiquity/iconik/api/utilities.rb', line 145 def (args = {}, = {}) _args = symbolize_keys(args, false) asset_id = _args[:asset_id] default_view_id = _args[:view_id] = _args[:metadata] responses = {} .each do |view| values_out = {} view_id = view['id'] || view[:id] || default_view_id values = view['metadata_values'] || view[:metadata_values] values.echo do |k, v| values_out[k] = { :field_values => [v] } end args_out = { :asset_id => asset_id, :view_id => view_id, :metadata_values => values_out } r = (args_out, ) responses[view_id] = r end { :responses => responses } end |
#symbolize_keys(value, recursive = true) ⇒ Object
Converts hash keys to symbols
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ubiquity/iconik/api/utilities.rb', line 12 def symbolize_keys (value, recursive = true) case value when Hash new_val = {} value.each { |k, v| k = (k.to_sym rescue k) v = symbolize_keys(v, true) if recursive and (v.is_a? Hash or v.is_a? Array) new_val[k] = v } return new_val when Array return value.map { |v| symbolize_keys(v, true) } else return value end end |