Class: Symgate::Wordlist::Client
- Defined in:
- lib/symgate/wordlist/client.rb
Overview
client for the Symgate wordlist system
Instance Attribute Summary
Attributes inherited from Client
#account, #endpoint, #key, #password, #savon_client, #savon_opts, #token, #user, #wsdl
Instance Method Summary collapse
-
#create_wordlist(name, context, entries = []) ⇒ Object
creates a wordlist with the specified name, context and scope (see auth:scope).
-
#create_wordlist_from_cfwl_data(raw_cfwl_data, context, preserve_uuid) ⇒ Object
creates a wordlist from the supplied cfwl data, in the requested context if ‘preserve_uuid’ is true, the new wordlist will have the same uuid as the file.
-
#destroy_wordlist(uuid) ⇒ Object
destroys a wordlist with the specified uuid.
-
#enumerate_wordlists(context = []) ⇒ Object
returns a list of wordlists available to the current user.
-
#get_wordlist_as_cfwl_data(uuid) ⇒ Object
gets the cfwl-format data for the specified wordlist.
-
#get_wordlist_entries(uuid, opts = {}) ⇒ Object
returns all wordlist entries for the wordlist specified by uuid.
-
#get_wordlist_info(uuid) ⇒ Object
returns the information for the wordlist identified by the specified uuid.
-
#insert_wordlist_entry(uuid, entry) ⇒ Object
inserts an entry into a wordlist, specified by the wordlist uuid.
-
#overwrite_wordlist(uuid, entries) ⇒ Object
overwrites a wordlist with the wordlist contents specified by ‘entries’.
-
#remove_wordlist_entry(uuid, entry_uuid) ⇒ Object
removes the wordlist entry specified by entry_uuid, from the wordlist specified by uuid.
-
#rename_wordlist(uuid, name) ⇒ Object
renames the wordlist specified by its uuid, to the name requested.
Methods inherited from Client
Constructor Details
This class inherits a constructor from Symgate::Client
Instance Method Details
#create_wordlist(name, context, entries = []) ⇒ Object
creates a wordlist with the specified name, context and scope (see auth:scope). optionally, supply a list of entries to form the wordlist’s initial content
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/symgate/wordlist/client.rb', line 29 def create_wordlist(name, context, entries = []) tries ||= 3 # TODO: Find out if we still need to do this! Symgate::Wordlist::Info.from_soap( savon_request(:create_wordlist) do |soap| soap.(soap_params_for_create_wordlist(name, context, entries)) end.body[:create_wordlist_response][:wordlistinfo] ) rescue Symgate::Error => e # Handle SOS-105 (sometimes the wordlist is created but the symboliser claims it can't # find it and sends a SOAP error back) by extract the wordlist UUID from the error message. # Yes, this is not nice. match = /^No wordlist found for ID: ({[0-9a-f-]{36}})$/.match(e.detail) return get_wordlist_info(match[1]) if match (tries -= 1).zero? ? raise(e) : retry end |
#create_wordlist_from_cfwl_data(raw_cfwl_data, context, preserve_uuid) ⇒ Object
creates a wordlist from the supplied cfwl data, in the requested context if ‘preserve_uuid’ is true, the new wordlist will have the same uuid as the file
134 135 136 137 138 139 140 |
# File 'lib/symgate/wordlist/client.rb', line 134 def create_wordlist_from_cfwl_data(raw_cfwl_data, context, preserve_uuid) savon_request(:create_wordlist_from_cfwl_data) do |soap| soap.(cfwl: Base64.encode64(raw_cfwl_data), context: context, preserve_uuid: preserve_uuid) end.body[:create_wordlist_from_cfwl_data_response][:uuid] end |
#destroy_wordlist(uuid) ⇒ Object
destroys a wordlist with the specified uuid. throws an error on failure
48 49 50 51 52 53 54 55 56 |
# File 'lib/symgate/wordlist/client.rb', line 48 def destroy_wordlist(uuid) tries ||= 3 # TODO: Find out if we still need to do this! savon_request(:destroy_wordlist, returns_error_string: true) do |soap| soap.(wordlistid: uuid) end rescue Symgate::Error => e (tries -= 1).zero? ? raise(e) : retry end |
#enumerate_wordlists(context = []) ⇒ Object
returns a list of wordlists available to the current user. optionally, supply one or more wordlist contexts as a string or string array parameter to only retrieve wordlist information about that context. e.g.: enumerate_wordlists(‘User’) enumerate_wordlists(%w(Topic SymbolSet))
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/symgate/wordlist/client.rb', line 15 def enumerate_wordlists(context = []) response = savon_request(:enumerate_wordlists) do |soap| soap.(context: [context].flatten) end Symgate::Client.savon_array( response.body[:enumerate_wordlists_response], :wordlistinfo, Symgate::Wordlist::Info ) end |
#get_wordlist_as_cfwl_data(uuid) ⇒ Object
gets the cfwl-format data for the specified wordlist
124 125 126 127 128 129 130 |
# File 'lib/symgate/wordlist/client.rb', line 124 def get_wordlist_as_cfwl_data(uuid) Base64.decode64( savon_request(:get_wordlist_as_cfwl_data) do |soap| soap.(wordlistid: uuid) end.body[:get_wordlist_as_cfwl_data_response][:cfwl] ) end |
#get_wordlist_entries(uuid, opts = {}) ⇒ Object
returns all wordlist entries for the wordlist specified by uuid. accepts the following optional parameters:
attachments (boolean) - fetch custom graphics for the entries (default: false)
match (string) - only return wordlist entries matching this word
entry (string, uuid) - return the entry specified by the uuid
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/symgate/wordlist/client.rb', line 74 def get_wordlist_entries(uuid, opts = {}) check_for_unknown_opts(%i(match entry attachments), opts) check_for_multiple_opts(%i(match entry), opts) response = savon_request(:get_wordlist_entries) do |soap| soap.(wordlistid: uuid, getattachments: opts[:attachments]) soap[:message][:match] = { matchstring: opts[:match] } if opts.include? :match soap[:message][:match] = { entryid: opts[:entry] } if opts.include? :entry end Symgate::Client.savon_array(response.body[:get_wordlist_entries_response], :wordlistentry, Symgate::Wordlist::Entry) end |
#get_wordlist_info(uuid) ⇒ Object
returns the information for the wordlist identified by the specified uuid
59 60 61 62 63 64 65 66 67 |
# File 'lib/symgate/wordlist/client.rb', line 59 def get_wordlist_info(uuid) response = savon_request(:get_wordlist_info) do |soap| soap.(wordlistid: uuid) end Symgate::Wordlist::Info.from_soap( response.body[:get_wordlist_info_response][:wordlistinfo] ) end |
#insert_wordlist_entry(uuid, entry) ⇒ Object
inserts an entry into a wordlist, specified by the wordlist uuid
90 91 92 93 94 95 96 97 98 |
# File 'lib/symgate/wordlist/client.rb', line 90 def insert_wordlist_entry(uuid, entry) unless entry.is_a? Symgate::Wordlist::Entry raise Symgate::Error, 'Please supply a Symgate::Wordlist::Entry to insert' end savon_request(:insert_wordlist_entry, returns_error_string: true) do |soap| soap.(wordlistid: uuid, %s(wl:wordlistentry) => entry.to_soap) end end |
#overwrite_wordlist(uuid, entries) ⇒ Object
overwrites a wordlist with the wordlist contents specified by ‘entries’
101 102 103 104 105 106 107 |
# File 'lib/symgate/wordlist/client.rb', line 101 def overwrite_wordlist(uuid, entries) check_array_for_type(entries, Symgate::Wordlist::Entry) savon_request(:overwrite_wordlist, returns_error_string: true) do |soap| soap.(wordlistid: uuid, %s(wl:wordlistentry) => entries.map(&:to_soap)) end end |
#remove_wordlist_entry(uuid, entry_uuid) ⇒ Object
removes the wordlist entry specified by entry_uuid, from the wordlist specified by uuid
110 111 112 113 114 |
# File 'lib/symgate/wordlist/client.rb', line 110 def remove_wordlist_entry(uuid, entry_uuid) savon_request(:remove_wordlist_entry, returns_error_string: true) do |soap| soap.(wordlistid: uuid, entryid: entry_uuid) end end |
#rename_wordlist(uuid, name) ⇒ Object
renames the wordlist specified by its uuid, to the name requested
117 118 119 120 121 |
# File 'lib/symgate/wordlist/client.rb', line 117 def rename_wordlist(uuid, name) savon_request(:rename_wordlist, returns_error_string: true) do |soap| soap.(wordlistid: uuid, name: name) end end |