gdata-jruby-client 0.7.0

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 (74) hide show
  1. data/MIT-LICENSE +22 -0
  2. data/README +25 -0
  3. data/lib/base.rb +16 -0
  4. data/lib/base_entry.rb +20 -0
  5. data/lib/calendar_event_entry.rb +3 -0
  6. data/lib/calendar_service.rb +19 -0
  7. data/lib/contacts_service.rb +17 -0
  8. data/lib/email.rb +16 -0
  9. data/lib/extended_property.rb +14 -0
  10. data/lib/gdata/COPYING +202 -0
  11. data/lib/gdata/RELEASE_NOTES.txt +448 -0
  12. data/lib/gdata/java/deps/google-collect-1.0-rc1.jar +0 -0
  13. data/lib/gdata/java/deps/jsr305.jar +0 -0
  14. data/lib/gdata/java/lib/gdata-analytics-2.0.jar +0 -0
  15. data/lib/gdata/java/lib/gdata-analytics-meta-2.0.jar +0 -0
  16. data/lib/gdata/java/lib/gdata-appsforyourdomain-1.0.jar +0 -0
  17. data/lib/gdata/java/lib/gdata-appsforyourdomain-meta-1.0.jar +0 -0
  18. data/lib/gdata/java/lib/gdata-base-1.0.jar +0 -0
  19. data/lib/gdata/java/lib/gdata-blogger-2.0.jar +0 -0
  20. data/lib/gdata/java/lib/gdata-blogger-meta-2.0.jar +0 -0
  21. data/lib/gdata/java/lib/gdata-books-1.0.jar +0 -0
  22. data/lib/gdata/java/lib/gdata-books-meta-1.0.jar +0 -0
  23. data/lib/gdata/java/lib/gdata-calendar-2.0.jar +0 -0
  24. data/lib/gdata/java/lib/gdata-calendar-meta-2.0.jar +0 -0
  25. data/lib/gdata/java/lib/gdata-client-1.0.jar +0 -0
  26. data/lib/gdata/java/lib/gdata-client-meta-1.0.jar +0 -0
  27. data/lib/gdata/java/lib/gdata-codesearch-2.0.jar +0 -0
  28. data/lib/gdata/java/lib/gdata-codesearch-meta-2.0.jar +0 -0
  29. data/lib/gdata/java/lib/gdata-contacts-3.0.jar +0 -0
  30. data/lib/gdata/java/lib/gdata-contacts-meta-3.0.jar +0 -0
  31. data/lib/gdata/java/lib/gdata-core-1.0.jar +0 -0
  32. data/lib/gdata/java/lib/gdata-docs-3.0.jar +0 -0
  33. data/lib/gdata/java/lib/gdata-docs-meta-3.0.jar +0 -0
  34. data/lib/gdata/java/lib/gdata-finance-2.0.jar +0 -0
  35. data/lib/gdata/java/lib/gdata-finance-meta-2.0.jar +0 -0
  36. data/lib/gdata/java/lib/gdata-health-2.0.jar +0 -0
  37. data/lib/gdata/java/lib/gdata-health-meta-2.0.jar +0 -0
  38. data/lib/gdata/java/lib/gdata-maps-2.0.jar +0 -0
  39. data/lib/gdata/java/lib/gdata-maps-meta-2.0.jar +0 -0
  40. data/lib/gdata/java/lib/gdata-media-1.0.jar +0 -0
  41. data/lib/gdata/java/lib/gdata-photos-2.0.jar +0 -0
  42. data/lib/gdata/java/lib/gdata-photos-meta-2.0.jar +0 -0
  43. data/lib/gdata/java/lib/gdata-projecthosting-2.0.jar +0 -0
  44. data/lib/gdata/java/lib/gdata-projecthosting-meta-2.0.jar +0 -0
  45. data/lib/gdata/java/lib/gdata-sidewiki-2.0.jar +0 -0
  46. data/lib/gdata/java/lib/gdata-sidewiki-meta-2.0.jar +0 -0
  47. data/lib/gdata/java/lib/gdata-sites-2.0.jar +0 -0
  48. data/lib/gdata/java/lib/gdata-sites-meta-2.0.jar +0 -0
  49. data/lib/gdata/java/lib/gdata-spreadsheet-3.0.jar +0 -0
  50. data/lib/gdata/java/lib/gdata-spreadsheet-meta-3.0.jar +0 -0
  51. data/lib/gdata/java/lib/gdata-webmastertools-2.0.jar +0 -0
  52. data/lib/gdata/java/lib/gdata-webmastertools-meta-2.0.jar +0 -0
  53. data/lib/gdata/java/lib/gdata-youtube-2.0.jar +0 -0
  54. data/lib/gdata/java/lib/gdata-youtube-meta-2.0.jar +0 -0
  55. data/lib/gdata/java/version.properties +46 -0
  56. data/lib/gdata_jruby_client.rb +22 -0
  57. data/lib/google_helpers.rb +14 -0
  58. data/lib/google_oauth_parameters.rb +13 -0
  59. data/lib/google_service.rb +58 -0
  60. data/lib/im.rb +16 -0
  61. data/lib/query.rb +12 -0
  62. data/lib/recurrence.rb +14 -0
  63. data/lib/string_ext.rb +10 -0
  64. data/lib/text_content.rb +5 -0
  65. data/lib/time_ext.rb +49 -0
  66. data/lib/when.rb +16 -0
  67. data/spec/entry_spec.rb +22 -0
  68. data/spec/google_calendar_service_spec.rb +296 -0
  69. data/spec/google_contacts_service_spec.rb +149 -0
  70. data/spec/google_keys.rb +11 -0
  71. data/spec/google_oauth_parameters_spec.rb +20 -0
  72. data/spec/images/sergey.jpg +0 -0
  73. data/spec/images/sergey_out.jpg +0 -0
  74. metadata +126 -0
