zimbra 0.0.4 → 0.0.5

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.
Files changed (53) hide show
  1. data/.gitignore +4 -0
  2. data/.irbrc +6 -0
  3. data/Gemfile +6 -0
  4. data/README +3 -2
  5. data/Rakefile +1 -0
  6. data/lib/zimbra.rb +31 -6
  7. data/lib/zimbra/appointment.rb +274 -0
  8. data/lib/zimbra/appointment/alarm.rb +101 -0
  9. data/lib/zimbra/appointment/attendee.rb +97 -0
  10. data/lib/zimbra/appointment/invite.rb +360 -0
  11. data/lib/zimbra/appointment/recur_exception.rb +83 -0
  12. data/lib/zimbra/appointment/recur_rule.rb +184 -0
  13. data/lib/zimbra/appointment/reply.rb +91 -0
  14. data/lib/zimbra/calendar.rb +27 -0
  15. data/lib/zimbra/delegate_auth_token.rb +49 -0
  16. data/lib/zimbra/ext/hash.rb +72 -0
  17. data/lib/zimbra/extra/date_helpers.rb +111 -0
  18. data/lib/zimbra/folder.rb +100 -0
  19. data/lib/zimbra/handsoap_account_service.rb +44 -0
  20. data/lib/zimbra/handsoap_service.rb +1 -1
  21. data/lib/zimbra/version.rb +3 -0
  22. data/spec/fixtures/xml_api_requests/appointments/create.xml +84 -0
  23. data/spec/fixtures/xml_api_responses/alarms/15_minutes_before.xml +26 -0
  24. data/spec/fixtures/xml_api_responses/alarms/using_all_intervals.xml +26 -0
  25. data/spec/fixtures/xml_api_responses/appointments/appointment_response_1.xml +40 -0
  26. data/spec/fixtures/xml_api_responses/attendees/one_attendee_and_one_reply.xml +27 -0
  27. data/spec/fixtures/xml_api_responses/attendees/three_attendees_response_1.xml +30 -0
  28. data/spec/fixtures/xml_api_responses/multiple_invites/recurring_with_exceptions.xml +109 -0
  29. data/spec/fixtures/xml_api_responses/recur_rules/day_27_of_every_2_months.xml +27 -0
  30. data/spec/fixtures/xml_api_responses/recur_rules/every_2_days.xml +26 -0
  31. data/spec/fixtures/xml_api_responses/recur_rules/every_3_weeks_on_tuesday_and_friday.xml +30 -0
  32. data/spec/fixtures/xml_api_responses/recur_rules/every_day_50_instances.xml +27 -0
  33. data/spec/fixtures/xml_api_responses/recur_rules/every_monday_wednesday_friday.xml +31 -0
  34. data/spec/fixtures/xml_api_responses/recur_rules/every_tuesday.xml +29 -0
  35. data/spec/fixtures/xml_api_responses/recur_rules/every_weekday_with_end_date.xml +34 -0
  36. data/spec/fixtures/xml_api_responses/recur_rules/every_year_on_february_2.xml +28 -0
  37. data/spec/fixtures/xml_api_responses/recur_rules/first_day_of_every_month.xml +36 -0
  38. data/spec/fixtures/xml_api_responses/recur_rules/first_monday_of_every_february.xml +31 -0
  39. data/spec/fixtures/xml_api_responses/recur_rules/first_weekend_day_of_every_month.xml +31 -0
  40. data/spec/fixtures/xml_api_responses/recur_rules/last_day_of_every_month.xml +36 -0
  41. data/spec/fixtures/xml_api_responses/recur_rules/second_day_of_every_2_months.xml +36 -0
  42. data/spec/fixtures/xml_api_responses/recur_rules/second_wednesday_of_every_month.xml +29 -0
  43. data/spec/fixtures/xml_api_responses/recur_rules/weekly_with_an_exception.xml +44 -0
  44. data/spec/spec_helper.rb +32 -0
  45. data/spec/zimbra/acl_spec.rb +11 -0
  46. data/spec/zimbra/appointment/alarm_spec.rb +33 -0
  47. data/spec/zimbra/appointment/invite_spec.rb +62 -0
  48. data/spec/zimbra/appointment/recur_rule_spec.rb +307 -0
  49. data/spec/zimbra/appointment_spec.rb +175 -0
  50. data/spec/zimbra/common_elements_spec.rb +33 -0
  51. data/spec/zimbra/distribution_list_spec.rb +54 -0
  52. data/zimbra.gemspec +28 -0
  53. metadata +165 -68
