Module: XMLParser

Included in:
AdobeConnectAPI
Defined in:
lib/adobe_connect_api/xml_parser.rb

Overview

This class is a simple utility to parse the result from querying the adobe connect api. All methods accept a String containing XML, that is returned from the AdobeConnectAPI methods. For queries and returned results see the API documentation: help.adobe.com/en_US/connect/8.0/webservices/connect_8_webservices.pdf

Instance Method Summary collapse

Instance Method Details

#get_description(xml) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/adobe_connect_api/xml_parser.rb', line 77

def get_description(xml)
  data = XmlSimple.xml_in(xml)

  if data['sco'].first['description']
    return data['sco'].first['description']
  else
    raise "No description information found."
  end
  return nil
end

#get_folder_id(xml) ⇒ Object

supported actions: ‘sco-contents’ but only with filter-name and the user’s e-mail-address (does not consider multiple sco results) e.g. action=sco-contents&sco-id=11&filter-name=interact-support%40switch.ch



66
67
68
69
70
71
72
73
74
75
# File 'lib/adobe_connect_api/xml_parser.rb', line 66

def get_folder_id(xml)
  data = XmlSimple.xml_in(xml)

  if data['scos']
    return data['scos'].first['sco'].first['sco-id'] unless data['scos'].first.empty?
  else
    raise "XMLParser does not support result of this format. No sco information found."
  end
  return nil
end

#get_invalid_subcode(xml) ⇒ Object

used if the returned status contains an invalid value



18
19
20
21
# File 'lib/adobe_connect_api/xml_parser.rb', line 18

def get_invalid_subcode(xml)
  data = XmlSimple.xml_in(xml)
  data['status'].first['invalid'].first['subcode']
end

#get_language(xml) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/adobe_connect_api/xml_parser.rb', line 88

def get_language(xml)
  data = XmlSimple.xml_in(xml)

  if data['sco'].first['lang']
    data['sco'].first['lang']
  else
    raise "No language information found."
  end
  return nil
end

#get_principal_id(xml) ⇒ Object

supported actions: ‘principal-update’ or ‘principal-list’ NOTE: does not handle more than one result, so use only for ‘principal-list’ that returns a unique result e.g. when querying users by e-mail



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/adobe_connect_api/xml_parser.rb', line 25

def get_principal_id(xml)
  data = XmlSimple.xml_in(xml)
  if data.keys.include?('principal-list')
    return data['principal-list'].first['principal'].first['principal-id'] unless data['principal-list'].first.empty?
  elsif data.keys.include?('principal')
    return data['principal'].first['principal-id']
  else
    raise "XMLParser does not support result of this format. No principal information found."
  end
  return nil
end

#get_sco_id(xml) ⇒ Object

supported actions: ‘sco-update’, ‘sco-info’



38
39
40
41
42
43
44
45
46
# File 'lib/adobe_connect_api/xml_parser.rb', line 38

def get_sco_id(xml)
  data = XmlSimple.xml_in(xml)
  if data['sco']
    return data['sco'].first['sco-id']
  else
    raise "XMLParser does not support result of this format. No sco information found."
  end
  return nil
end

#get_sco_id_for_unique_name(xml, name) ⇒ Object

supported action: ‘sco-search-by-field’ gets the first result that name EXACTLY matches the given name



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/adobe_connect_api/xml_parser.rb', line 50

def get_sco_id_for_unique_name(xml, name)
  data = XmlSimple.xml_in(xml)
  if data['sco-search-by-field-info'] && !data['sco-search-by-field-info'].first.empty?
    data['sco-search-by-field-info'].first['sco'].each do |sco|
      if sco['name'].first == name
        return sco['sco-id']
      else 
        raise "No correct match for name #{name} found"
      end
    end
  end
  return nil
end

#get_status_code(xml) ⇒ Object

used for all actions, e.g. ‘login’ and ‘logout’



12
13
14
15
# File 'lib/adobe_connect_api/xml_parser.rb', line 12

def get_status_code(xml)
  data = XmlSimple.xml_in(xml)
  data['status'].first['code']
end