Class: Viewpoint::SPWS::Websvc::Lists
- Inherits:
-
Object
- Object
- Viewpoint::SPWS::Websvc::Lists
- Includes:
- WebServiceBase
- Defined in:
- lib/viewpoint/spws/websvc/lists.rb
Overview
This class represents the Sharepoint Lists Web Service.
Constant Summary
Constants included from WebServiceBase
Constants included from Viewpoint::SPWS
Instance Attribute Summary
Attributes included from WebServiceBase
Attributes included from Viewpoint::SPWS
Instance Method Summary collapse
-
#add_list(name, desc, templ_id) ⇒ Viewpoint::SPWS::List
Add a List to this site.
-
#add_list_from_feature(name, desc, feature_id, templ_id) ⇒ Viewpoint::SPWS::List
Add a List to this site from a feature ID.
-
#delete_list(name) ⇒ Object
Delete a list from this site.
-
#get_file(file_ref) ⇒ String
Retrieve a file from Sharepoint.
-
#get_list(list) ⇒ Viewpoint::SPWS::List
Retrieve a specific Sharepoint List.
-
#get_list_collection(show_hidden = false) ⇒ Object
Returns all the lists for a Sharepoint site.
-
#get_list_content_types(name, content_type_id = nil) ⇒ Object
Returns a collection of content type definition schemas.
-
#get_list_item_changes_since_token(list, token = nil, opts = {}) {|builder| ... } ⇒ Hash
Get List Items changes from a given change token.
-
#get_list_items(list, opts = {}) {|builder| ... } ⇒ Object
Get List Items based on certain parameters.
-
#initialize(spcon) ⇒ Lists
constructor
A new instance of Lists.
-
#update_list_items(list, updates = {}) {|builder| ... } ⇒ Object
Adds, deletes, or updates the specified items in a list.
Methods included from Viewpoint::SPWS
Constructor Details
#initialize(spcon) ⇒ Lists
Returns a new instance of Lists.
24 25 26 27 28 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 24 def initialize(spcon) @default_ns = 'http://schemas.microsoft.com/sharepoint/soap/' @ws_endpoint = '_vti_bin/Lists.asmx' super end |
Instance Method Details
#add_list(name, desc, templ_id) ⇒ Viewpoint::SPWS::List
Add a List to this site.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 37 def add_list(name, desc, templ_id) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.AddList { builder.parent.default_namespace = @default_ns builder.listName(name) builder.description(desc) builder.templateID(templ_id) } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) return soaprsp ns = {"xmlns"=> @default_ns} new_list(soaprsp.xpath('//xmlns:AddListResult/xmlns:List', ns).first) end |
#add_list_from_feature(name, desc, feature_id, templ_id) ⇒ Viewpoint::SPWS::List
Add a List to this site from a feature ID.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 63 def add_list_from_feature(name, desc, feature_id, templ_id) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.AddListFromFeature { builder.parent.default_namespace = @default_ns builder.listName(name) builder.description(desc) builder.featureID(feature_id) builder.templateID(templ_id) } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) ns = {"xmlns"=> @default_ns} new_list(soaprsp.xpath('//xmlns:AddListResult/xmlns:List', ns).first) end |
#delete_list(name) ⇒ Object
Work out the return value
Delete a list from this site.
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 84 def delete_list(name) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.DeleteList { builder.parent.default_namespace = @default_ns builder.listName(name) } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) #ns = {"xmlns"=> @default_ns} end |
#get_file(file_ref) ⇒ String
Retrieve a file from Sharepoint. This is not a standard Web Service method, buth rather a convenience method that is part of ViewpointSPWS.
426 427 428 429 430 431 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 426 def get_file(file_ref) p1 = Pathname.new @spcon.site_base.request_uri p2 = Pathname.new "/#{file_ref}" target = p2.relative_path_from p1 @spcon.get(target.to_s) end |
#get_list(list) ⇒ Viewpoint::SPWS::List
Retrieve a specific Sharepoint List
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 148 def get_list(list) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.GetList { builder.parent.default_namespace = @default_ns builder.listName(list) } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) ns = {"xmlns"=> @default_ns} new_list(soaprsp.xpath('//xmlns:GetListResult/xmlns:List', ns).first) end |
#get_list_collection(show_hidden = false) ⇒ Object
Returns all the lists for a Sharepoint site.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 121 def get_list_collection(show_hidden = false) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.GetListCollection { builder.parent.default_namespace = @default_ns } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) ns = {"xmlns"=> @default_ns} lists = [] soaprsp.xpath('//xmlns:Lists/xmlns:List', ns).each do |l| lists << new_list(l) end if(!show_hidden) lists.reject! do |i| i.hidden? end end lists end |
#get_list_content_types(name, content_type_id = nil) ⇒ Object
Work out the return value
Returns a collection of content type definition schemas
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 104 def get_list_content_types(name, content_type_id = nil) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.GetListContentTypes { builder.parent.default_namespace = @default_ns builder.listName(name) builder.contentTypeId(content_type_id) } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) end |
#get_list_item_changes_since_token(list, token = nil, opts = {}) {|builder| ... } ⇒ Hash
Get List Items changes from a given change token
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 277 def get_list_item_changes_since_token(list, token=nil, opts = {}) # Set Default values opts[:recursive] = true unless opts.has_key?(:recursive) opts[:view_name] = '' unless opts.has_key?(:view_name) opts[:row_limit] = '' unless opts.has_key?(:row_limit) opts[:date_in_utc] = true unless opts.has_key?(:date_in_utc) opts[:folder] = '' unless opts.has_key?(:folder) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.GetListItemChangesSinceToken { builder.parent.default_namespace = @default_ns builder.listName(list) builder.viewName(opts[:view_name]) builder.rowLimit(opts[:row_limit]) if block_given? builder.query { builder.parent.default_namespace = '' yield builder } end builder.queryOptions { builder.QueryOptions { builder.parent.default_namespace = '' builder.Folder(opts[:folder]) builder.ViewAttributes(:Scope => 'Recursive') if opts[:recursive] builder.DateInUtc('True') if opts[:date_in_utc] builder.IncludeAttachmentUrls('True') } } builder.changeToken(token) # @todo Is this worth supporting??? #builder.contains() } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) ns = {'xmlns:z' => "#RowsetSchema", 'xmlns:rs' => "urn:schemas-microsoft-com:rowset", 'xmlns' => @default_ns, } items = [] soaprsp.xpath('//rs:data/z:row', ns).each do |li| items << Types::ListItem.new(self, list, li) end changes = soaprsp.xpath('//xmlns:GetListItemChangesSinceTokenResult/xmlns:listitems/xmlns:Changes',ns).first {:last_change_token => changes['LastChangeToken'], :items => items} end |
#get_list_items(list, opts = {}) {|builder| ... } ⇒ Object
Get List Items based on certain parameters
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 190 def get_list_items(list, opts = {}) # Set Default values opts[:recursive] = true unless opts.has_key?(:recursive) opts[:view_name] = '' unless opts.has_key?(:view_name) opts[:row_limit] = '' unless opts.has_key?(:row_limit) opts[:date_in_utc] = true unless opts.has_key?(:date_in_utc) opts[:folder] = '' unless opts.has_key?(:folder) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.GetListItems { builder.parent.default_namespace = @default_ns builder.listName(list) builder.viewName(opts[:view_name]) builder.rowLimit(opts[:row_limit]) if block_given? builder.query { builder.parent.default_namespace = '' yield builder } end if(opts[:view_fields]) builder.viewFields { builder.ViewFields { builder.parent.default_namespace = '' opts[:view_fields].each do |f| builder.FieldRef(:Name => f.to_s.camel_case) end } } end builder.queryOptions { builder.QueryOptions { builder.parent.default_namespace = '' builder.Folder(opts[:folder]) builder.ViewAttributes(:Scope => 'Recursive') if opts[:recursive] builder.DateInUtc('True') if opts[:date_in_utc] builder.IncludeAttachmentUrls('True') } } # @todo Is this worth supporting??? #builder.webID(parms[:web_id]) } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) ns = {'xmlns:z' => "#RowsetSchema"} items = [] soaprsp.xpath('//z:row', ns).each do |li| items << Types::ListItem.new(self, list, li) end items end |
#update_list_items(list, updates = {}) {|builder| ... } ⇒ Object
Adds, deletes, or updates the specified items in a list
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/viewpoint/spws/websvc/lists.rb', line 367 def update_list_items(list, updates = {}) # Set Default values updates[:view_name] = '' unless updates.has_key?(:view_name) updates[:on_error] = 'Continue' unless updates.has_key?(:on_error) updates[:list_version] = '' unless updates.has_key?(:list_version) updates[:version] = '' unless updates.has_key?(:version) soapmsg = build_soap_envelope do |type, builder| if(type == :header) else builder.UpdateListItems { builder.parent.default_namespace = @default_ns builder.listName(list) builder.updates { builder.Batch(:ViewName => updates[:view_name], :OnError => updates[:on_error], :ListVersion => updates[:list_version], :Version => updates[:version]) { builder.parent.default_namespace = '' # First format passed item_updates updates[:item_updates] && updates[:item_updates].each_with_index do |iu,idx| iu = iu.clone builder.Method(:ID => "VP_IDX#{idx}", :Cmd => iu.delete(:command)) do builder.Field(iu.delete(:id), :Name => 'ID') iu.each_pair do |k,v| builder.Field(v, :Name => k.to_s.camel_case) end end end # Now include block-passed updates if block_given? yield builder end } } } end end soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml)) parse_update_list_items(list, soaprsp) end |