@@ -0,0 +1,31 @@
1
+ <appt uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" id="498" rev="27637" nextAlarm="1391460900000" d="1387472617000" s="0" l="10">
2
+ <inv id="497" seq="13" compNum="0" type="appt">
3
+ <tz id="America/New_York" stdoff="-300" stdname="EST" dayoff="-240" dayname="EDT">
4
+ <standard wkday="1" min="0" sec="0" mon="11" hour="2" week="1"/>
5
+ <daylight wkday="1" min="0" sec="0" mon="3" hour="2" week="2"/>
6
+ </tz>
7
+ <comp uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" d="1387472617000" status="CONF" noBlob="1" ciFolder="10" isOrg="1" class="PUB" loc="" compNum="0" apptId="498" url="" fb="B" calItemId="498" x_uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" name="RECURTEST" seq="13" rsvp="0" fba="B" method="PUBLISH" transp="O">
8
+ <alarm action="DISPLAY">
9
+ <trigger>
10
+ <rel neg="1" m="5" related="START"/>
11
+ </trigger>
12
+ <desc/>
13
+ </alarm>
14
+ <or d="Mail03" a="mail03@greenviewdata.com" url="mail03@greenviewdata.com"/>
15
+ <recur>
16
+ <add>
17
+ <rule freq="YEA">
18
+ <interval ival="1"/>
19
+ <byday>
20
+ <wkday day="MO"/>
21
+ </byday>
22
+ <bymonth molist="2"/>
23
+ <bysetpos poslist="1"/>
24
+ </rule>
25
+ </add>
26
+ </recur>
27
+ <s u="1391461200000" d="20140203T160000" tz="America/New_York"/>
28
+ <e u="1391464800000" d="20140203T170000" tz="America/New_York"/>
29
+ </comp>
30
+ </inv>
31
+ </appt>
@@ -0,0 +1,31 @@
1
+ <appt uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" id="498" rev="27635" nextAlarm="1391288100000" d="1387472533000" s="0" l="10">
2
+ <inv id="497" seq="11" compNum="0" type="appt">
3
+ <tz id="America/New_York" stdoff="-300" stdname="EST" dayoff="-240" dayname="EDT">
4
+ <standard wkday="1" min="0" sec="0" mon="11" hour="2" week="1"/>
5
+ <daylight wkday="1" min="0" sec="0" mon="3" hour="2" week="2"/>
6
+ </tz>
7
+ <comp uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" d="1387472533000" status="CONF" noBlob="1" ciFolder="10" isOrg="1" class="PUB" loc="" compNum="0" apptId="498" url="" fb="B" calItemId="498" x_uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" name="RECURTEST" seq="11" rsvp="0" fba="B" method="PUBLISH" transp="O">
8
+ <alarm action="DISPLAY">
9
+ <trigger>
10
+ <rel neg="1" m="5" related="START"/>
11
+ </trigger>
12
+ <desc/>
13
+ </alarm>
14
+ <or d="Mail03" a="mail03@greenviewdata.com" url="mail03@greenviewdata.com"/>
15
+ <recur>
16
+ <add>
17
+ <rule freq="MON">
18
+ <interval ival="1"/>
19
+ <byday>
20
+ <wkday day="SU"/>
21
+ <wkday day="SA"/>
22
+ </byday>
23
+ <bysetpos poslist="1"/>
24
+ </rule>
25
+ </add>
26
+ </recur>
27
+ <s u="1391288400000" d="20140201T160000" tz="America/New_York"/>
28
+ <e u="1391292000000" d="20140201T170000" tz="America/New_York"/>
29
+ </comp>
30
+ </inv>
31
+ </appt>
@@ -0,0 +1,36 @@
1
+ <appt uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" id="498" rev="27634" nextAlarm="1391201700000" d="1387472498000" s="0" l="10">
2
+ <inv id="497" seq="10" compNum="0" type="appt">
3
+ <tz id="America/New_York" stdoff="-300" stdname="EST" dayoff="-240" dayname="EDT">
4
+ <standard wkday="1" min="0" sec="0" mon="11" hour="2" week="1"/>
5
+ <daylight wkday="1" min="0" sec="0" mon="3" hour="2" week="2"/>
6
+ </tz>
7
+ <comp uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" d="1387472498000" status="CONF" noBlob="1" ciFolder="10" isOrg="1" class="PUB" loc="" compNum="0" apptId="498" url="" fb="B" calItemId="498" x_uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" name="RECURTEST" seq="10" rsvp="0" fba="B" method="PUBLISH" transp="O">
8
+ <alarm action="DISPLAY">
9
+ <trigger>
10
+ <rel neg="1" m="5" related="START"/>
11
+ </trigger>
12
+ <desc/>
13
+ </alarm>
14
+ <or d="Mail03" a="mail03@greenviewdata.com" url="mail03@greenviewdata.com"/>
15
+ <recur>
16
+ <add>
17
+ <rule freq="MON">
18
+ <interval ival="1"/>
19
+ <byday>
20
+ <wkday day="SU"/>
21
+ <wkday day="MO"/>
22
+ <wkday day="TU"/>
23
+ <wkday day="WE"/>
24
+ <wkday day="TH"/>
25
+ <wkday day="FR"/>
26
+ <wkday day="SA"/>
27
+ </byday>
28
+ <bysetpos poslist="-1"/>
29
+ </rule>
30
+ </add>
31
+ </recur>
32
+ <s u="1391202000000" d="20140131T160000" tz="America/New_York"/>
33
+ <e u="1391205600000" d="20140131T170000" tz="America/New_York"/>
34
+ </comp>
35
+ </inv>
36
+ </appt>
@@ -0,0 +1,36 @@
1
+ <appt uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" id="498" rev="27633" nextAlarm="1388696100000" d="1387472467000" s="0" l="10">
2
+ <inv id="497" seq="9" compNum="0" type="appt">
3
+ <tz id="America/New_York" stdoff="-300" stdname="EST" dayoff="-240" dayname="EDT">
4
+ <standard wkday="1" min="0" sec="0" mon="11" hour="2" week="1"/>
5
+ <daylight wkday="1" min="0" sec="0" mon="3" hour="2" week="2"/>
6
+ </tz>
7
+ <comp uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" d="1387472467000" status="CONF" noBlob="1" ciFolder="10" isOrg="1" class="PUB" loc="" compNum="0" apptId="498" url="" fb="B" calItemId="498" x_uid="1b33102b-6d2e-4d98-ad27-c59a92de9798" name="RECURTEST" seq="9" rsvp="0" fba="B" method="PUBLISH" transp="O">
8
+ <alarm action="DISPLAY">
9
+ <trigger>
10
+ <rel neg="1" m="5" related="START"/>
11
+ </trigger>
12
+ <desc/>
13
+ </alarm>
14
+ <or d="Mail03" a="mail03@greenviewdata.com" url="mail03@greenviewdata.com"/>
15
+ <recur>
16
+ <add>
17
+ <rule freq="MON">
18
+ <interval ival="2"/>
19
+ <byday>
20
+ <wkday day="SU"/>
21
+ <wkday day="MO"/>
22
+ <wkday day="TU"/>
23
+ <wkday day="WE"/>
24
+ <wkday day="TH"/>
25
+ <wkday day="FR"/>
26
+ <wkday day="SA"/>
27
+ </byday>
28
+ <bysetpos poslist="2"/>
29
+ </rule>
30
+ </add>
31
+ </recur>
32
+ <s u="1388696400000" d="20140102T160000" tz="America/New_York"/>
33
+ <e u="1388700000000" d="20140102T170000" tz="America/New_York"/>
34
+ </comp>
35
+ </inv>
36
+ </appt>
@@ -0,0 +1,29 @@
1
+ <appt uid="1c71d474-5c1f-4048-84e3-9725c0825a44" id="518" rev="27656" nextAlarm="1389209100000" d="1387571704000" s="0" l="10">
2
+ <inv id="517" seq="4" compNum="0" type="appt">
3
+ <tz id="America/New_York" stdoff="-300" stdname="EST" dayoff="-240" dayname="EDT">
4
+ <standard wkday="1" min="0" sec="0" mon="11" hour="2" week="1"/>
5
+ <daylight wkday="1" min="0" sec="0" mon="3" hour="2" week="2"/>
6
+ </tz>
7
+ <comp uid="1c71d474-5c1f-4048-84e3-9725c0825a44" d="1387571704000" status="CONF" noBlob="1" ciFolder="10" isOrg="1" class="PUB" loc="" compNum="0" apptId="518" url="" fb="B" calItemId="518" x_uid="1c71d474-5c1f-4048-84e3-9725c0825a44" name="Test2222" seq="4" rsvp="0" fba="B" method="PUBLISH" transp="O">
8
+ <alarm action="DISPLAY">
9
+ <trigger>
10
+ <rel neg="1" m="5" related="START"/>
11
+ </trigger>
12
+ <desc/>
13
+ </alarm>
14
+ <or d="Mail03" a="mail03@greenviewdata.com" url="mail03@greenviewdata.com"/>
15
+ <recur>
16
+ <add>
17
+ <rule freq="MON">
18
+ <interval ival="1"/>
19
+ <byday>
20
+ <wkday ordwk="2" day="WE"/>
21
+ </byday>
22
+ </rule>
23
+ </add>
24
+ </recur>
25
+ <s u="1355340600000" d="20121212T143000" tz="America/New_York"/>
26
+ <e u="1355344200000" d="20121212T153000" tz="America/New_York"/>
27
+ </comp>
28
+ </inv>
29
+ </appt>
@@ -0,0 +1,44 @@
1
+ <appt uid="1c71d474-5c1f-4048-84e3-9725c0825a44" id="518" rev="27644" nextAlarm="1388087700000" d="1387483796000" s="0" l="10">
2
+ <inv id="517" seq="0" compNum="0" type="appt">
3
+ <tz id="America/New_York" stdoff="-300" stdname="EST" dayoff="-240" dayname="EDT">
4
+ <standard wkday="1" min="0" sec="0" mon="11" hour="2" week="1"/>
5
+ <daylight wkday="1" min="0" sec="0" mon="3" hour="2" week="2"/>
6
+ </tz>
7
+ <comp uid="1c71d474-5c1f-4048-84e3-9725c0825a44" d="1387483787000" status="CONF" noBlob="1" ciFolder="10" isOrg="1" class="PUB" loc="" compNum="0" apptId="518" url="" fb="B" calItemId="518" x_uid="1c71d474-5c1f-4048-84e3-9725c0825a44" name="Test" seq="0" rsvp="0" fba="B" method="PUBLISH" transp="O">
8
+ <alarm action="DISPLAY">
9
+ <trigger>
10
+ <rel neg="1" m="5" related="START"/>
11
+ </trigger>
12
+ <desc/>
13
+ </alarm>
14
+ <or d="Mail03" a="mail03@greenviewdata.com" url="mail03@greenviewdata.com"/>
15
+ <recur>
16
+ <add>
17
+ <rule freq="WEE">
18
+ <interval ival="1"/>
19
+ </rule>
20
+ </add>
21
+ </recur>
22
+ <s u="1387481400000" d="20131219T143000" tz="America/New_York"/>
23
+ <e u="1387485000000" d="20131219T153000" tz="America/New_York"/>
24
+ </comp>
25
+ </inv>
26
+ <inv id="519" recurId="TZID=America/New_York:20131226T143000" seq="1" compNum="0" type="appt">
27
+ <tz id="America/New_York" stdoff="-300" stdname="EST" dayoff="-240" dayname="EDT">
28
+ <standard wkday="1" min="0" sec="0" mon="11" hour="2" week="1"/>
29
+ <daylight wkday="1" min="0" sec="0" mon="3" hour="2" week="2"/>
30
+ </tz>
31
+ <comp uid="1c71d474-5c1f-4048-84e3-9725c0825a44" ex="1" d="1387483796000" status="CONF" noBlob="1" ciFolder="10" isOrg="1" class="PUB" loc="" compNum="0" apptId="518" url="" fb="B" calItemId="518" x_uid="1c71d474-5c1f-4048-84e3-9725c0825a44" ridZ="20131226T193000Z" name="Test" seq="1" rsvp="0" fba="B" method="PUBLISH" transp="O">
32
+ <alarm action="DISPLAY">
33
+ <trigger>
34
+ <rel neg="1" m="5" related="START"/>
35
+ </trigger>
36
+ <desc/>
37
+ </alarm>
38
+ <or d="Mail03" a="mail03@greenviewdata.com" url="mail03@greenviewdata.com"/>
39
+ <exceptId d="20131226T143000" tz="America/New_York"/>
40
+ <s u="1388088000000" d="20131226T150000" tz="America/New_York"/>
41
+ <e u="1388091600000" d="20131226T160000" tz="America/New_York"/>
42
+ </comp>
43
+ </inv>
44
+ </appt>
@@ -0,0 +1,32 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__),'../lib'))
2
+ require 'zimbra'
3
+ require 'nokogiri'
4
+
5
+ def zimbra_soap_doc(xml)
6
+ Nokogiri::XML.parse(<<XML)
7
+ <?xml version="1.0" encoding="UTF-8"?>
8
+ <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:n2="http://foo.bar/baz">
9
+ <soap:Header>
10
+ <context xmlns="urn:zimbra"/>
11
+ </soap:Header>
12
+ <soap:Body>
13
+ #{xml}
14
+ </soap:Body>
15
+ </soap:Envelope>
16
+ XML
17
+ end
18
+
19
+ def new_appointment_from_xml(xml_path)
20
+ xml = File.read(xml_path)
21
+ appointment_hash = Zimbra::Hash.from_xml(xml)
22
+ Zimbra::Appointment.new_from_zimbra_attributes(appointment_hash)
23
+ end
24
+
25
+ RSpec.configure do |config|
26
+
27
+ config.before(:each) do
28
+ @fixture_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures')
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__),'../spec_helper')
2
+
3
+ describe Zimbra::ACL do
4
+ describe 'to_zimbra_acl_value' do
5
+ it 'should generate the string to be placed in an acl element' do
6
+ domain = Zimbra::Domain.new('abc123','example.com')
7
+ acl = Zimbra::ACL.new(:target => domain, :name => 'zimbraAdminCosRights')
8
+ acl.to_zimbra_acl_value.should == "abc123 domain zimbraAdminCosRights"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zimbra::Appointment::Alarm do
4
+ before do
5
+ @xml_api_responses_path = File.join(@fixture_path, 'xml_api_responses', 'alarms')
6
+ end
7
+
8
+ describe ".new_from_zimbra_attributes" do
9
+ @sample_attribute_files = {
10
+ '15_minutes_before.xml' => {
11
+ :duration_negative=>true, :weeks=>nil, :days=>nil, :hours=>nil, :minutes=>15, :seconds=>nil, :when=>:start, :repeat_count=>nil
12
+ },
13
+ 'using_all_intervals.xml' => {
14
+ :duration_negative=>false, :weeks=>1, :days=>2, :hours=>3, :minutes=>15, :seconds=>25, :when=>:end, :repeat_count=>2
15
+ }
16
+ }
17
+
18
+ @sample_attribute_files.each do |file_name, expected_attributes|
19
+ context file_name do
20
+ before do
21
+ @attributes = Zimbra::Hash.from_xml(File.read(File.join(@xml_api_responses_path, file_name)))
22
+ @attributes = @attributes[:appt][:inv][:comp][:alarm]
23
+ @alarm = Zimbra::Appointment::Alarm.new_from_zimbra_attributes(@attributes)
24
+ end
25
+
26
+ it "should match the expected attributes" do
27
+ @alarm.to_hash.should == expected_attributes
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zimbra::Appointment::Invite do
4
+ before do
5
+ @xml_api_responses_path = File.join(@fixture_path, 'xml_api_responses', 'multiple_invites')
6
+ @appointment = new_appointment_from_xml(File.join(@xml_api_responses_path, 'recurring_with_exceptions.xml'))
7
+ end
8
+
9
+ describe "#exception" do
10
+ before do
11
+ @invite = @appointment.invites.find { |i| i.id == 549 }
12
+ end
13
+ it "should be set if this invite is an exception" do
14
+ @invite.exception.to_hash.should == {:recurrence_id=>"20140131T090000", :timezone=>"America/New_York", :range_type=>nil}
15
+ end
16
+ end
17
+
18
+ describe "basic attributes" do
19
+ it "should set the description" do
20
+ @appointment.invites.first.description.should == "This is a recurring series"
21
+ end
22
+ it "should set the fragment" do
23
+ @appointment.invites.first.fragment.should == "This is a recurring series"
24
+ end
25
+ it "should set the organizer_email_address" do
26
+ @appointment.invites.first.organizer_email_address.should == 'mail03@greenviewdata.com'
27
+ end
28
+ it "should set is_organizer" do
29
+ @appointment.invites.first.is_organizer.should be_true
30
+ end
31
+ it "should set the name" do
32
+ @appointment.invites.first.name.should == 'fdsafdsafdsafdsafdsafdsa'
33
+ end
34
+ it "should set the computed_free_busy_status" do
35
+ @appointment.invites.first.computed_free_busy_status.should == :busy
36
+ end
37
+ it "should set the free_busy_setting" do
38
+ @appointment.invites.first.free_busy_setting.should == :busy
39
+ end
40
+ it "should set the invite_status" do
41
+ @appointment.invites.first.invite_status.should == :confirmed
42
+ end
43
+ it "should set all_day" do
44
+ @appointment.invites.first.all_day.should be_false
45
+ end
46
+ it "should set the visibility" do
47
+ @appointment.invites.first.visibility.should == :public
48
+ end
49
+ it "should set the location" do
50
+ @appointment.invites.first.location.should == 'Conference Room'
51
+ end
52
+ it "should set transparency" do
53
+ @appointment.invites.first.transparency.should == :opaque
54
+ end
55
+ it "should set start_date_time" do
56
+ @appointment.invites.first.start_date_time.should == Time.parse("2013-12-09 09:00:00 -0500")
57
+ end
58
+ it "should set end_date_time" do
59
+ @appointment.invites.first.end_date_time.should == Time.parse("2013-12-09 09:30:00 -0500")
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,307 @@
1
+ require 'spec_helper'
2
+
3
+ describe Zimbra::Appointment::RecurRule do
4
+ before do
5
+ @xml_api_responses_path = File.join(@fixture_path, 'xml_api_responses', 'recur_rules')
6
+ end
7
+
8
+ describe "#create_xml" do
9
+ @sample_attribute_files = [
10
+ 'second_wednesday_of_every_month.xml',
11
+ 'day_27_of_every_2_months.xml',
12
+ 'every_2_days.xml',
13
+ 'every_3_weeks_on_tuesday_and_friday.xml',
14
+ 'every_day_50_instances.xml',
15
+ 'every_monday_wednesday_friday.xml',
16
+ 'every_tuesday.xml',
17
+ 'every_weekday_with_end_date.xml',
18
+ 'every_year_on_february_2.xml',
19
+ 'first_day_of_every_month.xml',
20
+ 'first_monday_of_every_february.xml',
21
+ 'first_weekend_day_of_every_month.xml',
22
+ 'last_day_of_every_month.xml',
23
+ 'second_day_of_every_2_months.xml'
24
+ ]
25
+
26
+ @sample_attribute_files.each do |file_name|
27
+ context file_name do
28
+ before do
29
+ @xml = File.read(File.join(@xml_api_responses_path, file_name))
30
+ @attributes = Zimbra::Hash.from_xml(@xml)
31
+ @attributes = @attributes[:appt][:inv][:comp][:recur]
32
+ @recur_rule = Zimbra::Appointment::RecurRule.new_from_zimbra_attributes(@attributes)
33
+ end
34
+
35
+ it "should match the expected attributes" do
36
+ document = Handsoap::XmlMason::Document.new do |doc|
37
+ doc.add "add" do |add_element|
38
+ @recur_rule.create_xml(add_element)
39
+ end
40
+ end
41
+
42
+ parsed_xml = Zimbra::Hash.from_xml(document.to_s)
43
+ parsed_xml.should == @attributes
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ describe ".new" do
50
+ @sample_attribute_files = {
51
+ 'second_wednesday_of_every_month.xml' => {
52
+ :frequency => :monthly,
53
+ :interval => 1,
54
+ :by_day => [
55
+ { :day => :wednesday, :week_number => 2 }
56
+ ]
57
+ },
58
+ 'day_27_of_every_2_months.xml' => {
59
+ frequency: :monthly,
60
+ interval: 2,
61
+ by_month_day: [27]
62
+ },
63
+ 'every_2_days.xml' => {
64
+ frequency: :daily,
65
+ interval: 2
66
+ },
67
+ 'every_3_weeks_on_tuesday_and_friday.xml' => {
68
+ :frequency=>:weekly,
69
+ :interval=>3,
70
+ :by_day => [
71
+ { :day => :tuesday },
72
+ { :day => :friday }
73
+ ]
74
+ },
75
+ 'every_day_50_instances.xml' => {
76
+ :frequency => :daily,
77
+ :interval => 1,
78
+ :count => 50
79
+ },
80
+ 'every_monday_wednesday_friday.xml' => {
81
+ :frequency => :weekly,
82
+ :interval => 1,
83
+ :by_day => [
84
+ {:day=> :monday},
85
+ {:day=> :wednesday},
86
+ {:day=> :friday}
87
+ ]
88
+ },
89
+ 'every_tuesday.xml' => {
90
+ :frequency=>:weekly,
91
+ :interval=>1,
92
+ :by_day=>[
93
+ {:day=>:tuesday}
94
+ ]
95
+ },
96
+ 'every_weekday_with_end_date.xml' => {
97
+ :frequency=>:daily,
98
+ :until_date=>Time.parse("20131220T045959Z"),
99
+ :interval=>1,
100
+ :by_day=>[
101
+ {:day=>:monday},
102
+ {:day=>:tuesday},
103
+ {:day=>:wednesday},
104
+ {:day=>:thursday},
105
+ {:day=>:friday}
106
+ ]
107
+ },
108
+ 'every_year_on_february_2.xml' => {
109
+ :frequency=>:yearly,
110
+ :interval=>1,
111
+ :by_month_day=>[2],
112
+ :by_month => [2]
113
+ },
114
+ 'first_day_of_every_month.xml' => {
115
+ :frequency=>:monthly,
116
+ :interval=>1,
117
+ :by_day=>[
118
+ {:day=>:sunday},
119
+ {:day=>:monday},
120
+ {:day=>:tuesday},
121
+ {:day=>:wednesday},
122
+ {:day=>:thursday},
123
+ {:day=>:friday},
124
+ {:day=>:saturday}
125
+ ],
126
+ :by_set_position => [1]
127
+ },
128
+ 'first_monday_of_every_february.xml' => {
129
+ :frequency=>:yearly,
130
+ :interval=>1,
131
+ :by_set_position=>[1],
132
+ :by_day=>[
133
+ {:day=>:monday}
134
+ ],
135
+ :by_month=>[2]
136
+ },
137
+ 'first_weekend_day_of_every_month.xml' => {
138
+ :frequency=>:monthly,
139
+ :interval=>1,
140
+ :by_set_position=>[1],
141
+ :by_day=>[
142
+ {:day=>:sunday},
143
+ {:day=>:saturday}
144
+ ]
145
+ },
146
+ 'last_day_of_every_month.xml' => {
147
+ :frequency=>:monthly,
148
+ :interval=>1,
149
+ :by_set_position=>[-1],
150
+ :by_day=>[
151
+ {:day=>:sunday},
152
+ {:day=>:monday},
153
+ {:day=>:tuesday},
154
+ {:day=>:wednesday},
155
+ {:day=>:thursday},
156
+ {:day=>:friday},
157
+ {:day=>:saturday}
158
+ ]
159
+ },
160
+ 'second_day_of_every_2_months.xml' => {
161
+ :frequency=>:monthly,
162
+ :interval=>2,
163
+ :by_set_position=>[2],
164
+ :by_day=>[
165
+ {:day=>:sunday},
166
+ {:day=>:monday},
167
+ {:day=>:tuesday},
168
+ {:day=>:wednesday},
169
+ {:day=>:thursday},
170
+ {:day=>:friday},
171
+ {:day=>:saturday}
172
+ ]
173
+ }
174
+ #'weekly_with_an_exception.xml' => {}
175
+ }
176
+
177
+ @sample_attribute_files.each do |file_name, expected_attributes|
178
+ context file_name do
179
+ before do
180
+ @attributes = Zimbra::Hash.from_xml(File.read(File.join(@xml_api_responses_path, file_name)))
181
+ @attributes = @attributes[:appt][:inv][:comp][:recur]
182
+ @recur_rule = Zimbra::Appointment::RecurRule.new_from_zimbra_attributes(@attributes)
183
+ end
184
+
185
+ it "should match the expected attributes" do
186
+ @recur_rule.to_hash.should == expected_attributes
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ describe ".parse_zimbra_attributes" do
193
+
194
+ @sample_attribute_files = {
195
+ 'second_wednesday_of_every_month.xml' => {
196
+ :frequency => "MON",
197
+ :interval => 1,
198
+ :by_day => [
199
+ { :day => 'WE', :week_number => 2 }
200
+ ]
201
+ },
202
+ 'day_27_of_every_2_months.xml' => {
203
+ frequency: "MON",
204
+ interval: 2,
205
+ by_month_day: [27]
206
+ },
207
+ 'every_2_days.xml' => {
208
+ frequency: 'DAI',
209
+ interval: 2
210
+ },
211
+ 'every_3_weeks_on_tuesday_and_friday.xml' => {
212
+ :frequency=>"WEE",
213
+ :interval=>3,
214
+ :by_day => [
215
+ {:day=>"TU"},
216
+ {:day=>"FR"}
217
+ ]
218
+ },
219
+ 'every_day_50_instances.xml' => {
220
+ :frequency => "DAI",
221
+ :interval => 1,
222
+ :count => 50
223
+ },
224
+ 'every_monday_wednesday_friday.xml' => {
225
+ :frequency => "WEE",
226
+ :interval => 1,
227
+ :by_day => [
228
+ {:day=>"MO"},
229
+ {:day=>"WE"},
230
+ {:day=>"FR"}
231
+ ]
232
+ },
233
+ 'every_tuesday.xml' => {
234
+ :frequency=>"WEE",
235
+ :interval=>1,
236
+ :by_day=>[
237
+ {:day=>"TU"}
238
+ ]
239
+ },
240
+ 'every_weekday_with_end_date.xml' => {
241
+ :frequency=>"DAI",
242
+ :until_date=>"20131220T045959Z",
243
+ :interval=>1,
244
+ :by_day=>[
245
+ {:day=>"MO"},
246
+ {:day=>"TU"},
247
+ {:day=>"WE"},
248
+ {:day=>"TH"},
249
+ {:day=>"FR"}
250
+ ]
251
+ },
252
+ 'every_year_on_february_2.xml' => {
253
+ :frequency=>"YEA",
254
+ :interval=>1,
255
+ :by_month_day=>[2],
256
+ :by_month => [2]
257
+ },
258
+ 'first_day_of_every_month.xml' => {
259
+ :frequency=>"MON",
260
+ :interval=>1,
261
+ :by_day=>[
262
+ {:day=>"SU"}, {:day=>"MO"}, {:day=>"TU"}, {:day=>"WE"}, {:day=>"TH"}, {:day=>"FR"}, {:day=>"SA"}
263
+ ],
264
+ :by_set_position => [1]
265
+ },
266
+ 'first_monday_of_every_february.xml' => {
267
+ :frequency=>"YEA",
268
+ :interval=>1,
269
+ :by_set_position=>[1],
270
+ :by_day=>[{:day=>"MO"}],
271
+ :by_month=>[2]
272
+ },
273
+ 'first_weekend_day_of_every_month.xml' => {
274
+ :frequency=>"MON",
275
+ :interval=>1,
276
+ :by_set_position=>[1],
277
+ :by_day=>[{:day=>"SU"}, {:day=>"SA"}]
278
+ },
279
+ 'last_day_of_every_month.xml' => {
280
+ :frequency=>"MON",
281
+ :interval=>1,
282
+ :by_set_position=>[-1],
283
+ :by_day=>[{:day=>"SU"}, {:day=>"MO"}, {:day=>"TU"}, {:day=>"WE"}, {:day=>"TH"}, {:day=>"FR"}, {:day=>"SA"}]
284
+ },
285
+ 'second_day_of_every_2_months.xml' => {
286
+ :frequency=>"MON",
287
+ :interval=>2,
288
+ :by_set_position=>[2],
289
+ :by_day=>[{:day=>"SU"}, {:day=>"MO"}, {:day=>"TU"}, {:day=>"WE"}, {:day=>"TH"}, {:day=>"FR"}, {:day=>"SA"}]
290
+ }
291
+ #'weekly_with_an_exception.xml' => {}
292
+ }
293
+
294
+ @sample_attribute_files.each do |file_name, expected_attributes|
295
+ context file_name do
296
+ before do
297
+ @attributes = Zimbra::Hash.from_xml(File.read(File.join(@xml_api_responses_path, file_name)))
298
+ @attributes = @attributes[:appt][:inv][:comp][:recur]
299
+ end
300
+
301
+ it "should match the expected attributes" do
302
+ Zimbra::Appointment::RecurRule.parse_zimbra_attributes(@attributes).should == expected_attributes
303
+ end
304
+ end
305
+ end
306
+ end
307
+ end