Class: Symgate::Wordlist::Client

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

Overview

client for the Symgate wordlist system

Instance Attribute Summary

Attributes inherited from Client

#account, #data_required_error_retries, #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

#copy_wordlist(src_uuid, dest_uuid: nil, context: nil, name: nil, readonly: nil, src_group: nil, src_user: nil, dest_group: nil, dest_user: nil) ⇒ Object

Copies a wordlist with the specified UUID with optional parameters to specify the destination wordlist UUID, the context, name and readonlyness of the destination wordlist, source and destination group and/or user



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/symgate/wordlist/client.rb', line 72

def copy_wordlist(src_uuid, dest_uuid: nil, context: nil, name: nil, readonly: nil,
                  src_group: nil, src_user: nil, dest_group: nil, dest_user: nil)
  response = savon_request(:copy_wordlist) do |soap|
    params = { srcwordlistuuid: src_uuid }
    params[:dstwordlistuuid] = dest_uuid unless dest_uuid.nil?
    params[:context] = context unless context.nil?
    params[:name] = name unless name.nil?
    params[:readonly] = readonly unless readonly.nil?
    params[:srcgroup] = src_group unless src_group.nil?
    params[:srcusername] = src_user unless src_user.nil?
    params[:dstgroup] = dest_group unless dest_group.nil?
    params[:dstusername] = dest_user unless dest_user.nil?
    soap.message(params)
  end

  Symgate::Wordlist::Info.from_soap(
    response.body[:copy_wordlist_response][:wordlistinfo]
  )
end

#create_wordlist(name, context, entries = [], readonly: false) ⇒ 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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/symgate/wordlist/client.rb', line 30

def create_wordlist(name, context, entries = [], readonly: false)
  tries ||= 3 # TODO: Find out if we still need to do this!

  Symgate::Wordlist::Info.from_soap(
    savon_request(:create_wordlist) do |soap|
      soap.message(soap_params_for_create_wordlist(name, context, readonly, 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 extracting 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, readonly: false) ⇒ 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



157
158
159
160
161
162
163
164
# File 'lib/symgate/wordlist/client.rb', line 157

def create_wordlist_from_cfwl_data(raw_cfwl_data, context, preserve_uuid, readonly: false)
  savon_request(:create_wordlist_from_cfwl_data) do |soap|
    soap.message(cfwl: Base64.encode64(raw_cfwl_data),
                 context: context,
                 preserve_uuid: preserve_uuid,
                 readonly: readonly)
  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



49
50
51
52
53
54
55
56
57
# File 'lib/symgate/wordlist/client.rb', line 49

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.message(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])



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/symgate/wordlist/client.rb', line 16

def enumerate_wordlists(context = [])
  response = savon_request(:enumerate_wordlists) do |soap|
    soap.message(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



147
148
149
150
151
152
153
# File 'lib/symgate/wordlist/client.rb', line 147

def get_wordlist_as_cfwl_data(uuid)
  Base64.decode64(
    savon_request(:get_wordlist_as_cfwl_data) do |soap|
      soap.message(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


97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/symgate/wordlist/client.rb', line 97

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.message(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



60
61
62
63
64
65
66
67
68
# File 'lib/symgate/wordlist/client.rb', line 60

def get_wordlist_info(uuid)
  response = savon_request(:get_wordlist_info) do |soap|
    soap.message(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



113
114
115
116
117
118
119
120
121
# File 'lib/symgate/wordlist/client.rb', line 113

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.message(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’



124
125
126
127
128
129
130
# File 'lib/symgate/wordlist/client.rb', line 124

def overwrite_wordlist(uuid, entries)
  check_array_for_type(entries, Symgate::Wordlist::Entry)

  savon_request(:overwrite_wordlist, returns_error_string: true) do |soap|
    soap.message(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



133
134
135
136
137
# File 'lib/symgate/wordlist/client.rb', line 133

def remove_wordlist_entry(uuid, entry_uuid)
  savon_request(:remove_wordlist_entry, returns_error_string: true) do |soap|
    soap.message(wordlistid: uuid, entryid: entry_uuid)
  end
end

#rename_wordlist(uuid, name) ⇒ Object

renames the wordlist specified by its uuid, to the name requested



140
141
142
143
144
# File 'lib/symgate/wordlist/client.rb', line 140

def rename_wordlist(uuid, name)
  savon_request(:rename_wordlist, returns_error_string: true) do |soap|
    soap.message(wordlistid: uuid, name: name)
  end
end