gcalapi 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +13 -0
- data/Rakefile +82 -0
- data/VERSION +1 -0
- data/example/mail2gcal.rb +101 -0
- data/example/ol2gcal.rb +55 -0
- data/html/classes/GoogleCalendar.html +281 -0
- data/html/classes/GoogleCalendar/AuthenticationFailed.html +111 -0
- data/html/classes/GoogleCalendar/Calendar.html +204 -0
- data/html/classes/GoogleCalendar/Event.html +511 -0
- data/html/classes/GoogleCalendar/EventDeleteFailed.html +111 -0
- data/html/classes/GoogleCalendar/EventInsertFailed.html +111 -0
- data/html/classes/GoogleCalendar/EventUpdateFailed.html +111 -0
- data/html/classes/GoogleCalendar/InvalidCalendarURL.html +111 -0
- data/html/classes/GoogleCalendar/Service.html +472 -0
- data/html/created.rid +1 -0
- data/html/files/README.html +117 -0
- data/html/files/lib/googlecalendar/calendar_rb.html +110 -0
- data/html/files/lib/googlecalendar/event_rb.html +110 -0
- data/html/files/lib/googlecalendar/service_rb.html +114 -0
- data/html/fr_class_index.html +35 -0
- data/html/fr_file_index.html +30 -0
- data/html/fr_method_index.html +49 -0
- data/html/index.html +24 -0
- data/html/rdoc-style.css +208 -0
- data/lib/googlecalendar/calendar.rb +117 -0
- data/lib/googlecalendar/event.rb +283 -0
- data/lib/googlecalendar/service.rb +193 -0
- data/test/00_service_test.rb +169 -0
- data/test/01_calendar_test.rb +52 -0
- data/test/02_event_test.rb +60 -0
- data/test/all.sh +2 -0
- data/test/base_unit.rb +54 -0
- data/test/each.sh +2 -0
- metadata +85 -0
@@ -0,0 +1,169 @@
|
|
1
|
+
require "base_unit"
|
2
|
+
|
3
|
+
class TestService < Test::Unit::TestCase
|
4
|
+
include GoogleCalendar
|
5
|
+
include CalendarTest
|
6
|
+
|
7
|
+
def test_invalid_auth
|
8
|
+
s = GoogleCalendar::Service.new("invalid@example.com", "invalidpassword")
|
9
|
+
assert_raise(GoogleCalendar::AuthenticationFailed) do
|
10
|
+
s.calendar_list
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_calendar_list
|
15
|
+
ret = @srv.calendar_list
|
16
|
+
assert_equal("200", ret.code, ret.body)
|
17
|
+
xml = nil
|
18
|
+
assert_nothing_raised { xml = REXML::Document.new(ret.body) }
|
19
|
+
list = xml.root.elements.each("entry/link") {}.map {|e| e.attributes["href"] if e.attributes["rel"] == "alternate"}.compact
|
20
|
+
assert(list.include?(FEED.gsub(/@/,"%40")))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_insert_and_delete_event
|
24
|
+
st = Time.now
|
25
|
+
en = st + 3600
|
26
|
+
ret = @srv.insert(FEED, event("title", "desc", st, en))
|
27
|
+
assert_equal("201", ret.code, ret.body)
|
28
|
+
xml = nil
|
29
|
+
assert_nothing_raised { xml = REXML::Document.new(ret.body) }
|
30
|
+
feed = get_feed_from_entry(xml)
|
31
|
+
assert_not_nil(feed)
|
32
|
+
assert_instance_of(String, feed)
|
33
|
+
ret = @srv.delete(feed)
|
34
|
+
assert_equal("200", ret.code, ret.body)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_insert_and_update_event
|
38
|
+
#insert
|
39
|
+
st = Time.now
|
40
|
+
en = st + 7200
|
41
|
+
ret = @srv.insert(FEED, event("title1", "desc1", st, en))
|
42
|
+
assert_equal("201", ret.code, ret.body)
|
43
|
+
|
44
|
+
#update
|
45
|
+
e1 = REXML::Document.new(ret.body)
|
46
|
+
e1.root.elements["content"].text = "desc2"
|
47
|
+
feed1 = get_feed_from_entry(e1)
|
48
|
+
ret = @srv.update(feed1, e1.to_s)
|
49
|
+
assert_equal("200", ret.code, ret.body)
|
50
|
+
e2 = REXML::Document.new(ret.body)
|
51
|
+
assert_equal("desc2", e2.root.elements["content"].text)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_query_without_range
|
55
|
+
ret = @srv.query(FEED, {})
|
56
|
+
entries = get_entry_from_query(ret)
|
57
|
+
assert_equal(0, entries.length)
|
58
|
+
|
59
|
+
ret = @srv.insert(FEED, event("t","d", Time.now, Time.now))
|
60
|
+
assert_equal("201", ret.code)
|
61
|
+
ret = @srv.query(FEED, {})
|
62
|
+
entries = get_entry_from_query(ret)
|
63
|
+
assert_equal(1, entries.length)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_query_start
|
67
|
+
t1, t2, t3, t4 = prepare_data
|
68
|
+
|
69
|
+
ret = @srv.query(FEED, :'start-min'=>t2, :'start-max'=>t3+1, :orderby=>'starttime')
|
70
|
+
ens = get_entry_from_query(ret)
|
71
|
+
assert_equal(2, ens.length)
|
72
|
+
assert_equal("t3", ens[0].elements["title"].text)
|
73
|
+
assert_equal("t2", ens[1].elements["title"].text)
|
74
|
+
|
75
|
+
ret = @srv.query(FEED, :'start-min'=>t2, :'start-max'=>t3, :orderby=>'starttime')
|
76
|
+
ens = get_entry_from_query(ret)
|
77
|
+
assert_equal(1, ens.length)
|
78
|
+
assert_equal("t2", ens[0].elements["title"].text)
|
79
|
+
|
80
|
+
ret = @srv.query(FEED, :'start-min'=>t2, :orderby=>'starttime')
|
81
|
+
ens = get_entry_from_query(ret)
|
82
|
+
assert_equal(3, ens.length)
|
83
|
+
assert_equal("t4", ens[0].elements["title"].text)
|
84
|
+
assert_equal("t3", ens[1].elements["title"].text)
|
85
|
+
assert_equal("t2", ens[2].elements["title"].text)
|
86
|
+
|
87
|
+
ret = @srv.query(FEED, :'start-max'=>t3, :orderby=>'starttime')
|
88
|
+
ens = get_entry_from_query(ret)
|
89
|
+
assert_equal(2, ens.length)
|
90
|
+
assert_equal("t2", ens[0].elements["title"].text)
|
91
|
+
assert_equal("t1", ens[1].elements["title"].text)
|
92
|
+
|
93
|
+
ret = @srv.query(FEED, :'start-max'=>t3+1, :orderby=>'starttime')
|
94
|
+
ens = get_entry_from_query(ret)
|
95
|
+
assert_equal(3, ens.length)
|
96
|
+
assert_equal("t3", ens[0].elements["title"].text)
|
97
|
+
assert_equal("t2", ens[1].elements["title"].text)
|
98
|
+
assert_equal("t1", ens[2].elements["title"].text)
|
99
|
+
|
100
|
+
ret = @srv.query(FEED, :orderby=>'starttime')
|
101
|
+
ens = get_entry_from_query(ret)
|
102
|
+
assert_equal(4, ens.length)
|
103
|
+
assert_equal("t4", ens[0].elements["title"].text)
|
104
|
+
assert_equal("t3", ens[1].elements["title"].text)
|
105
|
+
assert_equal("t2", ens[2].elements["title"].text)
|
106
|
+
assert_equal("t1", ens[3].elements["title"].text)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_query_q
|
110
|
+
prepare_data
|
111
|
+
|
112
|
+
ret = @srv.query(FEED, :q => 't1')
|
113
|
+
ens = get_entry_from_query(ret)
|
114
|
+
assert_equal(1, ens.length)
|
115
|
+
assert_equal("t1", ens[0].elements["title"].text)
|
116
|
+
|
117
|
+
ret = @srv.query(FEED, :q => 'd3')
|
118
|
+
ens = get_entry_from_query(ret)
|
119
|
+
assert_equal(1, ens.length)
|
120
|
+
assert_equal("t3", ens[0].elements["title"].text)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_query_max_result
|
124
|
+
prepare_data
|
125
|
+
|
126
|
+
ret = @srv.query(FEED, "max-results" => 2, :orderby => "starttime")
|
127
|
+
ens = get_entry_from_query(ret)
|
128
|
+
assert_equal(2, ens.length)
|
129
|
+
assert_equal("t4", ens[0].elements["title"].text)
|
130
|
+
assert_equal("t3", ens[1].elements["title"].text)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_query_default_order
|
134
|
+
prepare_data
|
135
|
+
|
136
|
+
ret = @srv.query(FEED, {})
|
137
|
+
ens = get_entry_from_query(ret)
|
138
|
+
assert_equal(4, ens.length)
|
139
|
+
assert_equal("t1", ens[0].elements["title"].text)
|
140
|
+
assert_equal("t2", ens[1].elements["title"].text)
|
141
|
+
assert_equal("t3", ens[2].elements["title"].text)
|
142
|
+
assert_equal("t4", ens[3].elements["title"].text)
|
143
|
+
end
|
144
|
+
|
145
|
+
def setup
|
146
|
+
@srv = get_service
|
147
|
+
clear_all(@srv, FEED)
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
def prepare_data
|
152
|
+
t1 = Time.parse("2006-09-12 01:00:00")
|
153
|
+
t2 = t1 + 3600
|
154
|
+
t3 = t2 + 3600
|
155
|
+
t4 = t3 + 3600
|
156
|
+
ret = @srv.insert(FEED, event("t4", "d4", t4, t4))
|
157
|
+
assert_equal("201", ret.code, ret.body)
|
158
|
+
sleep(2)
|
159
|
+
ret = @srv.insert(FEED, event("t3", "d3", t3, t3))
|
160
|
+
assert_equal("201", ret.code, ret.body)
|
161
|
+
sleep(2)
|
162
|
+
ret = @srv.insert(FEED, event("t2", "d2", t2, t2))
|
163
|
+
assert_equal("201", ret.code, ret.body)
|
164
|
+
sleep(2)
|
165
|
+
ret = @srv.insert(FEED, event("t1", "d1", t1, t1))
|
166
|
+
assert_equal("201", ret.code, ret.body)
|
167
|
+
[t1, t2, t3, t4]
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "base_unit"
|
2
|
+
|
3
|
+
class TestCalendar < Test::Unit::TestCase
|
4
|
+
include GoogleCalendar
|
5
|
+
include CalendarTest
|
6
|
+
|
7
|
+
def test_create_from_feed
|
8
|
+
assert_instance_of(GoogleCalendar::Calendar, @cal)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_create_from_calendar_list
|
12
|
+
list = GoogleCalendar::Calendar.calendars(@srv)
|
13
|
+
assert_instance_of(Hash, list)
|
14
|
+
list.each do |feed, cal|
|
15
|
+
assert_equal(cal.feed, feed)
|
16
|
+
assert_instance_of(GoogleCalendar::Calendar, cal)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# THESE ACTUAL VALUES COULD BE DIFFERENT.
|
22
|
+
#
|
23
|
+
def test_calendar_attributes
|
24
|
+
assert_equal("Calendar Test", @cal.title)
|
25
|
+
assert_equal("Calendar Test Description", @cal.subtitle)
|
26
|
+
assert_not_nil(@cal.name)
|
27
|
+
assert_not_nil(@cal.updated)
|
28
|
+
assert_equal(MAIL, @cal.email)
|
29
|
+
assert_equal("Europe/London", @cal.timezone)
|
30
|
+
assert_equal("Calendar Test Location", @cal.where)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_calendar_events_list
|
34
|
+
st = Time.now
|
35
|
+
en = st + 3600
|
36
|
+
@srv.insert(FEED, event("t1", "e1", st, en))
|
37
|
+
@srv.insert(FEED, event("t2", "e2", en, en + 3600))
|
38
|
+
@cal.events.each do |event|
|
39
|
+
assert_instance_of(GoogleCalendar::Event, event)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_create_event
|
44
|
+
ev = @cal.create_event
|
45
|
+
assert_instance_of(GoogleCalendar::Event, ev)
|
46
|
+
end
|
47
|
+
|
48
|
+
def setup
|
49
|
+
@srv = get_service
|
50
|
+
@cal = GoogleCalendar::Calendar.new(@srv, FEED)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "base_unit"
|
2
|
+
|
3
|
+
class TestCalendar < Test::Unit::TestCase
|
4
|
+
include GoogleCalendar
|
5
|
+
include CalendarTest
|
6
|
+
|
7
|
+
def test_create
|
8
|
+
st = Time.now
|
9
|
+
en = st + 3600
|
10
|
+
event = @cal.create_event
|
11
|
+
event.title = "title"
|
12
|
+
event.desc = "desc"
|
13
|
+
event.st = st
|
14
|
+
event.en = en
|
15
|
+
ret = event.save
|
16
|
+
assert(ret)
|
17
|
+
evs = @cal.events
|
18
|
+
assert_equal(1, evs.length)
|
19
|
+
assert_same_event(event, evs[0])
|
20
|
+
|
21
|
+
event.desc = "updated"
|
22
|
+
assert(event.save)
|
23
|
+
evs = @cal.events
|
24
|
+
assert_equal(1, evs.length)
|
25
|
+
assert_same_event(event, evs[0])
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_update
|
29
|
+
@srv.insert(FEED, event("test1", "desc1", Time.now, Time.now + 3600))
|
30
|
+
ev1 = @cal.events[0]
|
31
|
+
ev1.desc = "desc2"
|
32
|
+
#assert(ev1.save)
|
33
|
+
ev1.save!
|
34
|
+
ev2 = @cal.events[0]
|
35
|
+
assert_same_event(ev1, ev2)
|
36
|
+
assert_equal("desc2", ev2.desc)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_delete
|
40
|
+
@srv.insert(FEED, event("test1", "desc1", Time.now, Time.now + 3600))
|
41
|
+
ev1 = @cal.events[0]
|
42
|
+
#assert(ev1.destroy)
|
43
|
+
ev1.destroy!
|
44
|
+
assert_equal(0, @cal.events.length)
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup
|
48
|
+
@srv = get_service
|
49
|
+
clear_all(@srv, FEED)
|
50
|
+
@cal = GoogleCalendar::Calendar.new(@srv, FEED)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def assert_same_event(ev1, ev2)
|
56
|
+
["title", "desc", "st", "en"].each do |elem|
|
57
|
+
assert_equal(ev1.send(elem), ev2.send(elem))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/test/all.sh
ADDED
data/test/base_unit.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require "parameters"
|
4
|
+
require 'test/unit'
|
5
|
+
require "googlecalendar/calendar"
|
6
|
+
|
7
|
+
module CalendarTest
|
8
|
+
include GoogleCalendar
|
9
|
+
def get_service
|
10
|
+
srv = Service.new(MAIL, PASS)
|
11
|
+
assert_instance_of(Service, srv)
|
12
|
+
srv.send("auth")
|
13
|
+
assert_not_nil(srv.instance_eval("@auth"))
|
14
|
+
srv
|
15
|
+
end
|
16
|
+
|
17
|
+
def event(title, desc, st, en)
|
18
|
+
ret = <<XML
|
19
|
+
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>
|
20
|
+
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category>
|
21
|
+
<title type='text'>#{title}</title>
|
22
|
+
<content type='text'>#{desc}</content>
|
23
|
+
<gd:transparency value='http://schemas.google.com/g/2005#event.opaque'></gd:transparency>
|
24
|
+
<gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'></gd:eventStatus>
|
25
|
+
<gd:where valueString=''></gd:where>
|
26
|
+
<gd:when startTime='#{st.iso8601}' endTime='#{en.iso8601}'></gd:when>
|
27
|
+
</entry>
|
28
|
+
XML
|
29
|
+
ret
|
30
|
+
end
|
31
|
+
|
32
|
+
def clear_all(srv, feed)
|
33
|
+
ret = srv.query(feed, {})
|
34
|
+
ens = get_entry_from_query(ret)
|
35
|
+
ens.each do |entry|
|
36
|
+
entry.elements.each("link") do |link|
|
37
|
+
if link.attributes["rel"] == "edit"
|
38
|
+
@srv.delete(link.attributes["href"])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_entry_from_query(ret)
|
45
|
+
assert_equal("200", ret.code)
|
46
|
+
xml = nil
|
47
|
+
assert_nothing_raised { xml = REXML::Document.new(ret.body) }
|
48
|
+
entries = xml.root.elements.each("entry"){}
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_feed_from_entry(xmldoc)
|
52
|
+
xmldoc.root.elements.each("link"){}.map{|e| e.attributes["href"] if e.attributes["rel"] == "edit"}.compact[0]
|
53
|
+
end
|
54
|
+
end
|
data/test/each.sh
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.10
|
3
|
+
specification_version: 1
|
4
|
+
name: gcalapi
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2006-11-09
|
8
|
+
summary: Google Calendar API
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: zoriorz@gmail.com
|
12
|
+
homepage: http://gcalapi.rubyforge.net
|
13
|
+
rubyforge_project: gcalapi
|
14
|
+
description: ''
|
15
|
+
autorequire: googlecalendar/calendar
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
authors:
|
28
|
+
- zorio
|
29
|
+
files:
|
30
|
+
- lib
|
31
|
+
- html
|
32
|
+
- test
|
33
|
+
- Rakefile
|
34
|
+
- README
|
35
|
+
- example
|
36
|
+
- VERSION
|
37
|
+
- lib/googlecalendar
|
38
|
+
- lib/googlecalendar/calendar.rb
|
39
|
+
- lib/googlecalendar/event.rb
|
40
|
+
- lib/googlecalendar/service.rb
|
41
|
+
- html/files
|
42
|
+
- html/index.html
|
43
|
+
- html/rdoc-style.css
|
44
|
+
- html/fr_method_index.html
|
45
|
+
- html/fr_class_index.html
|
46
|
+
- html/fr_file_index.html
|
47
|
+
- html/created.rid
|
48
|
+
- html/classes
|
49
|
+
- html/files/lib
|
50
|
+
- html/files/README.html
|
51
|
+
- html/files/lib/googlecalendar
|
52
|
+
- html/files/lib/googlecalendar/event_rb.html
|
53
|
+
- html/files/lib/googlecalendar/service_rb.html
|
54
|
+
- html/files/lib/googlecalendar/calendar_rb.html
|
55
|
+
- html/classes/GoogleCalendar.html
|
56
|
+
- html/classes/GoogleCalendar
|
57
|
+
- html/classes/GoogleCalendar/Service.html
|
58
|
+
- html/classes/GoogleCalendar/EventUpdateFailed.html
|
59
|
+
- html/classes/GoogleCalendar/Calendar.html
|
60
|
+
- html/classes/GoogleCalendar/EventInsertFailed.html
|
61
|
+
- html/classes/GoogleCalendar/EventDeleteFailed.html
|
62
|
+
- html/classes/GoogleCalendar/Event.html
|
63
|
+
- html/classes/GoogleCalendar/InvalidCalendarURL.html
|
64
|
+
- html/classes/GoogleCalendar/AuthenticationFailed.html
|
65
|
+
- test/each.sh
|
66
|
+
- test/00_service_test.rb
|
67
|
+
- test/all.sh
|
68
|
+
- test/base_unit.rb
|
69
|
+
- test/01_calendar_test.rb
|
70
|
+
- test/02_event_test.rb
|
71
|
+
- example/ol2gcal.rb
|
72
|
+
- example/mail2gcal.rb
|
73
|
+
test_files:
|
74
|
+
- test/00_service_test.rb
|
75
|
+
- test/01_calendar_test.rb
|
76
|
+
- test/02_event_test.rb
|
77
|
+
rdoc_options:
|
78
|
+
- "--line-numbers"
|
79
|
+
- "--inline-source"
|
80
|
+
extra_rdoc_files:
|
81
|
+
- README
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
requirements: []
|
85
|
+
dependencies: []
|