Class: Viewpoint::EWS::SOAP::EwsParser

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/soap/handsoap/parsers/ews_parser.rb

Instance Method Summary collapse

Methods included from Parser

#initialize, #parse

Instance Method Details

#contact(contact_xml) ⇒ Object



212
213
214
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 212

def contact(contact_xml)
  xml_to_hash!(contact_xml.native_element)
end

#copy_item_response(opts) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 118

def copy_item_response(opts)
  if(@response_message.status == 'Success')
    @response_message.items << xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:Items/*").first.native_element)
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#create_attachment_response(opts) ⇒ Object



176
177
178
179
180
181
182
183
184
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 176

def create_attachment_response(opts)
  if(@response_message.status == 'Success')
    att_id = (@response/"//#{NS_EWS_TYPES}:FileAttachment/*").last
    att_id = xml_to_hash!(att_id.native_element)
    @response_message.items = [att_id]
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#create_folder_response(opts) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 44

def create_folder_response(opts)
  if(@response_message.status == 'Success')
    folders = []
    (@response/"//#{NS_EWS_MESSAGES}:Folders/*").each do |f|
      folders << xml_to_hash!(f.native_element)
    end
    @response_message.items = folders
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#create_item_response(opts) ⇒ Object

TODO:

need to find out out to us XPath to get ItemId. It doesn’t seem to work now.



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 135

def create_item_response(opts)
  if(@response_message.status == 'Success')
    items = []
    (@response/"//#{NS_EWS_MESSAGES}:Items/*").each do |i|
      items << xml_to_hash!(i.native_element)
    end
    @response_message.items = items
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#delete_folder_response(opts) ⇒ Object

Raises:



56
57
58
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 56

def delete_folder_response(opts)
  raise EwsError, "#{@response_message.code}: #{@response_message.message}" unless @response_message.status == 'Success'
end

#find_folder_response(opts) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 36

def find_folder_response(opts)
  folders = []
  (@response/"//#{NS_EWS_MESSAGES}:FindFolderResponseMessage//#{NS_EWS_TYPES}:Folders/*").each do |f|
    folders << xml_to_hash!(f.native_element)
  end
  @response_message.items = folders
end

#find_item_response(opts) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 78

def find_item_response(opts)
  items = []
  items << {}
  items.first[:total_items_in_view] = (@response/"//#{NS_EWS_MESSAGES}:FindItemResponseMessage/#{NS_EWS_MESSAGES}:RootFolder/@TotalItemsInView").first.to_i

  (@response/"//#{NS_EWS_MESSAGES}:FindItemResponseMessage//#{NS_EWS_TYPES}:Items/*").each do |i|
    items << xml_to_hash!(i.native_element)
  end

  @response_message.items = items
end

#foldersObject



228
229
230
231
232
233
234
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 228

def folders
  folders = []
  (@response/"//#{NS_EWS_MESSAGES}:Folders/*").each do |f|
    folders << xml_to_hash!(f.native_element)
  end
  folders
end

#get_attachment_response(opts) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 163

def get_attachment_response(opts)
  atts = []
  if(@response_message.status == 'Success')
    att_id = (@response/"//#{NS_EWS_MESSAGES}:Attachments/*").each do |a|
      atts << xml_to_hash!(a.native_element)
    end
    @response_message.items = atts
    #@response_message.items = @response
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#get_events_response(opts) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 60

def get_events_response(opts)
  if @response_message.status == 'Success'
    events = []
    events << {}
    events.first[:subscription_id] = (@response/"//#{NS_EWS_MESSAGES}:Notification/#{NS_EWS_TYPES}:SubscriptionId").first.to_s
    events.first[:more_events] = (@response/"//#{NS_EWS_MESSAGES}:Notification/#{NS_EWS_TYPES}:SubscriptionId").first.to_boolean

    (@response/"//#{NS_EWS_MESSAGES}:Notification/*[position()>3]").each do |e|
      events << xml_to_hash!(e.native_element)
      events.first[:watermark] = events.last[events.last.keys.first][:watermark][:text]
    end

    @response_message.items = events
  else
    raise EwsSubscriptionTimeout.new("#{@response_message.code}: #{@response_message.message}")
  end
end

#get_folder_response(opts) ⇒ Object



32
33
34
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 32

def get_folder_response(opts)
  @response_message.items = folders
end

#get_item_response(opts) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 108

def get_item_response(opts)
  if(@response_message.status == 'Success')
    (@response/"//#{NS_EWS_MESSAGES}:Items/*").each do |item|
      @response_message.items << xml_to_hash!(item.native_element)
    end
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#get_user_oof_settings_response(opts) ⇒ Object



201
202
203
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 201

def get_user_oof_settings_response(opts)
  @response_message.items = xml_to_hash!((@response/"//#{NS_EWS_TYPES}:OofSettings").first.native_element)
end

#mailbox(mbox_xml) ⇒ Hash

Parse out a Mailbox element

Parameters:

  • mbox (XML)

    The <t:Mailbox> element

Returns:

  • (Hash)

    Values of EWS Mailbox type :name, :email_address, :routing_type, :mailbox_type, :item_id



208
209
210
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 208

def mailbox(mbox_xml)
  xml_to_hash!(mbox_xml.native_element)
end

#move_item_response(opts) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 126

def move_item_response(opts)
  if(@response_message.status == 'Success')
    @response_message.items << xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:Items/*").first.native_element)
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#resolution_setArray

Parse out Resolutions from a ResolutionSet from the ResolveNames operation

Returns:

  • (Array)

    An array of :mailbox,:contact Hashes that resolved.



218
219
220
221
222
223
224
225
226
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 218

def resolution_set
  resolution_set = []
  (@response/"//#{NS_EWS_MESSAGES}:ResolutionSet/*").each do |r|
    mbox_hash    = mailbox((r/"#{NS_EWS_TYPES}:Mailbox").first)
    contact_hash = contact((r/"#{NS_EWS_TYPES}:Contact").first)
    resolution_set << mbox_hash.merge(contact_hash)
  end
  resolution_set
end

#resolve_names_response(opts) ⇒ Object

Parsing Methods




28
29
30
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 28

def resolve_names_response(opts)
  @response_message.items = resolution_set
end

#send_item_response(opts) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 151

def send_item_response(opts)
  if(@response_message.status == 'Success')
    items = []
    (@response/"//#{NS_EWS_MESSAGES}:Items/*").each do |i|
      items << xml_to_hash!(i.native_element)
    end
    @response_message.items = items
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#subscribe_response(opts) ⇒ Hash

Parsers the response from the SOAP Subscribe operation

Returns:

  • (Hash)

    A hash with the keys :watermark and :subscription_id

Raises:

  • (EwsError)

    Raise an error if the ResponseClass is not Success

See Also:



95
96
97
98
99
100
101
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 95

def subscribe_response(opts)
  subscription = []
  sid = xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:SubscriptionId").first.native_element)
  wmk = xml_to_hash!((@response/"//#{NS_EWS_MESSAGES}:Watermark").first.native_element)
  subscription << sid.merge(wmk)
  @response_message.items = subscription
end

#sync_folder_items_response(opts) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 186

def sync_folder_items_response(opts)
  if(@response_message.status == 'Success')
    sync = []
    sync << {}
    sync.first[:sync_state] = (@response/"//#{NS_EWS_MESSAGES}:SyncState").first.to_s
    sync.first[:includes_last_item_in_range] = (@response/"//#{NS_EWS_MESSAGES}:IncludesLastItemInRange").first.to_boolean
    (@response/"//m:Changes/*").each do |c|
      sync << xml_to_hash!(c.native_element)
    end
    @response_message.items = sync
  else
    raise EwsError, "#{@response_message.code}: #{@response_message.message}"
  end
end

#unsubscribe_response(opts) ⇒ Object

TODO:

Better handle error messages



104
105
106
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 104

def unsubscribe_response(opts)
  @response_message
end

#update_item_response(opts) ⇒ Object



147
148
149
# File 'lib/soap/handsoap/parsers/ews_parser.rb', line 147

def update_item_response(opts)
  create_item_response(opts)
end