Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Views WebServices to enable list of fields in View::view_fields #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ taskl.modified
tasks = taskl.items
```

### Retrieving Items with View fields
```ruby
# Retrieves an Array of Items with fields & it's values
list_name = 'ListOfProjects'
view_name = scli.get_view_collection(list_name).first.name
view = scli.get_view(list_name, view_name)
scli.get_list_items('ListOfProjects', :view_name => view_name, :view_fields => view.view_fields).each do |i|
fields_hash = i.fields
....
end
```

### Creating/Renaming/Deleting a Task (other types of ListItems are forthcoming)
```ruby
t1 = taskl.add_item!(:title => "New Task")
Expand Down
2 changes: 2 additions & 0 deletions lib/viewpoint/spws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ def self.set_log_level(level)
require 'viewpoint/spws/websvc/copy'
# Lists Web Service
require 'viewpoint/spws/websvc/lists'
require 'viewpoint/spws/websvc/views'
require 'viewpoint/spws/types'
require 'viewpoint/spws/types/list'
require 'viewpoint/spws/types/tasks_list'
require 'viewpoint/spws/types/document_library'
require 'viewpoint/spws/types/list_item'
require 'viewpoint/spws/types/view'
# User and Groups Web Service
require 'viewpoint/spws/websvc/user_group'
require 'viewpoint/spws/types/user'
Expand Down
20 changes: 20 additions & 0 deletions lib/viewpoint/spws/spws_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def lists_ws
@listsws ||= Websvc::Lists.new(@con)
end

def views_ws
@views ||= Websvc::Views.new(@con)
end


def usergroup_ws
@usergroupws ||= Websvc::UserGroup.new(@con)
end
Expand Down Expand Up @@ -73,6 +78,11 @@ def get_lists
lists_ws.get_list_collection
end

# Retrieve all of the viewable list_items for the list.
def get_list_items(list, opts = {})
lists_ws.get_list_items(list, opts)
end

# Retrieve a List object
# @param [String] list title or the GUID for the list
def get_list(list)
Expand Down Expand Up @@ -108,4 +118,14 @@ def get_user(user)
end
usergroup_ws.get_user_info user
end

# ========= Views Accessor Proxy Methods =========
def get_view_collection(list_name)
views_ws.get_view_collection(list_name)
end

def get_view(list_name, view_name)
views_ws.get_view(list_name, view_name)
end

end
8 changes: 8 additions & 0 deletions lib/viewpoint/spws/types/list_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Viewpoint::SPWS::Types::ListItem
attr_reader :title, :link_title, :status, :priority, :percent_complete
attr_reader :start_date, :end_date, :recurrence, :all_day_event
attr_reader :attachments
attr_reader :fields

# @param [Viewpoint::SPWS::Websvc::List] ws The webservice instance this ListItem spawned from
# @param [String] list_id The list id that this item belongs to
Expand Down Expand Up @@ -235,6 +236,13 @@ def parse_xml_fields(xml)
set_field :@attachments, 'ows_Attachments', @xmldoc, true
set_field :@created_date, 'ows_Created_x0020_Date' unless @created_date
set_field :@modified_date, 'ows_Last_x0020_Modified' unless @modified_date
begin
@fields = {}
xml.attributes.each do |a|
(@fields[a[1].name.gsub(/^ows_/, '')] = a[1].value rescue true)
end
rescue true
end
@xmldoc = nil
end

Expand Down
28 changes: 28 additions & 0 deletions lib/viewpoint/spws/types/view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Viewpoint::SPWS::Types::View
include Viewpoint::SPWS::Types

attr_reader :name, :default_view, :mobile_view, :mobile_default_view, :type
attr_reader :display_name, :url, :level, :base_viewID, :content_typeID, :imageUrl
attr_reader :view_fields

def initialize(ws, xml)
@ws = ws
@view_fields = nil
parse_xml_fields(xml)
ns = {"xmlns" => xml.namespace.href}
xml.xpath('//xmlns:ViewFields/xmlns:FieldRef', ns).each do |l|
@view_fields ||= []
@view_fields << l.attributes['Name'].value
end
end

def parse_xml_fields(xml)
[:name, :default_view, :mobile_view, :mobile_default_view, :type,
:display_name, :url, :level, :base_viewID, :content_typeID, :imageUrl].each do |a|
# var = "@#{a}".to_sym
# val = xml[a.to_s.camel_case]
# puts "#{var.inspect} -> #{val.inspect}"
instance_variable_set "@#{a}".to_sym, xml[a.to_s.camel_case]
end
end
end
65 changes: 65 additions & 0 deletions lib/viewpoint/spws/websvc/views.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
=begin
This file is part of ViewpointSPWS; the Ruby library for Microsoft Sharepoint Web Services.

Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end

# This class represents the Sharepoint Lists Web Service.
# @see http://msdn.microsoft.com/en-us/library/ms774654(v=office.12).aspx
class Viewpoint::SPWS::Websvc::Views
include Viewpoint::SPWS::Websvc::WebServiceBase

def initialize(spcon)
@default_ns = 'http://schemas.microsoft.com/sharepoint/soap/'
@ws_endpoint = '_vti_bin/Views.asmx'
super
end

def get_view_collection(listName)
soapmsg = build_soap_envelope do |type, builder|
if(type == :header)
else
builder.GetViewCollection {
builder.parent.default_namespace = @default_ns
builder.listName(listName)
}
end
end
soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml))
ns = {"xmlns"=> @default_ns}
views = []
soaprsp.xpath('//xmlns:GetViewCollectionResponse/xmlns:GetViewCollectionResult/xmlns:Views/xmlns:View', ns).each do |l|
views << Types::View.new(self, l)
end
views
end

def get_view(listName, viewName)
soapmsg = build_soap_envelope do |type, builder|
if(type == :header)
else
builder.GetView {
builder.parent.default_namespace = @default_ns
builder.listName(listName)
builder.viewName(viewName)
}
end
end
soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml))
ns = {"xmlns"=> @default_ns}
Types::View.new(self, soaprsp.xpath('//xmlns:GetViewResponse/xmlns:GetViewResult/xmlns:View', ns).first)
end

end