rews 0.5.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/lib/rews.rb +2 -0
- data/lib/rews/util.rb +35 -7
- data/spec/rews/client_spec.rb +14 -14
- data/spec/rews/item_spec.rb +4 -4
- data/spec/rews/update_spec.rb +2 -2
- data/spec/rews/util_spec.rb +9 -1
- metadata +31 -30
data/Rakefile
CHANGED
@@ -10,11 +10,11 @@ begin
|
|
10
10
|
gem.email = "craig@trampolinesystems.com"
|
11
11
|
gem.homepage = "http://github.com/trampoline/rews"
|
12
12
|
gem.authors = ["Trampoline Systems Ltd"]
|
13
|
-
gem.
|
14
|
-
gem.
|
15
|
-
gem.
|
16
|
-
gem.add_runtime_dependency "
|
17
|
-
gem.
|
13
|
+
gem.add_runtime_dependency "savon", "= 0.9.1"
|
14
|
+
gem.add_runtime_dependency "httpclient", ">= 2.2.0.2"
|
15
|
+
gem.add_runtime_dependency "pyu-ntlm-http", ">= 0.1.3"
|
16
|
+
gem.add_runtime_dependency "fetch_in", ">= 0.2.0"
|
17
|
+
gem.add_runtime_dependency "rsxml", ">= 0.3.0"
|
18
18
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
19
19
|
gem.add_development_dependency "rr", ">= 0.10.5"
|
20
20
|
gem.add_development_dependency "nokogiri", ">= 1.4.4"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.3
|
data/lib/rews.rb
CHANGED
data/lib/rews/util.rb
CHANGED
@@ -55,7 +55,11 @@ module Rews
|
|
55
55
|
|
56
56
|
# camel-case a +String+
|
57
57
|
def camelize(s)
|
58
|
-
s.
|
58
|
+
if s.is_a?(Symbol)
|
59
|
+
s.to_s.split('_').map(&:capitalize).join.to_sym
|
60
|
+
else
|
61
|
+
s.split('_').map(&:capitalize).join
|
62
|
+
end
|
59
63
|
end
|
60
64
|
|
61
65
|
# camel-case the keys of a +Hash+
|
@@ -63,14 +67,38 @@ module Rews
|
|
63
67
|
Hash[h.map{|k,v| [camelize(k.to_s), v]}]
|
64
68
|
end
|
65
69
|
|
66
|
-
#
|
67
|
-
#
|
70
|
+
# given an exploded qname, apply a given namespace and uri if the qname
|
71
|
+
# has no namespace already
|
72
|
+
def apply_namespace(qname, apply_prefix, apply_uri)
|
73
|
+
local_part, prefix, uri = qname
|
74
|
+
|
75
|
+
if !prefix
|
76
|
+
prefix = apply_prefix
|
77
|
+
uri = apply_uri
|
78
|
+
end
|
79
|
+
|
80
|
+
[local_part, prefix, uri].compact
|
81
|
+
end
|
82
|
+
|
83
|
+
# given an exploded qname, camelize the local_part
|
84
|
+
def camelize_qname(qname)
|
85
|
+
local_part, prefix, uri = qname
|
86
|
+
[camelize(local_part), prefix, uri].compact
|
87
|
+
end
|
88
|
+
|
89
|
+
# convert rsxml to xml, transforming local_parts of QNames to CamelCase and prefixing with
|
90
|
+
# the t: namespace prefix if no namespace is already applied
|
68
91
|
def rsxml_to_xml(sexp)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
92
|
+
# visit the rsxml, prefix the element tags with "t" namespace prefix, and camelcase
|
93
|
+
# all QName local_parts
|
94
|
+
transform_visitor = Rsxml::Visitor::BuildRsxmlVisitor.new() do |context, element_name, attrs|
|
95
|
+
t_element_name = camelize_qname(apply_namespace(element_name, "t", Rews::SCHEMA_TYPES))
|
96
|
+
t_attrs = Hash[attrs.map{|attr_name,v| [camelize_qname(attr_name), v]}]
|
97
|
+
[t_element_name, t_attrs]
|
73
98
|
end
|
99
|
+
|
100
|
+
xrsxml = Rsxml::Sexp.traverse(sexp, transform_visitor).sexp
|
101
|
+
Rsxml.to_xml(xrsxml, :ns=>{"t"=>Rews::SCHEMA_TYPES, "wsdl"=>Rews::SCHEMA_MESSAGES})
|
74
102
|
end
|
75
103
|
|
76
104
|
# check the response codes of an Exchange Web Services request.
|
data/spec/rews/client_spec.rb
CHANGED
@@ -35,8 +35,8 @@ module Rews
|
|
35
35
|
it "should create a CreateItem request and render the Items to the body" do
|
36
36
|
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
37
37
|
test_create_item(client, [[:suppress_read_receipt, [:reference_item_id, {:id=>"abc", :change_key=>"def"}]]]) do |body|
|
38
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
39
|
-
rsxml.should == ["wsdl:Items",
|
38
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"}, :style=>:xml)
|
39
|
+
rsxml.should == ["wsdl:Items",
|
40
40
|
["t:SuppressReadReceipt",
|
41
41
|
["t:ReferenceItemId", {"Id"=>"abc", "ChangeKey"=>"def"}]]]
|
42
42
|
end
|
@@ -61,8 +61,8 @@ module Rews
|
|
61
61
|
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
62
62
|
test_suppress_read_receipt(client, [Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}),
|
63
63
|
Item::ItemId.new(client, {:id=>"ghi", :change_key=>"jkl"})]) do |body|
|
64
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
65
|
-
rsxml.should == ["wsdl:Items",
|
64
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"}, :style=>:xml)
|
65
|
+
rsxml.should == ["wsdl:Items",
|
66
66
|
["t:SuppressReadReceipt",
|
67
67
|
["t:ReferenceItemId", {"Id"=>"abc", "ChangeKey"=>"def"}]],
|
68
68
|
["t:SuppressReadReceipt",
|
@@ -74,8 +74,8 @@ module Rews
|
|
74
74
|
client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
|
75
75
|
test_suppress_read_receipt(client, [Item::Item.new(client, 'Message', {:item_id=>{:id=>'abc', :change_key=>'def'}}),
|
76
76
|
Item::Item.new(client, 'Message', {:item_id=>{:id=>'ghi', :change_key=>'jkl'}})]) do |body|
|
77
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
78
|
-
rsxml.should == ["wsdl:Items",
|
77
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"}, :style=>:xml)
|
78
|
+
rsxml.should == ["wsdl:Items",
|
79
79
|
["t:SuppressReadReceipt",
|
80
80
|
["t:ReferenceItemId", {"Id"=>"abc", "ChangeKey"=>"def"}]],
|
81
81
|
["t:SuppressReadReceipt",
|
@@ -88,8 +88,8 @@ module Rews
|
|
88
88
|
fr = Folder::FindResult.new({}){[Item::Item.new(client, 'Message', {:item_id=>{:id=>'abc', :change_key=>'def'}}),
|
89
89
|
Item::Item.new(client, 'Message', {:item_id=>{:id=>'ghi', :change_key=>'jkl'}})]}
|
90
90
|
test_suppress_read_receipt(client, fr) do |body|
|
91
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
92
|
-
rsxml.should == ["wsdl:Items",
|
91
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"}, :style=>:xml)
|
92
|
+
rsxml.should == ["wsdl:Items",
|
93
93
|
["t:SuppressReadReceipt",
|
94
94
|
["t:ReferenceItemId", {"Id"=>"abc", "ChangeKey"=>"def"}]],
|
95
95
|
["t:SuppressReadReceipt",
|
@@ -108,8 +108,8 @@ module Rews
|
|
108
108
|
'Message',
|
109
109
|
{:item_id=>{:id=>'mno', :change_key=>'pqr'},
|
110
110
|
:is_read_receipt_requested=>false})]) do |body|
|
111
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"})
|
112
|
-
rsxml.should == ["wsdl:Items",
|
111
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{"wsdl"=>"ews_wsdl", "t"=>"ews_types"}, :style=>:xml)
|
112
|
+
rsxml.should == ["wsdl:Items",
|
113
113
|
["t:SuppressReadReceipt",
|
114
114
|
["t:ReferenceItemId", {"Id"=>"ghi", "ChangeKey"=>"jkl"}]]]
|
115
115
|
end
|
@@ -233,8 +233,8 @@ module Rews
|
|
233
233
|
SetItemField.new("message:IsRead", [:message, [:is_read, "true"]]),
|
234
234
|
[Item::ItemId.new(client, :id=>"abc", :change_key=>"def")]) do |body|
|
235
235
|
|
236
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"})
|
237
|
-
Rsxml.compare(rsxml, ["wsdl:ItemChanges",
|
236
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"}, :style=>:xml)
|
237
|
+
Rsxml.compare(rsxml, ["wsdl:ItemChanges",
|
238
238
|
["t:ItemChange",
|
239
239
|
["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
|
240
240
|
["t:Updates",
|
@@ -252,8 +252,8 @@ module Rews
|
|
252
252
|
[Item::ItemId.new(client, :id=>"abc", :change_key=>"def"),
|
253
253
|
Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")]) do |body|
|
254
254
|
|
255
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"})
|
256
|
-
Rsxml.compare(rsxml, ["wsdl:ItemChanges",
|
255
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"}, :style=>:xml)
|
256
|
+
Rsxml.compare(rsxml, ["wsdl:ItemChanges",
|
257
257
|
["t:ItemChange",
|
258
258
|
["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
|
259
259
|
["t:Updates",
|
data/spec/rews/item_spec.rb
CHANGED
@@ -201,8 +201,8 @@ module Rews
|
|
201
201
|
update=Object.new
|
202
202
|
stub(update).to_xml{"blahblah"}
|
203
203
|
msg = test_update_item(c, "AutoResolve", "SaveOnly", false, update) do |body|
|
204
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types"})
|
205
|
-
rsxml.should == ["wsdl:ItemChanges",
|
204
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types"}, :style=>:xml)
|
205
|
+
rsxml.should == ["wsdl:ItemChanges",
|
206
206
|
["t:ItemChange",
|
207
207
|
["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
|
208
208
|
["t:Updates", "blahblah"]]]
|
@@ -246,8 +246,8 @@ module Rews
|
|
246
246
|
it "should generate the body xml and parse the response" do
|
247
247
|
c = client
|
248
248
|
test_set_is_read(c, true) do |body|
|
249
|
-
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"})
|
250
|
-
Rsxml.compare(rsxml, ["wsdl:ItemChanges",
|
249
|
+
rsxml = Rsxml.to_rsxml(body, :ns=>{:wsdl=>"ews_wsdl", :t=>"ews_types", ""=>"ews_wsdl"}, :style=>:xml)
|
250
|
+
Rsxml.compare(rsxml, ["wsdl:ItemChanges",
|
251
251
|
["t:ItemChange",
|
252
252
|
["t:ItemId", {"Id"=>"abc", "ChangeKey"=>"def"}],
|
253
253
|
["t:Updates",
|
data/spec/rews/update_spec.rb
CHANGED
@@ -9,9 +9,9 @@ module Rews
|
|
9
9
|
[:is_read, "true"]]).to_xml
|
10
10
|
|
11
11
|
|
12
|
-
rsxml = Rsxml.to_rsxml(xml, :ns=>{"t"=>"ews_types"})
|
12
|
+
rsxml = Rsxml.to_rsxml(xml, :ns=>{"t"=>"ews_types"}, :style=>:xml)
|
13
13
|
|
14
|
-
rsxml.should == ["t:SetItemField",
|
14
|
+
rsxml.should == ["t:SetItemField",
|
15
15
|
["t:FieldURI", {"FieldURI"=>"message:IsRead"}],
|
16
16
|
["t:Message", ["t:IsRead", "true"]]]
|
17
17
|
end
|
data/spec/rews/util_spec.rb
CHANGED
@@ -16,6 +16,10 @@ module Rews
|
|
16
16
|
it "should camelize a String" do
|
17
17
|
Util.camelize("foo_bar").should == "FooBar"
|
18
18
|
end
|
19
|
+
|
20
|
+
it "should camelize a Symbol" do
|
21
|
+
Util.camelize(:foo_bar).should == :FooBar
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
describe "camel_keys" do
|
@@ -26,12 +30,16 @@ module Rews
|
|
26
30
|
end
|
27
31
|
|
28
32
|
describe "rsxml_to_xml" do
|
29
|
-
it "should camelize tags and attribute names, and
|
33
|
+
it "should camelize tags and attribute names, and give un-namespaced tags 't' prefix" do
|
30
34
|
Util.rsxml_to_xml([:foo]).should == "<t:Foo></t:Foo>"
|
31
35
|
Util.rsxml_to_xml([:foo_foo, {:bar_bar=>"blah"}]).should == '<t:FooFoo BarBar="blah"></t:FooFoo>'
|
32
36
|
Util.rsxml_to_xml([:foo_foo, {:bar_bar=>"blah"}, "foofoo", [:baz_baz, {:boo_hoo=>"10"}, "bazbaz"]]).should ==
|
33
37
|
'<t:FooFoo BarBar="blah">foofoo<t:BazBaz BooHoo="10">bazbaz</t:BazBaz></t:FooFoo>'
|
34
38
|
end
|
39
|
+
|
40
|
+
it "should not prefix tags which are already namespaced" do
|
41
|
+
Util.rsxml_to_xml([[:foo, "f", "http://f.com/f"]]).should == '<f:Foo xmlns:f="http://f.com/f"></f:Foo>'
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
45
|
describe "with_error_check" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rews
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 3
|
10
|
+
version: 0.5.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Trampoline Systems Ltd
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-01 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,79 +24,80 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - "="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 57
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
-
|
33
|
-
-
|
34
|
-
version: 0.
|
32
|
+
- 9
|
33
|
+
- 1
|
34
|
+
version: 0.9.1
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: httpclient
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 123
|
46
46
|
segments:
|
47
|
+
- 2
|
48
|
+
- 2
|
47
49
|
- 0
|
48
|
-
- 1
|
49
50
|
- 2
|
50
|
-
version: 0.
|
51
|
+
version: 2.2.0.2
|
51
52
|
type: :runtime
|
52
53
|
version_requirements: *id002
|
53
54
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
55
|
+
name: pyu-ntlm-http
|
55
56
|
prerelease: false
|
56
57
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
58
|
none: false
|
58
59
|
requirements:
|
59
60
|
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
62
|
+
hash: 29
|
62
63
|
segments:
|
63
64
|
- 0
|
64
|
-
-
|
65
|
-
-
|
66
|
-
version: 0.
|
65
|
+
- 1
|
66
|
+
- 3
|
67
|
+
version: 0.1.3
|
67
68
|
type: :runtime
|
68
69
|
version_requirements: *id003
|
69
70
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
+
name: fetch_in
|
71
72
|
prerelease: false
|
72
73
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
74
|
none: false
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
78
|
+
hash: 23
|
78
79
|
segments:
|
79
80
|
- 0
|
80
|
-
-
|
81
|
-
-
|
82
|
-
version: 0.
|
81
|
+
- 2
|
82
|
+
- 0
|
83
|
+
version: 0.2.0
|
83
84
|
type: :runtime
|
84
85
|
version_requirements: *id004
|
85
86
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
87
|
+
name: rsxml
|
87
88
|
prerelease: false
|
88
89
|
requirement: &id005 !ruby/object:Gem::Requirement
|
89
90
|
none: false
|
90
91
|
requirements:
|
91
92
|
- - ">="
|
92
93
|
- !ruby/object:Gem::Version
|
93
|
-
hash:
|
94
|
+
hash: 19
|
94
95
|
segments:
|
95
|
-
-
|
96
|
-
-
|
97
|
-
-
|
98
|
-
version:
|
99
|
-
type: :
|
96
|
+
- 0
|
97
|
+
- 3
|
98
|
+
- 0
|
99
|
+
version: 0.3.0
|
100
|
+
type: :runtime
|
100
101
|
version_requirements: *id005
|
101
102
|
- !ruby/object:Gem::Dependency
|
102
103
|
name: rspec
|