viewpoint-spws 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/README.md +75 -0
- data/Rakefile +7 -0
- data/lib/extensions/string.rb +35 -0
- data/lib/viewpoint/spws.rb +63 -0
- data/lib/viewpoint/spws/connection.rb +84 -0
- data/lib/viewpoint/spws/spws_client.rb +107 -0
- data/lib/viewpoint/spws/types.rb +27 -0
- data/lib/viewpoint/spws/types/document_library.rb +41 -0
- data/lib/viewpoint/spws/types/list.rb +107 -0
- data/lib/viewpoint/spws/types/list_item.rb +248 -0
- data/lib/viewpoint/spws/types/tasks_list.rb +48 -0
- data/lib/viewpoint/spws/types/user.rb +80 -0
- data/lib/viewpoint/spws/version.rb +5 -0
- data/lib/viewpoint/spws/websvc/copy.rb +108 -0
- data/lib/viewpoint/spws/websvc/lists.rb +484 -0
- data/lib/viewpoint/spws/websvc/user_group.rb +96 -0
- data/lib/viewpoint/spws/websvc/web_service_base.rb +65 -0
- data/preamble +17 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/spws_client_spec.rb +43 -0
- data/viewpoint-spws.gemspec +32 -0
- metadata +120 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of ViewpointSPWS; the Ruby library for Microsoft Sharepoint Web Services.
|
3
|
+
|
4
|
+
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
5
|
+
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
you may not use this file except in compliance with the License.
|
8
|
+
You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
See the License for the specific language governing permissions and
|
16
|
+
limitations under the License.
|
17
|
+
=end
|
18
|
+
|
19
|
+
# This class represents the Sharepoint User and Groups Web Service.
|
20
|
+
# @see http://msdn.microsoft.com/en-us/library/ms772647(v=office.12).aspx
|
21
|
+
class Viewpoint::SPWS::Websvc::UserGroup
|
22
|
+
include Viewpoint::SPWS::Websvc::WebServiceBase
|
23
|
+
|
24
|
+
def initialize(spcon)
|
25
|
+
@default_ns = 'http://schemas.microsoft.com/sharepoint/soap/directory/'
|
26
|
+
@ws_endpoint = '_vti_bin/UserGroup.asmx'
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_all_user_collection_from_web
|
31
|
+
soapmsg = build_soap_envelope do |type, builder|
|
32
|
+
if(type == :header)
|
33
|
+
else
|
34
|
+
builder.GetAllUserCollectionFromWeb {
|
35
|
+
builder.parent.default_namespace = @default_ns
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml))
|
40
|
+
ns = {'xmlns' => @default_ns}
|
41
|
+
users = []
|
42
|
+
soaprsp.xpath('//xmlns:Users/xmlns:User', ns).each do |li|
|
43
|
+
users << Types::User.new(self,li)
|
44
|
+
end
|
45
|
+
users
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns information about a specified user
|
49
|
+
# @param [String] user A username to retrieve infor for. It must be of the form
|
50
|
+
# DOMAIN\username
|
51
|
+
def get_user_info(user)
|
52
|
+
soapmsg = build_soap_envelope do |type, builder|
|
53
|
+
if(type == :header)
|
54
|
+
else
|
55
|
+
builder.GetUserInfo {
|
56
|
+
builder.parent.default_namespace = @default_ns
|
57
|
+
builder.userLoginName(user)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml))
|
62
|
+
ns = {'xmlns' => @default_ns}
|
63
|
+
user = soaprsp.xpath('//xmlns:GetUserInfo/xmlns:User', ns).first
|
64
|
+
Types::User.new(self,user)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Get user logins from e-mail addresses
|
68
|
+
# @see http://msdn.microsoft.com/en-us/library/ms774890(v=office.12).aspx
|
69
|
+
# @param [Array<String>] emails an Array of e-mail addresses to search for
|
70
|
+
# @return [Hash] a hash of email to login mappings
|
71
|
+
def get_user_login_from_email(emails)
|
72
|
+
soapmsg = build_soap_envelope do |type, builder|
|
73
|
+
if(type == :header)
|
74
|
+
else
|
75
|
+
builder.GetUserLoginFromEmail {
|
76
|
+
builder.parent.default_namespace = @default_ns
|
77
|
+
builder.emailXml {
|
78
|
+
builder.Users {
|
79
|
+
emails.each do |email|
|
80
|
+
builder.User(:Email => email)
|
81
|
+
end
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
soaprsp = Nokogiri::XML(send_soap_request(soapmsg.doc.to_xml))
|
88
|
+
ns = {'xmlns' => @default_ns}
|
89
|
+
logins = {}
|
90
|
+
soaprsp.xpath('//xmlns:GetUserLoginFromEmail/xmlns:User', ns).each do |li|
|
91
|
+
logins[li['Email']] = li['Login']
|
92
|
+
end
|
93
|
+
logins
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of ViewpointSPWS; the Ruby library for Microsoft Sharepoint Web Services.
|
3
|
+
|
4
|
+
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
5
|
+
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
you may not use this file except in compliance with the License.
|
8
|
+
You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
See the License for the specific language governing permissions and
|
16
|
+
limitations under the License.
|
17
|
+
=end
|
18
|
+
|
19
|
+
# This module represents the common elements of Sharepoint Web Services
|
20
|
+
module Viewpoint::SPWS::Websvc
|
21
|
+
module WebServiceBase
|
22
|
+
include Viewpoint::SPWS
|
23
|
+
|
24
|
+
NAMESPACES = {
|
25
|
+
'xmlns:soap' => 'http://www.w3.org/2003/05/soap-envelope',
|
26
|
+
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
|
27
|
+
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
attr_reader :spcon
|
31
|
+
|
32
|
+
# @param [Viewpoint::SPWS::Connection] spcon A connection to a Sharepoint Site
|
33
|
+
def initialize(spcon)
|
34
|
+
@log = Logging.logger[self.class.name.to_s.to_sym]
|
35
|
+
@spcon = spcon
|
36
|
+
raise "Auth failure" unless(@spcon.authenticate(@ws_endpoint))
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def build_soap_envelope
|
42
|
+
new_ent = Nokogiri::XML::Builder.new do |xml|
|
43
|
+
xml.Envelope(NAMESPACES) do |ent|
|
44
|
+
xml.parent.namespace = xml.parent.namespace_definitions.find{|ns|ns.prefix=="soap"}
|
45
|
+
ent['soap'].Header {
|
46
|
+
yield(:header, ent) if block_given?
|
47
|
+
}
|
48
|
+
ent['soap'].Body {
|
49
|
+
yield(:body, ent) if block_given?
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Send the SOAP request to the endpoint
|
56
|
+
# @param [String] soapmsg an XML formatted string
|
57
|
+
def send_soap_request(soapmsg)
|
58
|
+
@log.debug "Sending SOAP Request:\n----------------\n#{soapmsg}\n----------------"
|
59
|
+
respmsg = @spcon.post(@ws_endpoint, soapmsg)
|
60
|
+
@log.debug "Received SOAP Response:\n----------------\n#{Nokogiri::XML(respmsg).to_xml}\n----------------"
|
61
|
+
respmsg
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/preamble
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of ViewpointSPWS; the Ruby library for Microsoft Sharepoint Web Services.
|
3
|
+
|
4
|
+
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
|
5
|
+
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
you may not use this file except in compliance with the License.
|
8
|
+
You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
See the License for the specific language governing permissions and
|
16
|
+
limitations under the License.
|
17
|
+
=end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib/'
|
2
|
+
require 'yaml'
|
3
|
+
require 'date'
|
4
|
+
require 'viewpoint/spws'
|
5
|
+
|
6
|
+
# To run these tests put configuration into a file called site_info.yaml
|
7
|
+
# ---
|
8
|
+
# :site: sp_site_base
|
9
|
+
# :user: user
|
10
|
+
# :pass: pass
|
11
|
+
|
12
|
+
module SpecHelper
|
13
|
+
def self.specdir
|
14
|
+
File.dirname(__FILE__)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.before(:all) do
|
20
|
+
@conf = YAML.load(File.open("#{SpecHelper.specdir}/site_info.yaml",'r'))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
$: << File.dirname(__FILE__)
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Test the Sharepoint List web service functionality' do
|
5
|
+
before(:all) do
|
6
|
+
@scli = Viewpoint::SPWSClient.new(@conf[:site], @conf[:user], @conf[:pass])
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should return the Lists web service' do
|
10
|
+
@scli.lists_ws.should be_an_instance_of Viewpoint::SPWS::Websvc::Lists
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return the Copy web service' do
|
14
|
+
@scli.copy_ws.should be_an_instance_of Viewpoint::SPWS::Websvc::Copy
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return the UserGroup web service' do
|
18
|
+
@scli.usergroup_ws.should be_an_instance_of Viewpoint::SPWS::Websvc::UserGroup
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should retrieve the Lists from a given Sharepoint site' do
|
22
|
+
lists = @scli.get_lists
|
23
|
+
lists.should be_an_instance_of(Array)
|
24
|
+
lists.first.should be_a_kind_of(Viewpoint::SPWS::Types::List)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should retrieve the Items from a given List' do
|
28
|
+
lists = @scli.get_lists
|
29
|
+
items = lists.first.items
|
30
|
+
items.should be_an_instance_of(Array)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should retrieve a User given a domain login' do
|
34
|
+
u = @scli.get_user @conf[:user_login]
|
35
|
+
u.should be_an_instance_of(Viewpoint::SPWS::Types::User)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should retrieve a User given an e-mail' do
|
39
|
+
u = @scli.get_user @conf[:user_email]
|
40
|
+
u.should be_an_instance_of(Viewpoint::SPWS::Types::User)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "viewpoint/spws/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "viewpoint-spws"
|
7
|
+
s.version = Viewpoint::SPWS::VERSION
|
8
|
+
s.date = Date.today.to_s
|
9
|
+
s.author = "Dan Wanek"
|
10
|
+
s.email = "dan.wanek@gmail.com"
|
11
|
+
s.homepage = "http://github.com/zenchild/viewpoint-spws"
|
12
|
+
s.summary = "A Ruby client access library for Microsoft Sharepoint Web Services (SPWS)"
|
13
|
+
s.description = %q{TODO: Write a gem description}
|
14
|
+
s.description = <<-EOF
|
15
|
+
A Ruby client access library for Microsoft Sharepoint Web Services (SPWS). It is a work in progress. Methods are still being added from the Sharepoint API docs.
|
16
|
+
EOF
|
17
|
+
s.required_ruby_version = '>= 1.8.7'
|
18
|
+
|
19
|
+
s.rubyforge_project = nil
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
s.rdoc_options = %w(-x spec/)
|
26
|
+
s.extra_rdoc_files = %w(README.md LICENSE)
|
27
|
+
|
28
|
+
s.add_runtime_dependency 'nokogiri', '~> 1.5.0'
|
29
|
+
s.add_runtime_dependency 'httpclient', '~> 2.2.4'
|
30
|
+
s.add_runtime_dependency 'logging', '~> 1.6.1'
|
31
|
+
s.add_runtime_dependency 'rubyntlm'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viewpoint-spws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Wanek
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &11969560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *11969560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httpclient
|
27
|
+
requirement: &11969100 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.4
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *11969100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: logging
|
38
|
+
requirement: &11968540 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.6.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *11968540
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rubyntlm
|
49
|
+
requirement: &11968100 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *11968100
|
58
|
+
description: ! ' A Ruby client access library for Microsoft Sharepoint Web Services
|
59
|
+
(SPWS). It is a work in progress. Methods are still being added from the Sharepoint
|
60
|
+
API docs.
|
61
|
+
|
62
|
+
'
|
63
|
+
email: dan.wanek@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files:
|
67
|
+
- README.md
|
68
|
+
- LICENSE
|
69
|
+
files:
|
70
|
+
- .rvmrc
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/extensions/string.rb
|
76
|
+
- lib/viewpoint/spws.rb
|
77
|
+
- lib/viewpoint/spws/connection.rb
|
78
|
+
- lib/viewpoint/spws/spws_client.rb
|
79
|
+
- lib/viewpoint/spws/types.rb
|
80
|
+
- lib/viewpoint/spws/types/document_library.rb
|
81
|
+
- lib/viewpoint/spws/types/list.rb
|
82
|
+
- lib/viewpoint/spws/types/list_item.rb
|
83
|
+
- lib/viewpoint/spws/types/tasks_list.rb
|
84
|
+
- lib/viewpoint/spws/types/user.rb
|
85
|
+
- lib/viewpoint/spws/version.rb
|
86
|
+
- lib/viewpoint/spws/websvc/copy.rb
|
87
|
+
- lib/viewpoint/spws/websvc/lists.rb
|
88
|
+
- lib/viewpoint/spws/websvc/user_group.rb
|
89
|
+
- lib/viewpoint/spws/websvc/web_service_base.rb
|
90
|
+
- preamble
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- spec/spws_client_spec.rb
|
93
|
+
- viewpoint-spws.gemspec
|
94
|
+
homepage: http://github.com/zenchild/viewpoint-spws
|
95
|
+
licenses: []
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options:
|
98
|
+
- -x
|
99
|
+
- spec/
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 1.8.7
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.10
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: A Ruby client access library for Microsoft Sharepoint Web Services (SPWS)
|
120
|
+
test_files: []
|