Binary file
@@ -0,0 +1,46 @@
1
+ # Define version number for GData client and property extension jars.
2
+ # Specification version
3
+ client.spec.version=1.0
4
+ media.spec.version=1.0
5
+ appsforyourdomain.spec.version=1.0
6
+ analytics.spec.version=2.0
7
+ base.spec.version=1.0
8
+ blogger.spec.version=2.0
9
+ books.spec.version=1.0
10
+ calendar.spec.version=2.0
11
+ codesearch.spec.version=2.0
12
+ contacts.spec.version=3.0
13
+ docs.spec.version=3.0
14
+ finance.spec.version=2.0
15
+ health.spec.version=2.0
16
+ maps.spec.version=2.0
17
+ photos.spec.version=2.0
18
+ projecthosting.spec.version=2.0
19
+ sidewiki.spec.version=2.0
20
+ sites.spec.version=2.0
21
+ spreadsheet.spec.version=3.0
22
+ youtube.spec.version=2.0
23
+ webmastertools.spec.version=2.0
24
+
25
+ # Implementation version
26
+ client.impl.version=1.39.1
27
+ media.impl.version=1.0.2
28
+ appsforyourdomain.impl.version=1.1.3
29
+ analytics.impl.version=2.0.0
30
+ base.impl.version=1.2.0
31
+ blogger.impl.version=2.0.0
32
+ books.impl.version=1.0.0
33
+ calendar.impl.version=2.0.2
34
+ codesearch.impl.version=2.0.0
35
+ contacts.impl.version=3.0.0
36
+ docs.impl.version=3.0.0
37
+ finance.impl.version=2.0.0
38
+ health.impl.version=2.0.1
39
+ maps.impl.version=2.0.1
40
+ photos.impl.version=2.0.0
41
+ projecthosting.impl.version=2.0.0
42
+ sidewiki.impl.version=2.0.1
43
+ sites.impl.version=2.0.0
44
+ spreadsheet.impl.version=3.0.1
45
+ youtube.impl.version=2.1.1
46
+ webmastertools.impl.version=2.0.0
@@ -0,0 +1,22 @@
1
+ DEFAULT_APPLICATION_NAME = "Presdo-GDataJRubyClient-0.1"
2
+
3
+ module GData end
4
+
5
+ require 'java'
6
+ require File.dirname(__FILE__) + '/base'
7
+ require File.dirname(__FILE__) + '/contacts_service'
8
+ require File.dirname(__FILE__) + '/time_ext'
9
+ require File.dirname(__FILE__) + '/string_ext'
10
+ require File.dirname(__FILE__) + '/google_helpers'
11
+ require File.dirname(__FILE__) + '/base_entry'
12
+ require File.dirname(__FILE__) + '/text_content'
13
+ require File.dirname(__FILE__) + '/query'
14
+ require File.dirname(__FILE__) + '/when'
15
+ require File.dirname(__FILE__) + '/email'
16
+ require File.dirname(__FILE__) + '/im'
17
+ require File.dirname(__FILE__) + '/extended_property'
18
+ require File.dirname(__FILE__) + '/recurrence'
19
+ require File.dirname(__FILE__) + '/calendar_event_entry'
20
+ require File.dirname(__FILE__) + '/google_oauth_parameters'
21
+ require File.dirname(__FILE__) + '/google_service'
22
+ require File.dirname(__FILE__) + '/calendar_service'
@@ -0,0 +1,14 @@
1
+ module GoogleHelpers
2
+ include_class 'java.net.URL'
3
+
4
+ def url_for(url_or_string)
5
+ (url_or_string.kind_of? String) ? URL.new(url_or_string) : url_or_string
6
+ end
7
+
8
+ def update_attributes(attributes)
9
+ attributes.each do |k, v|
10
+ self.send("#{k}=".to_sym, (v.kind_of? Time)? v.to_joda_time : v)
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ module GData
2
+ include_package 'com.google.gdata.client.authn.oauth'
3
+ end
4
+
5
+ class Java::ComGoogleGdataClientAuthnOauth::GoogleOAuthParameters
6
+ def attributes=(credentials = {})
7
+ self.oauth_consumer_key = credentials[:consumer_key] if credentials[:consumer_key]
8
+ self.oauth_consumer_secret = credentials[:consumer_secret] if credentials[:consumer_secret]
9
+ self.oauth_token = credentials[:token] if credentials[:token]
10
+ self.oauth_token_secret = credentials[:token_secret] if credentials[:token_secret]
11
+ self
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ class Java::ComGoogleGdataClient::GoogleService
2
+ include GoogleHelpers
3
+
4
+ def oauth_credentials=(credientials, signer=GData::OAuthHmacSha1Signer.new)
5
+ self.set_oauth_credentials(credientials, signer)
6
+ end
7
+
8
+ def auth_sub_token=(token, private_key=nil)
9
+ self.set_auth_sub_token(token, private_key)
10
+ end
11
+
12
+ def find_feed(options={})
13
+ raise "URL or query is required" unless options[:url] or options[:query]
14
+ raise "Feed Class is required" unless options[:class]
15
+ options[:url] = url_for(options[:url]) if options[:url]
16
+
17
+ if options[:etag] or options[:modified_since]
18
+ get_feed(options[:url] || options[:query],
19
+ options[:class].java_class,
20
+ options[:etag] || options[:modified_since])
21
+ else
22
+ get_feed(options[:url] || options[:query],
23
+ options[:class].java_class)
24
+ end
25
+ end
26
+
27
+ def find_entry(options={})
28
+ raise "URL or query is required" unless options[:url] or option[:query]
29
+ raise "Entry Class is required" unless options[:class]
30
+ options[:url] = url_for(options[:url]) if options[:url]
31
+
32
+ if options[:etag] or options[:modified_since]
33
+ get_entry(options[:url] || options[:query],
34
+ options[:class].java_class,
35
+ options[:etag] || options[:modified_since])
36
+ else
37
+ get_entry(options[:url] || options[:query],
38
+ options[:class].java_class)
39
+ end
40
+ end
41
+
42
+ def create_entry(options={})
43
+ raise "Feed URL is required" unless options[:url]
44
+ raise "Entry is required" unless options[:entry]
45
+ options[:url] = url_for(options[:url]) if options[:url]
46
+
47
+ insert(options[:url], options[:entry])
48
+ end
49
+
50
+ def create_batch(options={})
51
+ raise "Feed URL is required" unless options[:url]
52
+ raise "Feed is required" unless options[:feed]
53
+ options[:url] = url_for(options[:url]) if options[:url]
54
+
55
+ batch(options[:url], options[:feed])
56
+ end
57
+
58
+ end
data/lib/im.rb ADDED
@@ -0,0 +1,16 @@
1
+ class Java::ComGoogleGdataDataExtensions::Im
2
+ include GoogleHelpers
3
+
4
+ alias_method :orig_initialize, :initialize
5
+
6
+ def initialize(options=nil)
7
+ if options.is_a? Hash
8
+ orig_initialize()
9
+ update_attributes(options)
10
+ elsif options.nil?
11
+ orig_initialize()
12
+ else
13
+ orig_initialize
14
+ end
15
+ end
16
+ end
data/lib/query.rb ADDED
@@ -0,0 +1,12 @@
1
+ class Java::ComGoogleGdataClient::Query
2
+ include GoogleHelpers
3
+
4
+ def initialize(options)
5
+ if options.is_a? Hash
6
+ super url_for(options.delete(:url))
7
+ update_attributes(options)
8
+ else
9
+ super url_for(options)
10
+ end
11
+ end
12
+ end
data/lib/recurrence.rb ADDED
@@ -0,0 +1,14 @@
1
+ class Java::ComGoogleGdataDataExtensions::Recurrence
2
+ include GoogleHelpers
3
+
4
+ alias_method :orig_initialize, :initialize
5
+
6
+ def initialize(value=nil)
7
+ if value.nil?
8
+ orig_initialize
9
+ else
10
+ orig_initialize
11
+ self.value = value
12
+ end
13
+ end
14
+ end
data/lib/string_ext.rb ADDED
@@ -0,0 +1,10 @@
1
+ class String
2
+ include_class 'com.google.gdata.data.PlainTextConstruct'
3
+
4
+ def to_plain_text
5
+ PlainTextConstruct.new(self)
6
+ end
7
+
8
+ alias_method :to_gdata, :to_plain_text
9
+
10
+ end
@@ -0,0 +1,5 @@
1
+ class Java::ComGoogleGdataData::Content
2
+ def method_missing(method_name, *args)
3
+ self.content.send(method_name, *args)
4
+ end
5
+ end
data/lib/time_ext.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'parsedate'
2
+
3
+ class Time
4
+ include_class('com.google.gdata.data.DateTime') {|package,name| "G#{name}" }
5
+
6
+ def to_joda_time
7
+ GDateTime.parseDateTime(self.iso8601)
8
+ end
9
+
10
+ alias_method :to_gdata, :to_joda_time
11
+ alias_method :to_date_time, :to_joda_time
12
+
13
+ class << self
14
+ def from_joda_time(gdatetime)
15
+ if defined? parse
16
+ self.parse(gdatetime.to_s)
17
+ else
18
+ res = ParseDate.parsedate(gdatetime.to_s)
19
+ Time.local(*res)
20
+ end
21
+ end
22
+
23
+ alias_method :from_gdata, :from_joda_time
24
+ alias_method :from_date_time, :from_joda_time
25
+ end
26
+
27
+ unless defined? iso8601
28
+ # The following are copied from Rails. If you are using Rails, everything
29
+ # is already defined in ActiveSupport
30
+ def iso8601(fraction_digits = 0)
31
+ fraction = if fraction_digits > 0
32
+ ".%i" % self.usec.to_s[0, fraction_digits]
33
+ end
34
+ "#{self.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}"
35
+ end
36
+
37
+ def formatted_offset(colon = true, alternate_utc_string = nil)
38
+ utc? && alternate_utc_string || to_utc_offset_s(utc_offset, colon)
39
+ end
40
+
41
+ def to_utc_offset_s(utc_offset, colon=true)
42
+ seconds = utc_offset
43
+ sign = (seconds < 0 ? -1 : 1)
44
+ hours = seconds.abs / 3600
45
+ minutes = (seconds.abs % 3600) / 60
46
+ "%+03d%s%02d" % [ hours * sign, colon ? ":" : "", minutes ]
47
+ end
48
+ end
49
+ end
data/lib/when.rb ADDED
@@ -0,0 +1,16 @@
1
+ class Java::ComGoogleGdataDataExtensions::When
2
+ include GoogleHelpers
3
+
4
+ alias_method :orig_initialize, :initialize
5
+
6
+ def initialize(options=nil)
7
+ if options.is_a? Hash
8
+ orig_initialize()
9
+ update_attributes(options)
10
+ elsif options.nil?
11
+ orig_initialize()
12
+ else
13
+ orig_initialize
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require File.dirname(__FILE__) + '/../lib/gdata_jruby_client'
3
+
4
+ include GoogleHelpers
5
+
6
+ describe GData::Entry do
7
+ it "should able to initialize a new entry without attributes" do
8
+ entry = GData::CalendarEventEntry.new
9
+ entry.title = 'New Title'.to_plain_text
10
+
11
+ entry.title.plain_text.should == 'New Title'
12
+ end
13
+
14
+ it "should able to initialize a new entry with attributes" do
15
+ entry = GData::CalendarEventEntry.new({
16
+ :title => 'New Title'.to_plain_text,
17
+ :content => 'New Content'.to_plain_text })
18
+
19
+ entry.title.plain_text.should == 'New Title'
20
+ entry.content.plain_text.should == 'New Content'
21
+ end
22
+ end
@@ -0,0 +1,296 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require File.dirname(__FILE__) + '/../lib/gdata_jruby_client'
3
+ require File.dirname(__FILE__) + '/google_keys.rb'
4
+
5
+ include GoogleHelpers
6
+
7
+ describe GData::CalendarService do
8
+
9
+ before(:each) do
10
+ create_service
11
+ end
12
+
13
+ it "should able to retrieving all calendars" do
14
+ feed = @service.find_feed(:url => GData::CalendarService::ALL_CALENDAR_URL)
15
+ feed.should_not be_nil
16
+ entries = feed.entries
17
+ entries.size.should > 0
18
+ entries.each do |e|
19
+ e.title.plain_text.should_not be_nil
20
+ end
21
+ end
22
+
23
+ it "should able to retrieving own calendars" do
24
+ feed = @service.find_feed(:url => GData::CalendarService::OWN_CALENDAR_URL)
25
+ feed.should_not be_nil
26
+ entries = feed.entries
27
+ entries.size.should > 0
28
+ entries.each do |e|
29
+ e.title.plain_text.should_not be_nil
30
+ end
31
+ end
32
+
33
+ # Commented out if you run this test case too many times which will hit
34
+ # the API throttle limit
35
+ it "should be able to create, update and delete new calendars" do
36
+ # Create a new calendar
37
+ calendar = GData::CalendarEntry.new(
38
+ :title => "New Calendar".to_plain_text,
39
+ :summary => "This is a new Calendar.".to_plain_text,
40
+ :time_zone => GData::TimeZoneProperty.new('America/Los_Angeles'),
41
+ :hidden => GData::HiddenProperty::FALSE,
42
+ :color => GData::ColorProperty.new('#2952A3'))
43
+ calendar.add_location GData::Where.new("", "", "Palo Alto")
44
+
45
+ calendar = @service.create_entry(:url => GData::CalendarService::OWN_CALENDAR_URL,
46
+ :entry => calendar)
47
+ calendar.should_not be_nil
48
+ calendar.id.should_not be_nil
49
+ calendar.title.plain_text.should == "New Calendar"
50
+
51
+ #Update a new calendar
52
+ calendar.title = "New Title".to_gdata
53
+ calendar = calendar.update
54
+ calendar.title.plain_text.should == "New Title"
55
+
56
+ # Delete the calendar
57
+ lambda do
58
+ calendar.delete
59
+ end.should_not raise_error
60
+
61
+ feed = @service.find_feed(:url => GData::CalendarService::OWN_CALENDAR_URL)
62
+ entries = feed.entries
63
+ entries.each do |e|
64
+ e.id.should_not == calendar.id
65
+ end
66
+ end
67
+
68
+ it "should be able to create, update, and delete events" do
69
+ event = GData::CalendarEventEntry.new(
70
+ :title => 'New Event'.to_plain_text,
71
+ :content => 'New Content'.to_plain_text)
72
+ event_time = GData::When.new(
73
+ :start_time => Time.local(2010, "dec", 25, 20, 0, 0),
74
+ :end_time => Time.local(2010, "dec", 25, 21, 0, 0))
75
+ event.add_time(event_time)
76
+ event = @service.create_entry(:url => GData::CalendarService::DEFAULT_CALENDAR_URI,
77
+ :entry => event)
78
+ event.id.should_not be_nil
79
+
80
+ event.title = 'New Title'.to_plain_text
81
+ event = event.update
82
+ event.title.plain_text.should == 'New Title'
83
+
84
+ lambda do
85
+ event.delete
86
+ end.should_not raise_error
87
+ end
88
+
89
+ it "should able to quick add an event" do
90
+ event = GData::CalendarEventEntry.new(
91
+ :content => "Say Hi to Jerry Oct 31, 2010 12pm-1pm".to_plain_text,
92
+ :quick_add => true)
93
+
94
+ event = @service.create_entry(:url => GData::CalendarService::DEFAULT_CALENDAR_URI,
95
+ :entry => event)
96
+
97
+ event.id.should_not be_nil
98
+
99
+ event.title.plain_text.should == "Say Hi to Jerry"
100
+ start_time = Time.from_joda_time(event.times.first.start_time)
101
+ start_time.should == Time.local(2010, 10, 31, 12, 0, 0, "-07:00", nil)
102
+
103
+ lambda do
104
+ event.delete
105
+ end.should_not raise_error
106
+ end
107
+
108
+ it "should be able to create recurring events" do
109
+ recur_data = "DTSTART;VALUE=DATE:20070501\n" +
110
+ "DTEND;VALUE=DATE:20070502\n" +
111
+ "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904"
112
+ recur = GData::Recurrence.new(recur_data)
113
+ event = GData::CalendarEventEntry.new(:recurrence => recur)
114
+
115
+ event = @service.create_entry(:url => GData::CalendarService::DEFAULT_CALENDAR_URI,
116
+ :entry => event)
117
+
118
+ event.id.should_not be_nil
119
+ event.recurrence.value.should == recur_data
120
+
121
+ lambda do
122
+ event.delete
123
+ end.should_not raise_error
124
+ end
125
+
126
+ # Copied from Google: When working with batch requests, the size of the request must be
127
+ # under a megabyte and it's best to limit batches to 50-100 operations at a time.
128
+ it "should be able to perform multiple operations with a batch request" do
129
+ # Create a test calendar so this test case won't have dependency on the test account
130
+ calendar = GData::CalendarEntry.new(:title => "Test Calendar".to_plain_text)
131
+ calendar = @service.create_entry(:url => GData::CalendarService::OWN_CALENDAR_URL,
132
+ :entry => calendar)
133
+ calendar_url = calendar.get_link(nil, nil).href
134
+
135
+ # Create some events
136
+ 1.upto 3 do |i|
137
+ event = GData::CalendarEventEntry.new(:title => "Test Event #{i}".to_plain_text)
138
+ event = @service.create_entry(:url => calendar_url, :entry => event)
139
+ end
140
+
141
+ # Give it a small delay such that the changes is propagated
142
+ sleep(2)
143
+
144
+ # Get some events to operate on
145
+ feed = @service.find_feed(:url => calendar_url)
146
+
147
+ insert_event = GData::CalendarEventEntry.new(:title => 'first batch event'.to_plain_text)
148
+ GData::BatchUtils.set_batch_id(insert_event, "1")
149
+ GData::BatchUtils.set_batch_operation_type(insert_event, GData::BatchOperationType::INSERT)
150
+
151
+ query_event = feed.entries[0]
152
+ GData::BatchUtils.set_batch_id(query_event, "2")
153
+ GData::BatchUtils.set_batch_operation_type(query_event, GData::BatchOperationType::QUERY)
154
+
155
+ update_event = feed.entries[1]
156
+ update_event.title = 'update via batch'.to_plain_text
157
+ GData::BatchUtils.set_batch_id(update_event, "3")
158
+ GData::BatchUtils.set_batch_operation_type(update_event, GData::BatchOperationType::UPDATE)
159
+
160
+ delete_event = feed.entries[2]
161
+ GData::BatchUtils.set_batch_id(delete_event, "4")
162
+ GData::BatchUtils.set_batch_operation_type(delete_event, GData::BatchOperationType::DELETE)
163
+
164
+ batch_request = GData::CalendarEventFeed.new
165
+ batch_request.entries << insert_event
166
+ batch_request.entries << query_event
167
+ batch_request.entries << update_event
168
+ batch_request.entries << delete_event
169
+
170
+ # Get the batch link URL and send the batch request there
171
+ batch_url = feed.get_link(GData::Link::Rel::FEED_BATCH, GData::Link::Type::ATOM).href
172
+ batch_response = @service.create_batch(:url => batch_url, :feed => batch_request)
173
+
174
+ batch_response.entries.each do |entry|
175
+ unless GData::BatchUtils.success?(entry)
176
+ batch_id = GData::BatchUtils.getBatchId(entry)
177
+ status = GData::BatchUtils.getBatchStatus(entry)
178
+ puts "#{batch_id} failed (#{status.reason}) #{status.content}"
179
+ end
180
+ GData::BatchUtils.success?(entry).should == true
181
+ end
182
+
183
+ # Clean up
184
+ sleep(3)
185
+ calendar.delete
186
+ end
187
+
188
+ it "should be able to add extented properties to the event" do
189
+ event = GData::CalendarEventEntry.new(
190
+ :title => 'New Event'.to_plain_text,
191
+ :content => 'New Content'.to_plain_text)
192
+ event_time = GData::When.new(
193
+ :start_time => Time.local(2010, "dec", 25, 20, 0, 0),
194
+ :end_time => Time.local(2010, "dec", 25, 21, 0, 0))
195
+ event.add_time(event_time)
196
+
197
+ property = GData::ExtendedProperty.new(
198
+ :name => 'http://schemas.presdo.com/2009#event.id',
199
+ :value => '1234')
200
+ event.add_extended_property(property)
201
+
202
+ event = @service.create_entry(:url => GData::CalendarService::DEFAULT_CALENDAR_URI,
203
+ :entry => event)
204
+ event.id.should_not be_nil
205
+
206
+ event.extended_properties.first.name.should == 'http://schemas.presdo.com/2009#event.id'
207
+ event.extended_properties.first.value.should == '1234'
208
+
209
+ lambda do
210
+ event.delete
211
+ end.should_not raise_error
212
+ end
213
+
214
+ describe "Retrieving events" do
215
+ before(:all) do
216
+ create_service
217
+
218
+ @calendar = GData::CalendarEntry.new(
219
+ :title => "Test Calendar".to_plain_text,
220
+ :time_zone => GData::TimeZoneProperty.new('America/Los_Angeles'))
221
+ @calendar = @service.create_entry(:url => GData::CalendarService::OWN_CALENDAR_URL,
222
+ :entry => @calendar)
223
+ @calendar_url = @calendar.get_link(nil, nil).href
224
+
225
+ @event = GData::CalendarEventEntry.new(:title => 'Test Event'.to_plain_text)
226
+ @event_time = GData::When.new(
227
+ :start_time => Time.local(2010, "dec", 25, 20, 0, 0),
228
+ :end_time => Time.local(2010, "dec", 25, 21, 0, 0))
229
+ @event.add_time(@event_time)
230
+ @event = @service.create_entry(:url => @calendar_url, :entry => @event)
231
+ end
232
+
233
+ after(:all) do
234
+ sleep(3)
235
+ @calendar.delete
236
+ end
237
+
238
+ it "should retrieve events without query parameters" do
239
+ feed = @service.find_feed(:url => @calendar_url)
240
+ feed.should_not be_nil
241
+ entries = feed.entries
242
+ entries.size.should == 1
243
+ entries.first.id.should == @event.id
244
+ end
245
+
246
+ it "should retrieve events for a specified date range" do
247
+ query = GData::CalendarQuery.new(
248
+ :url => @calendar_url,
249
+ :minimum_start_time => Time.local(2010, "dec", 25, 0, 0, 0),
250
+ :maximum_start_time => Time.local(2010, "dec", 26, 0, 0, 0))
251
+
252
+ feed = @service.find_feed(:query => query)
253
+ feed.should_not be_nil
254
+ entries = feed.entries
255
+ entries.size.should == 1
256
+ entries.first.id.should == @event.id
257
+
258
+ query = GData::CalendarQuery.new(@calendar_url)
259
+ query.minimum_start_time = Time.local(2010, "dec", 20, 0, 0, 0).to_joda_time
260
+ query.maximum_start_time = Time.local(2010, "dec", 21, 0, 0, 0).to_joda_time
261
+
262
+ feed = @service.find_feed(:query => query)
263
+ feed.should_not be_nil
264
+ feed.entries.size.should == 0
265
+ end
266
+
267
+ it "should retrieve events matching a full text query" do
268
+ query = GData::CalendarQuery.new(
269
+ :url => @calendar_url,
270
+ :full_text_query => "Test Event")
271
+
272
+ feed = @service.find_feed(:query => query)
273
+ feed.should_not be_nil
274
+ entries = feed.entries
275
+ entries.size.should == 1
276
+ entries.first.id.should == @event.id
277
+ end
278
+
279
+ end
280
+
281
+ def create_service
282
+ @service = GData::CalendarService.new DEFAULT_APPLICATION_NAME
283
+ # Use OAuth
284
+ credentials = GData::GoogleOAuthParameters.new
285
+ credentials.attributes = {
286
+ :consumer_key => CONSUMER_KEY,
287
+ :consumer_secret => CONSUMER_SECRET,
288
+ :token => TOKEN,
289
+ :token_secret => TOKEN_SECRET }
290
+ @service.oauth_credentials = credentials
291
+ # Use AuthSubToken
292
+ # @service.auth_sub_token = SESSION_TOKEN
293
+ @service
294
+ end
295
+
296
+ end