google_calendar 0.2.1 → 0.2.2
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/VERSION +1 -1
- data/google_calendar.gemspec +3 -3
- data/lib/google/calendar.rb +15 -5
- data/lib/google/event.rb +20 -0
- data/test/test_google_calendar.rb +36 -1
- metadata +26 -26
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/google_calendar.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{google_calendar}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steve Zich"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2012-03-27}
|
13
13
|
s.description = %q{A minimal wrapper around the google calendar API, which uses nokogiri for fast parsing.}
|
14
14
|
s.email = %q{steve.zich@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.homepage = %q{http://github.com/northworld/google_calendar}
|
45
45
|
s.licenses = ["MIT"]
|
46
46
|
s.require_paths = ["lib"]
|
47
|
-
s.rubygems_version = %q{1.
|
47
|
+
s.rubygems_version = %q{1.6.2}
|
48
48
|
s.summary = %q{A lightweight google calendar API wrapper}
|
49
49
|
s.test_files = [
|
50
50
|
"test/helper.rb",
|
data/lib/google/calendar.rb
CHANGED
@@ -79,7 +79,7 @@ module Google
|
|
79
79
|
def find_events_in_range(start_min, start_max)
|
80
80
|
formatted_start_min = start_min.strftime("%Y-%m-%dT%H:%M:%S")
|
81
81
|
formatted_start_max = start_max.strftime("%Y-%m-%dT%H:%M:%S")
|
82
|
-
event_lookup("?start-min=#{formatted_start_min}&start-max=#{formatted_start_max}")
|
82
|
+
event_lookup("?start-min=#{formatted_start_min}&start-max=#{formatted_start_max}&recurrence-expansion-start=#{formatted_start_min}&recurrence-expansion-end=#{formatted_start_max}")
|
83
83
|
end
|
84
84
|
|
85
85
|
# Attempts to find the event specified by the id
|
@@ -158,6 +158,10 @@ module Google
|
|
158
158
|
:auth_url => auth_url)
|
159
159
|
self
|
160
160
|
end
|
161
|
+
|
162
|
+
def display_color
|
163
|
+
calendar_data.xpath("//entry[title='#{@calendar}']/color/@value").first.value
|
164
|
+
end
|
161
165
|
|
162
166
|
protected
|
163
167
|
|
@@ -188,15 +192,21 @@ module Google
|
|
188
192
|
#
|
189
193
|
def events_url
|
190
194
|
if @calendar and !@calendar.include?("@")
|
191
|
-
|
192
|
-
doc = Nokogiri::XML(xml.body)
|
193
|
-
doc.remove_namespaces!
|
194
|
-
link = doc.xpath("//entry[title='#{@calendar}']/link[contains(@rel, '#eventFeed')]/@href").to_s
|
195
|
+
link = calendar_data.xpath("//entry[title='#{@calendar}']/link[contains(@rel, '#eventFeed')]/@href").to_s
|
195
196
|
link.empty? ? raise(Google::InvalidCalendar) : link
|
196
197
|
else
|
197
198
|
"https://www.google.com/calendar/feeds/#{calendar_id}/private/full"
|
198
199
|
end
|
199
200
|
end
|
201
|
+
|
202
|
+
def calendar_data
|
203
|
+
unless @calendar_data
|
204
|
+
xml = @connection.send(Addressable::URI.parse("https://www.google.com/calendar/feeds/default/allcalendars/full"), :get)
|
205
|
+
@calendar_data = Nokogiri::XML(xml.body)
|
206
|
+
@calendar_data.remove_namespaces!
|
207
|
+
end
|
208
|
+
@calendar_data
|
209
|
+
end
|
200
210
|
|
201
211
|
def setup_event(event) #:nodoc:
|
202
212
|
event.calendar = self
|
data/lib/google/event.rb
CHANGED
@@ -36,6 +36,7 @@ module Google
|
|
36
36
|
@where = params[:where]
|
37
37
|
@start_time = params[:start_time]
|
38
38
|
@end_time = params[:end_time]
|
39
|
+
self.all_day= params[:all_day] if params[:all_day]
|
39
40
|
@calendar = params[:calendar]
|
40
41
|
@raw_xml = params[:raw_xml]
|
41
42
|
@quickadd = params[:quickadd]
|
@@ -72,6 +73,25 @@ module Google
|
|
72
73
|
raise ArgumentError, "End Time must be either Time or String" unless (time.is_a?(String) || time.is_a?(Time))
|
73
74
|
@end_time = ((time.is_a? String) ? Time.parse(time) : time)
|
74
75
|
end
|
76
|
+
|
77
|
+
# Returns whether the Event is an all-day event, based on whether the event starts at the beginning and ends at the end of the day.
|
78
|
+
#
|
79
|
+
def all_day?
|
80
|
+
duration == 24 * 60 * 60 # Exactly one day
|
81
|
+
end
|
82
|
+
|
83
|
+
def all_day=(time)
|
84
|
+
if time.class == String
|
85
|
+
time = Time.parse(time)
|
86
|
+
end
|
87
|
+
@start_time = time.strftime("%Y-%m-%d")
|
88
|
+
@end_time = (time + 24*60*60).strftime("%Y-%m-%d")
|
89
|
+
end
|
90
|
+
|
91
|
+
# Duration in seconds
|
92
|
+
def duration
|
93
|
+
Time.parse(end_time) - Time.parse(start_time)
|
94
|
+
end
|
75
95
|
|
76
96
|
#
|
77
97
|
def self.build_from_google_feed(xml, calendar)
|
@@ -128,7 +128,7 @@ class TestGoogleCalendar < Test::Unit::TestCase
|
|
128
128
|
should "find events in range" do
|
129
129
|
start_min = DateTime.new(2011, 2, 1, 11, 1, 1)
|
130
130
|
start_max = DateTime.new(2011, 2, 28, 23, 59, 59)
|
131
|
-
@calendar.expects(:event_lookup).with('?start-min=2011-02-01T11:01:01&start-max=2011-02-28T23:59:59')
|
131
|
+
@calendar.expects(:event_lookup).with('?start-min=2011-02-01T11:01:01&start-max=2011-02-28T23:59:59&recurrence-expansion-start=2011-02-01T11:01:01&recurrence-expansion-end=2011-02-28T23:59:59')
|
132
132
|
events = @calendar.find_events_in_range(start_min, start_max)
|
133
133
|
end
|
134
134
|
|
@@ -216,6 +216,41 @@ class TestGoogleCalendar < Test::Unit::TestCase
|
|
216
216
|
end # Logged on context
|
217
217
|
|
218
218
|
end # Connected context
|
219
|
+
|
220
|
+
context "Event instance methods" do
|
221
|
+
context "#all_day?" do
|
222
|
+
context "when the event is 24 hours long or more" do
|
223
|
+
should "be true" do
|
224
|
+
@event = Event.new(:start_time => "2012-03-31", :end_time => "2012-04-01")
|
225
|
+
assert @event.all_day?
|
226
|
+
end
|
227
|
+
end
|
228
|
+
context "when the event is not an all-day event" do
|
229
|
+
should "be false" do
|
230
|
+
@event = Event.new(:start_time => "2012-03-27T10:00:00.000-07:00", :end_time => "2012-03-27T10:30:00.000-07:00")
|
231
|
+
assert !@event.all_day?
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context "#all_day=" do
|
237
|
+
context "sets the start and end time to the appropriate values for an all day event on that day" do
|
238
|
+
should "set the start time" do
|
239
|
+
@event = Event.new :all_day => Time.parse("2012-05-02 12:24")
|
240
|
+
assert_equal @event.start_time, "2012-05-02"
|
241
|
+
end
|
242
|
+
should "set the end time" do
|
243
|
+
@event = Event.new :all_day => Time.parse("2012-05-02 12:24")
|
244
|
+
assert_equal @event.end_time, "2012-05-03"
|
245
|
+
end
|
246
|
+
should "be able to handle strings" do
|
247
|
+
@event = Event.new :all_day => "2012-05-02 12:24"
|
248
|
+
assert_equal @event.start_time, "2012-05-02"
|
249
|
+
assert_equal @event.end_time, "2012-05-03"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
219
254
|
|
220
255
|
def test_https_extension
|
221
256
|
assert_nothing_thrown do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steve Zich
|
@@ -15,12 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-03-27 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
type: :runtime
|
23
|
-
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
@@ -31,12 +31,12 @@ dependencies:
|
|
31
31
|
- 4
|
32
32
|
- 4
|
33
33
|
version: 1.4.4
|
34
|
-
requirement: *id001
|
35
|
-
prerelease: false
|
36
34
|
name: nokogiri
|
35
|
+
version_requirements: *id001
|
36
|
+
prerelease: false
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
type: :runtime
|
39
|
-
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
@@ -47,12 +47,12 @@ dependencies:
|
|
47
47
|
- 2
|
48
48
|
- 2
|
49
49
|
version: 2.2.2
|
50
|
-
requirement: *id002
|
51
|
-
prerelease: false
|
52
50
|
name: addressable
|
51
|
+
version_requirements: *id002
|
52
|
+
prerelease: false
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
type: :development
|
55
|
-
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
@@ -61,12 +61,12 @@ dependencies:
|
|
61
61
|
segments:
|
62
62
|
- 0
|
63
63
|
version: "0"
|
64
|
-
requirement: *id003
|
65
|
-
prerelease: false
|
66
64
|
name: shoulda
|
65
|
+
version_requirements: *id003
|
66
|
+
prerelease: false
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
type: :development
|
69
|
-
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
72
72
|
- - ~>
|
@@ -77,12 +77,12 @@ dependencies:
|
|
77
77
|
- 0
|
78
78
|
- 0
|
79
79
|
version: 1.0.0
|
80
|
-
requirement: *id004
|
81
|
-
prerelease: false
|
82
80
|
name: bundler
|
81
|
+
version_requirements: *id004
|
82
|
+
prerelease: false
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
type: :development
|
85
|
-
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - ~>
|
@@ -93,12 +93,12 @@ dependencies:
|
|
93
93
|
- 5
|
94
94
|
- 1
|
95
95
|
version: 1.5.1
|
96
|
-
requirement: *id005
|
97
|
-
prerelease: false
|
98
96
|
name: jeweler
|
97
|
+
version_requirements: *id005
|
98
|
+
prerelease: false
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
type: :development
|
101
|
-
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
102
|
none: false
|
103
103
|
requirements:
|
104
104
|
- - ">="
|
@@ -107,12 +107,12 @@ dependencies:
|
|
107
107
|
segments:
|
108
108
|
- 0
|
109
109
|
version: "0"
|
110
|
-
requirement: *id006
|
111
|
-
prerelease: false
|
112
110
|
name: rcov
|
111
|
+
version_requirements: *id006
|
112
|
+
prerelease: false
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
type: :development
|
115
|
-
|
115
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ">="
|
@@ -121,9 +121,9 @@ dependencies:
|
|
121
121
|
segments:
|
122
122
|
- 0
|
123
123
|
version: "0"
|
124
|
-
requirement: *id007
|
125
|
-
prerelease: false
|
126
124
|
name: mocha
|
125
|
+
version_requirements: *id007
|
126
|
+
prerelease: false
|
127
127
|
description: A minimal wrapper around the google calendar API, which uses nokogiri for fast parsing.
|
128
128
|
email: steve.zich@gmail.com
|
129
129
|
executables: []
|
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
187
|
requirements: []
|
188
188
|
|
189
189
|
rubyforge_project:
|
190
|
-
rubygems_version: 1.
|
190
|
+
rubygems_version: 1.6.2
|
191
191
|
signing_key:
|
192
192
|
specification_version: 3
|
193
193
|
summary: A lightweight google calendar API wrapper
|