Class: Symgate::Metadata::Client

Inherits:
Client
  • Object
show all
Defined in:
lib/symgate/metadata/client.rb

Overview

client for the Symgate metadata system

Instance Attribute Summary

Attributes inherited from Client

#account, #endpoint, #key, #password, #savon_client, #savon_opts, #token, #user, #wsdl

Instance Method Summary collapse

Methods inherited from Client

#initialize, savon_array

Constructor Details

This class inherits a constructor from Symgate::Client

Instance Method Details

#destroy_metadata(scope, keys) ⇒ Object

Destroys one or more metadata items on the specified scope, specified by their key(s). Specify a valid scope and a single string, or an array of strings.

Raises:



53
54
55
56
57
58
59
60
61
# File 'lib/symgate/metadata/client.rb', line 53

def (scope, keys)
  k = [keys].flatten
  check_array_for_type(k, String)
  raise Symgate::Error, 'No keys supplied' if k.empty?

  savon_request(:destroy_metadata, returns_error_string: true) do |soap|
    soap.message(scope: scope, key: k)
  end
end

#get_metadata(opts = {}) ⇒ Object

Gets metadata visible to the current user.

If the 'scope' option is specified, this will list only the metadata defined at a particular scope. Otherwise it will list metadata items visible, with user metadata replacing group metadata and so on.

If the 'keys' option is specified, this will list only the metadata matching the list of keys supplied.

The 'key' option is also provided as a convenience, which works as above for a single item.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/symgate/metadata/client.rb', line 22

def (opts = {})
  o = opts
   o
  o[:key] = o.delete(:keys) if o.include? :keys

  resp = savon_request(:get_metadata) { |soap| soap.message(o) }

  Symgate::Client.savon_array(
    resp.body[:get_metadata_response],
    :data_item,
    Symgate::Metadata::DataItem
  )
end

#set_metadata(items) ⇒ Object

Creates one or more metadata items, overwriting any that match the key and scope specified within the DataItem object. Supply either a single item or an array of items.

Raises:



39
40
41
42
43
44
45
46
47
48
# File 'lib/symgate/metadata/client.rb', line 39

def (items)
  i = [items].flatten

  check_array_for_type(i, Symgate::Metadata::DataItem)
  raise Symgate::Error, 'No items supplied' if i.empty?

  savon_request(:set_metadata, returns_error_string: true) do |soap|
    soap.message(%s(auth:data_item) => i.map(&:to_soap))
  end
end