zimbreasy 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +18 -4
- data/lib/zimbreasy.rb +3 -0
- data/lib/zimbreasy/account.rb +2 -1
- data/lib/zimbreasy/mail.rb +82 -25
- data/lib/zimbreasy/version.rb +1 -1
- metadata +10 -10
data/README.md
CHANGED
@@ -37,7 +37,14 @@ It's pretty simple to use, I will post some examples:
|
|
37
37
|
|
38
38
|
zs = Zimbreasy::Account.new('username', 'password', "https://yourzimbraserver.com/service/soap"); #login
|
39
39
|
zm = Zimbreasy::Mail.new(zs); #create a Zimbreasy::Mail object. This has methods for the ZimbraMail submodule of their API.
|
40
|
-
z = zm.create_appointment({
|
40
|
+
z = zm.create_appointment({
|
41
|
+
:appointee_email => "neo@matrix.com",
|
42
|
+
:start_time => Time.now+1.days,
|
43
|
+
:end_time => (Time.now+1.days+1.hours),
|
44
|
+
:name => "Joss Whedon Meeting",
|
45
|
+
:subject => "Hallelujah",
|
46
|
+
:desc => "Ridiculous stuff happening here"
|
47
|
+
}) #I create an appointment.
|
41
48
|
|
42
49
|
=> "BEGIN:VCALENDAR\r\nCALSCALE:GREGORIAN\r\nPRODID:iCalendar-Ruby\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nDESCRIPTION:Poopmaster\r\nDTEND:20130208T171612\r\nDTSTAMP:20130207T161614\r\nDTSTART:20130208T161612\r\nCLASS:PRIVATE\r\nSEQUENCE:0\r\nSUMMARY:Jossss\r\nUID:336-335\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"
|
43
50
|
|
@@ -45,11 +52,18 @@ It's pretty simple to use, I will post some examples:
|
|
45
52
|
create_appointment returns ics formatted data, for use with icalendar. Notice that the UID in the data is 336-335. This is an invitation id, not an appointment id.
|
46
53
|
The appointment id is 336, the first part of it.
|
47
54
|
|
48
|
-
The
|
55
|
+
The other methods of note:
|
49
56
|
|
50
57
|
zm.get_appointment(336) #takes appt id
|
51
58
|
|
52
|
-
zm.modify_appointment({
|
59
|
+
zm.modify_appointment({
|
60
|
+
:appointee_email => "neo@matrix.com",
|
61
|
+
:start_time => Time.now,
|
62
|
+
:end_time => (Time.now+2.hours),
|
63
|
+
:name => "Joss Whedon!!!",
|
64
|
+
:subject => "Hallelujah 2: The Electric Boogaloo",
|
65
|
+
:desc => "Yoda Fights Back", :inv_id => "336-335"
|
66
|
+
})
|
53
67
|
|
54
68
|
zm.cancel_appointment("336-335")
|
55
69
|
|
@@ -58,7 +72,7 @@ it seems Zimbra API only works with invitation, not appointment ids, when it com
|
|
58
72
|
|
59
73
|
zm.get_appt_summaries(Time.now-1.days, Time.now)
|
60
74
|
|
61
|
-
This just returns appointment Ics texts in an array.
|
75
|
+
This just returns appointment Ics texts in an array. First arg is a Time object representing start date, second arg is end date.
|
62
76
|
|
63
77
|
## Contributing
|
64
78
|
|
data/lib/zimbreasy.rb
CHANGED
data/lib/zimbreasy/account.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Zimbreasy
|
2
2
|
class Account
|
3
3
|
attr_accessor :user, :pass, :endpoint, :client, :soap_namespace, :zimbra_namespace
|
4
|
+
|
4
5
|
def initialize(user, pass, endpoint)
|
5
6
|
@user = user
|
6
7
|
@pass = pass
|
@@ -31,7 +32,7 @@ module Zimbreasy
|
|
31
32
|
end
|
32
33
|
|
33
34
|
@client.config.pretty_print_xml = true
|
34
|
-
@client.config.log =
|
35
|
+
@client.config.log = false
|
35
36
|
|
36
37
|
response = @client.request method do
|
37
38
|
soap.xml do |xml|
|
data/lib/zimbreasy/mail.rb
CHANGED
@@ -2,13 +2,14 @@ module Zimbreasy
|
|
2
2
|
class Mail
|
3
3
|
include Icalendar
|
4
4
|
attr_accessor :account, :zimbra_namespace
|
5
|
+
|
5
6
|
def initialize(account)
|
6
7
|
@account = account
|
7
8
|
@zimbra_namespace = "urn:zimbraMail"
|
8
9
|
end
|
9
10
|
|
10
11
|
#Params can contain the following:
|
11
|
-
#:
|
12
|
+
#:appointee_emails(req)
|
12
13
|
#:start_time(opt)
|
13
14
|
#:end_time(opt)
|
14
15
|
#:name(opt)
|
@@ -26,24 +27,36 @@ module Zimbreasy
|
|
26
27
|
appointment_xml_block(xml, params)
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
29
31
|
params.merge!({:appt_id => response.body[:create_appointment_response][:@inv_id]})
|
30
|
-
|
32
|
+
|
33
|
+
to_ical(params)
|
31
34
|
end
|
35
|
+
|
36
|
+
def get_free_busy(start_time, end_time, email)
|
37
|
+
start_time = start_time.to_i*1000 #it wants millis, to_i gives seconds.
|
38
|
+
end_time = end_time.to_i*1000
|
39
|
+
response = account.make_call("GetFreeBusyRequest") do |xml|
|
40
|
+
xml.GetFreeBusyRequest({"xmlns" => @zimbra_namespace, "s" => start_time, "e" => end_time}) do |xml|
|
41
|
+
xml.usr({"name" => email})
|
42
|
+
end
|
43
|
+
end
|
32
44
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
array = []
|
46
|
+
return response[:get_free_busy_response][:usr].reject { |k,v| k if k == :@id }.inject(Hash.new) do |hash, entry|
|
47
|
+
if entry[1].is_a?(Array)
|
48
|
+
array_of_times = entry[1].inject(Array.new) do |times_array, times_entry|
|
49
|
+
times_array << { :s => Time.at(times_entry[:@s].to_f/1000.0), :e => Time.at(times_entry[:@e].to_f/1000.0) }
|
50
|
+
times_array
|
51
|
+
end
|
52
|
+
hash[entry[0]] = array_of_times
|
53
|
+
else
|
54
|
+
hash[entry[0]] = [ {:s => Time.at(entry[1][:@s].to_f/1000.0), :e => Time.at(entry[1][:@e].to_f/1000.0)} ]
|
55
|
+
end
|
56
|
+
hash
|
42
57
|
end
|
43
|
-
|
44
|
-
calendar.to_ical
|
45
58
|
end
|
46
|
-
|
59
|
+
|
47
60
|
def get_appointment(appt_id)
|
48
61
|
response = account.make_call("GetAppointmentRequest") do |xml|
|
49
62
|
xml.GetAppointmentRequest({ "xmlns" => @zimbra_namespace, "id" => appt_id})
|
@@ -59,7 +72,7 @@ module Zimbreasy
|
|
59
72
|
:appt_id => appt_id
|
60
73
|
}
|
61
74
|
|
62
|
-
|
75
|
+
to_ical(hash)
|
63
76
|
end
|
64
77
|
|
65
78
|
def get_appt_summaries(start_date, end_date)
|
@@ -74,17 +87,31 @@ module Zimbreasy
|
|
74
87
|
|
75
88
|
appts = []
|
76
89
|
|
77
|
-
response[:get_appt_summaries_response][:appt].
|
90
|
+
if response[:get_appt_summaries_response][:appt].is_a?(Array)
|
91
|
+
response[:get_appt_summaries_response][:appt].each do |appt|
|
92
|
+
|
93
|
+
inst = appt[:inst]
|
94
|
+
|
95
|
+
hash = {
|
96
|
+
:start_time => Zimbreasy.zimbra_date(Time.at(inst[:@s].to_f/1000.0)),
|
97
|
+
:name => appt[:@name],
|
98
|
+
:appt_id => appt[:@id]
|
99
|
+
}
|
100
|
+
|
101
|
+
appts << to_ical(hash)
|
102
|
+
end
|
103
|
+
else
|
104
|
+
appt = response[:get_appt_summaries_response][:appt]
|
78
105
|
|
79
106
|
inst = appt[:inst]
|
80
|
-
|
107
|
+
|
81
108
|
hash = {
|
82
|
-
:start_time => Zimbreasy.zimbra_date(Time.at(inst[:@s].to_f/1000.0)),
|
83
|
-
:name => appt[:@name],
|
109
|
+
:start_time => Zimbreasy.zimbra_date(Time.at(inst[:@s].to_f/1000.0)),
|
110
|
+
:name => appt[:@name],
|
84
111
|
:appt_id => appt[:@id]
|
85
112
|
}
|
86
113
|
|
87
|
-
appts <<
|
114
|
+
appts << to_ical(hash)
|
88
115
|
end
|
89
116
|
|
90
117
|
appts
|
@@ -104,11 +131,11 @@ module Zimbreasy
|
|
104
131
|
end
|
105
132
|
end
|
106
133
|
|
107
|
-
|
134
|
+
to_ical(params.merge({:appt_id => params[:inv_id]}))
|
108
135
|
end
|
109
136
|
|
110
137
|
#returns true if it worked, inv_id is not appt_id, it's normally something like 320-319, the first number is appt_id.
|
111
|
-
def cancel_appointment(inv_id)
|
138
|
+
def cancel_appointment(inv_id, emails, subject=nil, content=nil)
|
112
139
|
unless inv_id and inv_id.is_a?(String) and inv_id.match(/-/) and inv_id.split("-").count==2 #so it has x-y formatting.
|
113
140
|
raise 'inv_id must be string of format x-y, where x and y are numbers.'
|
114
141
|
end
|
@@ -119,7 +146,23 @@ module Zimbreasy
|
|
119
146
|
"id" => inv_id,
|
120
147
|
"comp" => 0
|
121
148
|
}) do |xml|
|
122
|
-
|
149
|
+
|
150
|
+
xml.m do |xml|
|
151
|
+
emails.each do |email|
|
152
|
+
xml.e({"a" => email, "t" => "t"})
|
153
|
+
end
|
154
|
+
|
155
|
+
xml.su(subject)
|
156
|
+
|
157
|
+
xml.mp({"ct" => "text/plain"}) do |xml|
|
158
|
+
xml.content(content)
|
159
|
+
end
|
160
|
+
|
161
|
+
#xml.inv({"id" => inv_id, "method" => "none", "compNum" => "0", "rsvp" => "1"}) do |xml|
|
162
|
+
# xml.comp({"method" => "none", "compNum" => "0", "rsvp" => "1"}) do |xml|
|
163
|
+
# end
|
164
|
+
#end
|
165
|
+
end
|
123
166
|
end
|
124
167
|
end
|
125
168
|
|
@@ -128,6 +171,19 @@ module Zimbreasy
|
|
128
171
|
|
129
172
|
private
|
130
173
|
|
174
|
+
def to_ical(params)
|
175
|
+
calendar = Calendar.new
|
176
|
+
calendar.event do
|
177
|
+
dtstart params[:start_time]
|
178
|
+
dtend params[:end_time]
|
179
|
+
summary params[:name]
|
180
|
+
description params[:desc]
|
181
|
+
uid params[:appt_id]
|
182
|
+
klass "PRIVATE"
|
183
|
+
end
|
184
|
+
calendar.to_ical
|
185
|
+
end
|
186
|
+
|
131
187
|
def appointment_xml_block(xml, params)
|
132
188
|
xml.m({"su" => params[:subject]}) do |xml|
|
133
189
|
xml.mp({"ct" =>(params[:mime_type] || "text/plain")})
|
@@ -137,8 +193,9 @@ module Zimbreasy
|
|
137
193
|
xml.s({"d" => params[:start_time]}) if params[:start_time]
|
138
194
|
xml.e({"d" => params[:end_time]}) if params[:end_time]
|
139
195
|
end
|
140
|
-
|
141
|
-
|
196
|
+
params[:appointee_emails].each do |email|
|
197
|
+
xml.e({"a" => email, "t" => "t"})
|
198
|
+
end
|
142
199
|
end
|
143
200
|
end
|
144
201
|
end
|
data/lib/zimbreasy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zimbreasy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-unit
|
16
|
-
requirement: &
|
16
|
+
requirement: &10238380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *10238380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: savon
|
27
|
-
requirement: &
|
27
|
+
requirement: &10234600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *10234600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &10231340 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *10231340
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: icalendar
|
49
|
-
requirement: &
|
49
|
+
requirement: &10227460 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *10227460
|
58
58
|
description: A no-nonsense gem for the nonsensical Zimbra API.
|
59
59
|
email:
|
60
60
|
- jordanmprince@gmail.com
|