Class: ResourceSpace::Metadata
- Inherits:
-
Object
- Object
- ResourceSpace::Metadata
- Defined in:
- lib/resourcespace/metadata.rb
Overview
Metadata management interface for ResourceSpace API
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
The ResourceSpace client.
Instance Method Summary collapse
-
#add_resource_nodes(resource_id, field_id, node_ids) ⇒ Hash
Add resource nodes (multiple field values).
-
#add_resource_nodes_multi(resource_id, field_data) ⇒ Hash
Add resource nodes for multiple fields.
-
#create_resource_type_field(name:, type:, resource_types: [1], **options) ⇒ Hash
Create a new resource type field.
-
#create_web_asset_fields(resource_types: [1]) ⇒ Array
Create web asset metadata fields.
-
#get_field_options(field_id, node_info: false) ⇒ Array
Get field options for dropdown/checkbox fields.
-
#get_node_id(field_id, value) ⇒ Integer
Get node ID for a field value.
-
#get_nodes(field_id) ⇒ Array
Get all nodes for a field.
-
#get_resource_type_fields(resource_type = nil) ⇒ Array
Get resource type fields.
-
#initialize(client) ⇒ Metadata
constructor
Initialize the metadata interface.
-
#set_node(field_id, value, return_existing: true) ⇒ Integer
Set/create a node value.
-
#toggle_active_state_for_nodes(field_id, node_ids, active: true) ⇒ Hash
Toggle active state for nodes.
-
#update_field(field_id, properties = {}) ⇒ Hash
Update a field definition.
-
#update_web_asset_metadata(resource_id, metadata = {}) ⇒ Array
Update resource with web asset metadata.
-
#web_asset_schema ⇒ Hash
Get metadata schema for web assets.
Constructor Details
#initialize(client) ⇒ Metadata
Initialize the metadata interface
24 25 26 |
# File 'lib/resourcespace/metadata.rb', line 24 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Client (readonly)
Returns the ResourceSpace client.
19 20 21 |
# File 'lib/resourcespace/metadata.rb', line 19 def client @client end |
Instance Method Details
#add_resource_nodes(resource_id, field_id, node_ids) ⇒ Hash
Add resource nodes (multiple field values)
84 85 86 87 88 89 90 91 92 |
# File 'lib/resourcespace/metadata.rb', line 84 def add_resource_nodes(resource_id, field_id, node_ids) node_ids_str = Array(node_ids).join(",") client.post("add_resource_nodes", { param1: resource_id.to_s, param2: field_id.to_s, param3: node_ids_str }) end |
#add_resource_nodes_multi(resource_id, field_data) ⇒ Hash
Add resource nodes for multiple fields
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/resourcespace/metadata.rb', line 99 def add_resource_nodes_multi(resource_id, field_data) # Convert field_data to the format expected by the API # This might need adjustment based on the exact API format params = { param1: resource_id.to_s } field_data.each_with_index do |(field_id, node_ids), index| node_ids_str = Array(node_ids).join(",") params["param#{index + 2}"] = "#{field_id}:#{node_ids_str}" end client.post("add_resource_nodes_multi", params) end |
#create_resource_type_field(name:, type:, resource_types: [1], **options) ⇒ Hash
Create a new resource type field
146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/resourcespace/metadata.rb', line 146 def create_resource_type_field(name:, type:, resource_types: [1], **) params = { param1: name, param2: type, param3: Array(resource_types).join(",") } # Add additional options .each_with_index do |(key, value), index| params["param#{index + 4}"] = "#{key}:#{value}" end client.post("create_resource_type_field", params) end |
#create_web_asset_fields(resource_types: [1]) ⇒ Array
Create web asset metadata fields
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/resourcespace/metadata.rb', line 198 def create_web_asset_fields(resource_types: [1]) fields_to_create = [ { name: "Web Asset Type", type: "dropdown", options: ["Image", "CSS", "JavaScript", "Font", "Icon", "Video", "Audio"] }, { name: "Usage Rights", type: "dropdown", options: ["Public Domain", "Creative Commons", "Licensed", "Proprietary"] }, { name: "Dimensions", type: "text", description: "Width x Height (e.g., 1920x1080)" }, { name: "File Size", type: "text", description: "File size in bytes/KB/MB" }, { name: "Compression", type: "dropdown", options: ["None", "Lossless", "Lossy", "Optimized"] }, { name: "Color Profile", type: "dropdown", options: ["sRGB", "Adobe RGB", "ProPhoto RGB", "CMYK", "Grayscale"] }, { name: "Purpose/Context", type: "text", description: "Intended use or context for this asset" } ] created_fields = [] fields_to_create.each do |field_data| = field_data.dup name = .delete(:name) type = .delete(:type) created_field = create_resource_type_field( name: name, type: type, resource_types: resource_types, ** ) created_fields << created_field end created_fields end |
#get_field_options(field_id, node_info: false) ⇒ Array
Get field options for dropdown/checkbox fields
33 34 35 36 37 38 |
# File 'lib/resourcespace/metadata.rb', line 33 def (field_id, node_info: false) params = { param1: field_id.to_s } params[:param2] = node_info ? "true" : "false" client.get("get_field_options", params) end |
#get_node_id(field_id, value) ⇒ Integer
Get node ID for a field value
45 46 47 48 49 50 51 |
# File 'lib/resourcespace/metadata.rb', line 45 def get_node_id(field_id, value) response = client.get("get_node_id", { param1: field_id.to_s, param2: value }) response.to_i end |
#get_nodes(field_id) ⇒ Array
Get all nodes for a field
57 58 59 |
# File 'lib/resourcespace/metadata.rb', line 57 def get_nodes(field_id) client.get("get_nodes", { param1: field_id.to_s }) end |
#get_resource_type_fields(resource_type = nil) ⇒ Array
Get resource type fields
132 133 134 135 136 137 |
# File 'lib/resourcespace/metadata.rb', line 132 def get_resource_type_fields(resource_type = nil) params = {} params[:param1] = resource_type.to_s if resource_type client.get("get_resource_type_fields", params) end |
#set_node(field_id, value, return_existing: true) ⇒ Integer
Set/create a node value
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/resourcespace/metadata.rb', line 67 def set_node(field_id, value, return_existing: true) params = { param1: field_id.to_s, param2: value } params[:param3] = return_existing ? "true" : "false" response = client.post("set_node", params) response.to_i end |
#toggle_active_state_for_nodes(field_id, node_ids, active: true) ⇒ Hash
Toggle active state for nodes
167 168 169 170 171 172 173 174 175 |
# File 'lib/resourcespace/metadata.rb', line 167 def toggle_active_state_for_nodes(field_id, node_ids, active: true) node_ids_str = Array(node_ids).join(",") client.post("toggle_active_state_for_nodes", { param1: field_id.to_s, param2: node_ids_str, param3: active ? "1" : "0" }) end |
#update_field(field_id, properties = {}) ⇒ Hash
Update a field definition
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/resourcespace/metadata.rb', line 117 def update_field(field_id, properties = {}) params = { param1: field_id.to_s } # Add properties as additional parameters properties.each_with_index do |(key, value), index| params["param#{index + 2}"] = "#{key}:#{value}" end client.post("update_field", params) end |
#update_web_asset_metadata(resource_id, metadata = {}) ⇒ Array
Update resource with web asset metadata
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/resourcespace/metadata.rb', line 260 def (resource_id, = {}) updates = [] schema = web_asset_schema .each do |field_name, value| field_id = case field_name.to_s.downcase when "title", "name" 8 when "keywords", "tags" 12 when "asset_type", "type" 51 when "usage_rights", "rights", "license" 52 when "dimensions", "size" 53 when "file_size" 54 when "compression" 55 when "color_profile", "color" 56 when "purpose", "context", "description" 57 else field_name.to_i if field_name.to_s.match?(/^\d+$/) end if field_id update_response = client.resources.update_field(resource_id, field_id, value.to_s) updates << { field_id: field_id, field_name: field_name, response: update_response } end end updates end |
#web_asset_schema ⇒ Hash
Get metadata schema for web assets
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/resourcespace/metadata.rb', line 180 def web_asset_schema { 8 => "Title/Name", 12 => "Keywords/Tags", 51 => "Asset Type", # Custom field for web asset type 52 => "Usage Rights", # Custom field for usage/license 53 => "Dimensions", # Custom field for dimensions 54 => "File Size", # Custom field for file size 55 => "Compression", # Custom field for compression type 56 => "Color Profile", # Custom field for color profile 57 => "Purpose/Context" # Custom field for intended use } end |