viewpoint 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/viewpoint.rb +1 -0
- data/lib/viewpoint/calendar.rb +8 -0
- data/lib/viewpoint/calendar_item.rb +13 -4
- data/lib/viewpoint/errors.rb +34 -0
- data/lib/viewpoint/folder.rb +58 -2
- data/lib/viewpoint/item.rb +42 -16
- data/lib/viewpoint/mail.rb +4 -0
- data/lib/viewpoint/message.rb +3 -4
- metadata +13 -2
data/Rakefile
CHANGED
@@ -29,6 +29,7 @@ GEMSPEC = Gem::Specification.new do |gem|
|
|
29
29
|
gem.required_ruby_version = '>= 1.8.7'
|
30
30
|
gem.add_runtime_dependency 'soap4r', '>=1.5.8'
|
31
31
|
gem.add_runtime_dependency 'icalendar'
|
32
|
+
gem.add_runtime_dependency 'rubyntlm', '>=0.1.1'
|
32
33
|
gem.post_install_message = "Don't forget to create .viewpointrc. See README"
|
33
34
|
end
|
34
35
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/viewpoint.rb
CHANGED
data/lib/viewpoint/calendar.rb
CHANGED
@@ -116,5 +116,13 @@ class Viewpoint::CalendarFolder < Viewpoint::Folder
|
|
116
116
|
def get_item(item_id)
|
117
117
|
cali = super(item_id, "calendarItem", true)
|
118
118
|
end
|
119
|
+
|
120
|
+
def get_event(item_id)
|
121
|
+
begin
|
122
|
+
return CalendarItem.new(get_item(item_id), self)
|
123
|
+
rescue InvalidEWSItemError => e
|
124
|
+
return nil
|
125
|
+
end
|
126
|
+
end
|
119
127
|
end
|
120
128
|
|
@@ -25,13 +25,12 @@ require 'item'
|
|
25
25
|
class Viewpoint::CalendarItem < Viewpoint::Item
|
26
26
|
include Viewpoint
|
27
27
|
|
28
|
-
|
29
|
-
attr_reader :ews_item if $DEBUG
|
28
|
+
attr_reader :subject, :organizer, :location, :start, :end, :cal_item_type
|
30
29
|
|
31
30
|
# Initialize an Exchange Web Services item
|
32
31
|
def initialize(ews_item, parent_folder)
|
33
|
-
|
34
|
-
|
32
|
+
raise InvalidEWSItemError if ews_item.nil?
|
33
|
+
|
35
34
|
@subject = ews_item.subject # String
|
36
35
|
@location = ews_item.location if ews_item.location
|
37
36
|
@cal_item_type = ews_item.calendarItemType
|
@@ -50,6 +49,16 @@ class Viewpoint::CalendarItem < Viewpoint::Item
|
|
50
49
|
end
|
51
50
|
|
52
51
|
|
52
|
+
def body
|
53
|
+
get_calitem if @message == nil
|
54
|
+
@message.body
|
55
|
+
end
|
56
|
+
|
57
|
+
def sender
|
58
|
+
@organizer
|
59
|
+
end
|
60
|
+
|
61
|
+
|
53
62
|
# Convert item to iCal format: http://www.ietf.org/rfc/rfc2445.txt
|
54
63
|
# Returns Icalendar::Event object
|
55
64
|
def to_ical_event
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# Copyright © 2009 Dan Wanek <dan.wanek@gmail.com>
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# This file is part of Viewpoint.
|
6
|
+
#
|
7
|
+
# Viewpoint is free software: you can redistribute it and/or
|
8
|
+
# modify it under the terms of the GNU General Public License as published
|
9
|
+
# by the Free Software Foundation, either version 3 of the License, or (at
|
10
|
+
# your option) any later version.
|
11
|
+
#
|
12
|
+
# Viewpoint is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
15
|
+
# Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License along
|
18
|
+
# with Viewpoint. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#############################################################################
|
20
|
+
$:.unshift(File.dirname(__FILE__))
|
21
|
+
require 'viewpoint'
|
22
|
+
|
23
|
+
class Viewpoint::InvalidEWSItemError < Exception
|
24
|
+
def message
|
25
|
+
"Invalid Item for Exchange Web Services"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class Viewpoint::NoSuchItemIdError < Exception
|
31
|
+
def message
|
32
|
+
"No such item_id found in Exchange"
|
33
|
+
end
|
34
|
+
end
|
data/lib/viewpoint/folder.rb
CHANGED
@@ -39,6 +39,10 @@ class Viewpoint::Folder
|
|
39
39
|
# to check_subscription will use that id.
|
40
40
|
# Returns true if the operation is successful, false otherwise
|
41
41
|
def subscribe
|
42
|
+
# Refresh the subscription if already subscribed
|
43
|
+
if( subscribed? )
|
44
|
+
unsubscribe
|
45
|
+
end
|
42
46
|
subscribe = SubscribeType.new
|
43
47
|
pull = PullSubscriptionRequestType.new
|
44
48
|
|
@@ -69,6 +73,10 @@ class Viewpoint::Folder
|
|
69
73
|
return (resp.responseCode == "NoError")? true: false
|
70
74
|
end
|
71
75
|
|
76
|
+
def subscribed?
|
77
|
+
( @subscription_id.nil? or @watermark.nil? )? false : true
|
78
|
+
end
|
79
|
+
|
72
80
|
|
73
81
|
# unsubscribe from folder
|
74
82
|
# Returns true if unsubscription succeeds, false otherwise
|
@@ -88,6 +96,9 @@ class Viewpoint::Folder
|
|
88
96
|
|
89
97
|
# Fetch events with the subscription_id. If one does not exists or is expired,
|
90
98
|
# call subscribe.
|
99
|
+
# Returns a hash with the event type as the key and an Array of Hashes that
|
100
|
+
# represent each event's data
|
101
|
+
# An :error key is set if there is a problem
|
91
102
|
def check_subscription
|
92
103
|
begin
|
93
104
|
if( @subscription_id == nil or @watermark == nil) then
|
@@ -102,40 +113,77 @@ class Viewpoint::Folder
|
|
102
113
|
|
103
114
|
notifications = resp.first.notification
|
104
115
|
|
116
|
+
notif_hash = {}
|
105
117
|
# Process Notifications
|
106
118
|
if( notifications.copiedEvent != nil)
|
107
|
-
|
119
|
+
notif_hash[:copiedEvent] = []
|
120
|
+
notifications.copiedEvent.each do |note|
|
108
121
|
@watermark = note.watermark
|
122
|
+
item = {}
|
123
|
+
item.store(:old_item_id,note.oldItemId.xmlattr_Id) if note.itemId
|
124
|
+
item.store(:old_folder_id,note.oldParentFolderId.xmlattr_Id) if note.oldParentFolderId
|
125
|
+
item.store(:item_id,note.itemId.xmlattr_Id) if note.itemId
|
126
|
+
item.store(:folder_id,note.parentFolderId.xmlattr_Id) if note.parentFolderId
|
127
|
+
notif_hash[:copiedEvent] << item
|
109
128
|
end
|
110
129
|
end
|
111
130
|
|
112
131
|
if( notifications.createdEvent != nil)
|
132
|
+
notif_hash[:createdEvent] = []
|
113
133
|
notifications.createdEvent.each do |note|
|
114
134
|
@watermark = note.watermark
|
135
|
+
item = {}
|
136
|
+
item.store(:item_id,note.itemId.xmlattr_Id) if note.itemId
|
137
|
+
item.store(:folder_id,note.parentFolderId.xmlattr_Id) if note.parentFolderId
|
138
|
+
notif_hash[:createdEvent] << item
|
115
139
|
end
|
116
140
|
end
|
117
141
|
|
118
142
|
if( notifications.deletedEvent != nil)
|
143
|
+
notif_hash[:deletedEvent] = []
|
119
144
|
notifications.deletedEvent.each do |note|
|
120
145
|
@watermark = note.watermark
|
146
|
+
item = {}
|
147
|
+
item.store(:item_id,note.itemId.xmlattr_Id) if note.itemId
|
148
|
+
item.store(:folder_id,note.parentFolderId.xmlattr_Id) if note.parentFolderId
|
149
|
+
notif_hash[:deletedEvent] << item
|
121
150
|
end
|
122
151
|
end
|
123
152
|
|
124
153
|
if( notifications.modifiedEvent != nil)
|
154
|
+
notif_hash[:modifiedEvent] = []
|
125
155
|
notifications.modifiedEvent.each do |note|
|
126
156
|
@watermark = note.watermark
|
157
|
+
item = {}
|
158
|
+
item.store(:item_id,note.itemId.xmlattr_Id) if note.itemId
|
159
|
+
item.store(:folder_id,note.folderId.xmlattr_Id) if note.folderId
|
160
|
+
item.store(:parent_folder_id,note.parentFolderId.xmlattr_Id) if note.parentFolderId
|
161
|
+
item.store(:unreadCount,note.unreadCount)
|
162
|
+
notif_hash[:modifiedEvent] << item
|
127
163
|
end
|
128
164
|
end
|
129
165
|
|
130
166
|
if( notifications.movedEvent != nil)
|
167
|
+
notif_hash[:movedEvent] = []
|
131
168
|
notifications.movedEvent.each do |note|
|
132
169
|
@watermark = note.watermark
|
170
|
+
item = {}
|
171
|
+
item.store(:old_item_id,note.oldItemId.xmlattr_Id) if note.oldItemId
|
172
|
+
item.store(:old_folder_id,note.oldParentFolderId.xmlattr_Id) if note.oldParentFolderId
|
173
|
+
item.store(:item_id,note.itemId.xmlattr_Id) if note.itemId
|
174
|
+
item.store(:folder_id,note.parentFolderId.xmlattr_Id) if note.parentFolderId
|
175
|
+
notif_hash[:movedEvent] << item
|
133
176
|
end
|
134
177
|
end
|
135
178
|
|
136
179
|
if( notifications.newMailEvent!= nil)
|
180
|
+
notif_hash[:newMailEvent] = []
|
137
181
|
notifications.newMailEvent.each do |note|
|
138
182
|
@watermark = note.watermark
|
183
|
+
item = {}
|
184
|
+
item.store(:item_id,note.itemId.xmlattr_Id) if note.itemId
|
185
|
+
item.store(:folder_id,note.parentFolderId.xmlattr_Id) if note.parentFolderId
|
186
|
+
notif_hash[:newMailEvent] << item
|
139
187
|
end
|
140
188
|
end
|
141
189
|
|
@@ -145,9 +193,17 @@ class Viewpoint::Folder
|
|
145
193
|
end
|
146
194
|
end
|
147
195
|
|
196
|
+
rescue NoMethodError
|
197
|
+
# This ocurrs if something bad happened to the subscription.
|
198
|
+
# This is handled by resubscribing to the subscription and returning
|
199
|
+
# an error key.
|
200
|
+
self.subscribe
|
201
|
+
return {:error => "Something bad happened to your subscription. You have been re-subscribed" }
|
148
202
|
end
|
149
203
|
|
150
|
-
return resp
|
204
|
+
#return resp
|
205
|
+
notif_hash[:resp] = resp
|
206
|
+
return notif_hash
|
151
207
|
end
|
152
208
|
|
153
209
|
|
data/lib/viewpoint/item.rb
CHANGED
@@ -25,12 +25,16 @@
|
|
25
25
|
class Viewpoint::Item
|
26
26
|
include Viewpoint
|
27
27
|
|
28
|
-
attr_accessor :item_id
|
28
|
+
attr_accessor :item_id, :parent_folder, :item_class
|
29
|
+
attr_reader :ews_item if $DEBUG
|
29
30
|
|
30
31
|
# Initialize an Exchange Web Services item
|
31
32
|
def initialize(ews_item, parent_folder)
|
33
|
+
@ews_item = ews_item if $DEBUG
|
34
|
+
|
32
35
|
@item_id = ews_item.itemId.xmlattr_Id
|
33
36
|
@parent_folder = parent_folder
|
37
|
+
@item_class = ews_item.itemClass
|
34
38
|
end
|
35
39
|
|
36
40
|
# Takes an object of type Viewpoint::Folder as an argument
|
@@ -43,26 +47,28 @@ class Viewpoint::Item
|
|
43
47
|
end
|
44
48
|
|
45
49
|
|
50
|
+
def entry_id
|
51
|
+
convert_id(IdFormatType::EntryId)
|
52
|
+
end
|
53
|
+
|
46
54
|
# Return the OWA ID so we can link to webmail
|
55
|
+
# Example usage: uri = "https://host/owa/?ae=Item&a=open&id=" + owa_id
|
47
56
|
def owa_id
|
48
|
-
|
49
|
-
altids_ar = NonEmptyArrayOfAlternateIdsType.new
|
50
|
-
|
51
|
-
altid_t = AlternateIdType.new
|
52
|
-
altid_t.xmlattr_Format = IdFormatType::EwsId
|
53
|
-
altid_t.xmlattr_Id = @item_id
|
54
|
-
altid_t.xmlattr_Mailbox = vp.email
|
55
|
-
altids_ar.alternateId << altid_t
|
56
|
-
|
57
|
-
convertid_t = ConvertIdType.new(altids_ar)
|
58
|
-
convertid_t.xmlattr_DestinationFormat = IdFormatType::OwaId
|
59
|
-
|
60
|
-
resp = vp.ews.convertId(convertid_t)
|
61
|
-
resp.responseMessages.convertIdResponseMessage.first.alternateId.xmlattr_Id
|
62
|
-
#uri = "https://host/owa/?ae=Item&a=open&id=" + owa_id
|
57
|
+
convert_id(IdFormatType::OwaId)
|
63
58
|
end
|
64
59
|
|
60
|
+
def ews_legacy_id
|
61
|
+
convert_id(IdFormatType::EwsLegacyId)
|
62
|
+
end
|
63
|
+
|
64
|
+
def hex_id
|
65
|
+
convert_id(IdFormatType::HexEntryId)
|
66
|
+
end
|
65
67
|
|
68
|
+
def store_id
|
69
|
+
convert_id(IdFormatType::StoreId)
|
70
|
+
end
|
71
|
+
|
66
72
|
# Returns a boolean value, true if the delete ocurred, false otherwise.
|
67
73
|
def delete!
|
68
74
|
@parent_folder.delete_item(@item_id)
|
@@ -72,4 +78,24 @@ class Viewpoint::Item
|
|
72
78
|
def recycle!
|
73
79
|
@parent_folder.recycle_item(@item_id)
|
74
80
|
end
|
81
|
+
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def convert_id(dest_type)
|
86
|
+
vp = ExchWebServ.instance
|
87
|
+
altids_ar = NonEmptyArrayOfAlternateIdsType.new
|
88
|
+
|
89
|
+
altid_t = AlternateIdType.new
|
90
|
+
altid_t.xmlattr_Format = IdFormatType::EwsId
|
91
|
+
altid_t.xmlattr_Id = @item_id
|
92
|
+
altid_t.xmlattr_Mailbox = vp.email
|
93
|
+
altids_ar.alternateId << altid_t
|
94
|
+
|
95
|
+
convertid_t = ConvertIdType.new(altids_ar)
|
96
|
+
convertid_t.xmlattr_DestinationFormat = dest_type
|
97
|
+
|
98
|
+
resp = vp.ews.convertId(convertid_t)
|
99
|
+
resp.responseMessages.convertIdResponseMessage.first.alternateId.xmlattr_Id
|
100
|
+
end
|
75
101
|
end
|
data/lib/viewpoint/mail.rb
CHANGED
data/lib/viewpoint/message.rb
CHANGED
@@ -23,13 +23,12 @@ require 'item'
|
|
23
23
|
class Viewpoint::Message < Viewpoint::Item
|
24
24
|
include Viewpoint
|
25
25
|
|
26
|
-
attr_reader :subject, :
|
27
|
-
attr_reader :ews_item if $DEBUG
|
26
|
+
attr_reader :subject, :sender, :date_time_recieved
|
28
27
|
|
29
28
|
# Initialize an Exchange Web Services item of MessageType
|
30
29
|
def initialize(ews_item, parent_folder)
|
31
|
-
|
32
|
-
|
30
|
+
raise InvalidEWSItemError if ews_item.nil?
|
31
|
+
|
33
32
|
@subject = ews_item.subject # String
|
34
33
|
@sender = ews_item.sender.mailbox.name if ews_item.sender # String
|
35
34
|
@recipients =
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viewpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Wanek
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-27 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,6 +32,16 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rubyntlm
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.1.1
|
44
|
+
version:
|
35
45
|
description: " \tA Ruby client access library for Microsoft Exchange Web Services (EWS). It is a work in progress. Methods are still being added from the EWS API docs. Please see them for further information: http://msdn.microsoft.com/en-us/library/bb204119.aspx\n"
|
36
46
|
email: dan.wanek@gmail.com
|
37
47
|
executables: []
|
@@ -97,6 +107,7 @@ files:
|
|
97
107
|
- lib/viewpoint.rb
|
98
108
|
- lib/viewpoint/calendar.rb
|
99
109
|
- lib/viewpoint/calendar_item.rb
|
110
|
+
- lib/viewpoint/errors.rb
|
100
111
|
- lib/viewpoint/event.rb
|
101
112
|
- lib/viewpoint/exchange_headers.rb
|
102
113
|
- lib/viewpoint/exchwebserv.rb
|