google_calendar 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.8.7"
4
3
  - "1.9.2"
5
4
  - "1.9.3"
6
5
  - "2.0.0"
data/Gemfile.lock CHANGED
@@ -4,26 +4,25 @@ GEM
4
4
  activesupport (3.2.13)
5
5
  i18n (= 0.6.1)
6
6
  multi_json (~> 1.0)
7
- addressable (2.3.3)
8
- bourne (1.4.0)
9
- mocha (~> 0.13.2)
7
+ addressable (2.3.4)
10
8
  i18n (0.6.1)
11
- json (1.7.7)
9
+ json (1.8.0)
12
10
  metaclass (0.0.1)
13
- mocha (0.13.3)
11
+ mini_portile (0.5.0)
12
+ mocha (0.14.0)
14
13
  metaclass (~> 0.0.1)
15
- multi_json (1.7.2)
16
- nokogiri (1.5.9)
14
+ multi_json (1.7.7)
15
+ nokogiri (1.6.0)
16
+ mini_portile (~> 0.5.0)
17
17
  rake (10.0.4)
18
18
  rdoc (4.0.1)
19
19
  json (~> 1.4)
20
- shoulda (3.4.0)
20
+ shoulda (3.5.0)
21
21
  shoulda-context (~> 1.0, >= 1.0.1)
22
- shoulda-matchers (~> 1.0, >= 1.4.1)
23
- shoulda-context (1.1.1)
24
- shoulda-matchers (1.5.6)
22
+ shoulda-matchers (>= 1.4.1, < 3.0)
23
+ shoulda-context (1.1.2)
24
+ shoulda-matchers (2.2.0)
25
25
  activesupport (>= 3.0.0)
26
- bourne (~> 1.3)
27
26
 
28
27
  PLATFORMS
29
28
  ruby
data/README.rdoc CHANGED
@@ -40,7 +40,7 @@ Note: Google requests that you set the name of your application so they can bett
40
40
  puts cal.find_events('my search string')
41
41
 
42
42
 
43
- Note: This is not a complete implementation of the calendar api, it just includes the features I needed to support our internal calendar integration.
43
+ Note: This is not a complete implementation of the calendar api, it just includes the features we needed to support our internal calendar integration.
44
44
 
45
45
  == Contributing to google_calendar
46
46
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "google_calendar"
5
- s.version = "0.3.0"
6
- s.date = "2013-04-15"
5
+ s.version = "0.3.1"
6
+ s.date = "2013-08-23"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
 
@@ -77,11 +77,19 @@ module Google
77
77
  # an array of events if many found.
78
78
  #
79
79
  def find_events_in_range(start_min, start_max,options = {})
80
- options[:max_results] ||= 25
80
+ options[:max_results] ||= 25
81
+ options[:order_by] ||= 'lastmodified' # other option is 'starttime'
81
82
  formatted_start_min = start_min.strftime("%Y-%m-%dT%H:%M:%S")
82
83
  formatted_start_max = start_max.strftime("%Y-%m-%dT%H:%M:%S")
83
84
  query = "?start-min=#{formatted_start_min}&start-max=#{formatted_start_max}&recurrence-expansion-start=#{formatted_start_min}&recurrence-expansion-end=#{formatted_start_max}"
84
- query = "#{query}&max-results=#{options[:max_results]}"
85
+ query = "#{query}&orderby=#{options[:order_by]}&max-results=#{options[:max_results]}"
86
+ event_lookup(query)
87
+ end
88
+
89
+ def find_future_events(options={})
90
+ options[:max_results] ||= 25
91
+ options[:order_by] ||= 'lastmodified' # other option is 'starttime'
92
+ query = "?futureevents=true&orderby=#{options[:order_by]}&max-results=#{options[:max_results]}"
85
93
  event_lookup(query)
86
94
  end
87
95
 
@@ -213,7 +221,12 @@ module Google
213
221
 
214
222
  def setup_event(event) #:nodoc:
215
223
  event.calendar = self
