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

#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



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 = [])
  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, 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



135
136
137
138
139
140
141
# File 'lib/symgate/wordlist/client.rb', line 135

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



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



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

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


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

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



91
92
93
94
95
96
97
98
99
# File 'lib/symgate/wordlist/client.rb', line 91

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'



102
103
104
105
106
107
108
# File 'lib/symgate/wordlist/client.rb', line 102

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



111
112
113
114
115
# File 'lib/symgate/wordlist/client.rb', line 111

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



118
119
120
121
122
# File 'lib/symgate/wordlist/client.rb', line 118

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