216
- yield(event) if block_given?
224
+ if block_given?
225
+ yield(event)
226
+ event.title = event.title.encode(:xml => :text) if event.title
227
+ event.content = event.content.encode(:xml => :text) if event.content
228
+ event.where = event.where.encode(:xml => :text) if event.where
229
+ end
217
230
  event.save
218
231
  event
219
232
  end
data/lib/google/event.rb CHANGED
@@ -165,14 +165,26 @@ module Google
165
165
  # Create a new event from a google 'entry' xml block.
166
166
  #
167
167
  def self.new_from_xml(xml, calendar) #:nodoc:
168
- Event.new(:id => xml.at_xpath("gCal:uid")['value'].split('@').first,
168
+ id = xml.at_xpath("gCal:uid")['value'].split('@').first
169
+
170
+ # Check if this event came from an apple program (ios, iCal, Calendar, etc)
171
+ # Id format ex: E52411E2-8DB9-4A26-AD5A-8B6104320D3C
172
+ if id.match( /[0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12}/ )
173
+ # Use the ID field instead of the UID which apple overwrites for its own purposes.
174
+ # TODO With proper testing, this should be way to parse all event id's
175
+ id = xml.at_xpath("xmlns:id").content.split('/').last
176
+ end
177
+
178
+ event_time_data = xml.at_xpath("gd:when")
179
+
180
+ Event.new(:id => id,
169
181
  :calendar => calendar,
170
182
  :raw_xml => xml,
171
183
  :title => xml.at_xpath("xmlns:title").content,
172
184
  :content => xml.at_xpath("xmlns:content").content,
173
185
  :where => xml.at_xpath("gd:where")['valueString'],
174
- :start_time => xml.at_xpath("gd:when")['startTime'],
175
- :end_time => xml.at_xpath("gd:when")['endTime'],
186
+ :start_time => (event_time_data.nil? ? nil : xml.at_xpath("gd:when")['startTime']),
187
+ :end_time => (event_time_data.nil? ? nil : xml.at_xpath("gd:when")['endTime']),
176
188
  :transparency => xml.at_xpath("gd:transparency")['value'].split('.').last,
177
189
  :quickadd => (xml.at_xpath("gCal:quickadd") ? (xml.at_xpath("gCal:quickadd")['quickadd']) : nil),
178
190
  :html_link => xml.at_xpath('//xmlns:link[@title="alternate" and @rel="alternate" and @type="text/html"]')['href'],
@@ -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&recurrence-expansion-start=2011-02-01T11:01:01&recurrence-expansion-end=2011-02-28T23:59:59&max-results=25')
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&orderby=lastmodified&max-results=25')
132
132
  events = @calendar.find_events_in_range(start_min, start_max)
133
133
  end
134
134
 
@@ -168,6 +168,22 @@ class TestGoogleCalendar < Test::Unit::TestCase
168
168
  assert_equal event.content, "movie tomorrow 23:00 at AMC Van Ness"
169
169
  end
170
170
 
171
+ should "format create event with ampersand correctly" do
172
+ @http_mock.stubs(:body).returns( get_mock_body("create_event.xml") )
173
+
174
+ event = @calendar.create_event do |e|
175
+ e.title = 'New Event with &'
176
+ e.start_time = Time.now + (60 * 60)
177
+ e.end_time = Time.now + (60 * 60 * 2)
178
+ e.content = "A new event with &"
179
+ e.where = "Joe's House & Backyard"
180
+ end
181
+
182
+ assert_equal event.title, 'New Event with &amp;'
183
+ assert_equal event.content, 'A new event with &amp;'
184
+ assert_equal event.where, "Joe's House &amp; Backyard"
185
+ end
186
+
171
187
  should "format to_s properly" do
172
188
  @http_mock.stubs(:body).returns( get_mock_body("query_events.xml") )
173
189
  event = @calendar.find_events('Test')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-15 00:00:00.000000000 Z
12
+ date: 2013-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri