googlecalendar 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 (3) hide show
  1. data/CHANGELOG +10 -0
  2. data/lib/googlecalendar.rb +72 -7
  3. metadata +3 -3
data/CHANGELOG CHANGED
@@ -1,5 +1,15 @@
1
1
  = Versions
2
2
 
3
+ === 0.0.5 (Spet 24th, 2007)
4
+ * You can now set a different google url in GData class (default value is www.google.com)
5
+ * Adding code to post an event to other calendar than the default one
6
+ * Get the list of calendar associated with the user.
7
+ Thanks to Christos Trochalakis for his contribution :)
8
+ * Handle hosted email account (different domain name emails)
9
+ Thanks to Sam Morrison for his contribution :)
10
+ * Add description and location informations to available fields
11
+ Thanks to Kalle Saas for his contribution :)
12
+
3
13
  === 0.0.4 (June 8th, 2007)
4
14
  * Can add simple events now
5
15
  ** Added a GData class and an example of how to use it
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
3
  require 'uri'
4
+ require "rexml/document"
4
5
 
5
6
  class Calendar
6
7
  attr_accessor :product_id, :version, :scale, :method, :events
@@ -24,8 +25,17 @@ class Calendar
24
25
  end
25
26
  end
26
27
 
28
+ class GCalendar
29
+ attr_reader :title, :url
30
+
31
+ def initialize(title, url)
32
+ @title = title
33
+ @url = url
34
+ end
35
+ end
36
+
27
37
  class Event
28
- attr_accessor :start_date, :end_date, :time_stamp, :class_name, :created, :last_modified, :status, :summary, :rrule
38
+ attr_accessor :start_date, :end_date, :time_stamp, :class_name, :created, :last_modified, :status, :summary, :description, :location, :rrule
29
39
 
30
40
  def to_s
31
41
  data = "---------- event ----------\n"
@@ -38,6 +48,8 @@ class Event
38
48
  data << 'status: ' + @status.to_s + "\n"
39
49
  data << 'rrule: ' + @rrule.to_s + "\n"
40
50
  data << 'summary: ' + @summary.to_s + "\n"
51
+ data << 'desription: ' + @desription.to_s + "\n"
52
+ data << 'location: ' + @ location.to_s + "\n"
41
53
  return data
42
54
  end
43
55
 
@@ -69,7 +81,13 @@ end
69
81
  #More informations
70
82
  #_Google calendar API: http://code.google.com/apis/calendar/developers_guide_protocol.html_
71
83
  class GData
72
-
84
+ attr_accessor :google_url
85
+
86
+ def initialize(google='www.google.com')
87
+ @calendars = []
88
+ @google_url = google
89
+ end
90
+
73
91
  #Log into google data, this method needs to be call once before using other methods of the class
74
92
  #* Email The user's email address.
75
93
  #* Passwd The user's password.
@@ -78,11 +96,12 @@ class GData
78
96
  #+companyName-applicationName-versionID+
79
97
  def login(email, pwd, source='googlecalendar.rubyforge.org-googlecalendar-default')
80
98
  # service The string cl, which is the service name for Google Calendar.
81
-
82
- response = Net::HTTPS.post_form(URI.parse('https://www.google.com/accounts/ClientLogin'),
99
+ @user_id = email
100
+ response = Net::HTTPS.post_form(URI.parse("https://#{@google_url}/accounts/ClientLogin"),
83
101
  { 'Email' => email,
84
102
  'Passwd' => pwd,
85
103
  'source' => source,
104
+ 'accountType' => 'HOSTED_OR_GOOGLE',
86
105
  'service' => 'cl'})
87
106
  response.error! unless response.kind_of? Net::HTTPSuccess
88
107
  @token = response.body.split(/=/).last
@@ -101,10 +120,20 @@ class GData
101
120
  #* :where
102
121
  #* :startTime '2007-06-06T15:00:00.000Z'
103
122
  #* :endTime '2007-06-06T17:00:00.000Z'
104
- def new_event(event={})
123
+ def new_event(event={},calendar = nil)
105
124
  new_event = template(event)
106
- http = Net::HTTP.new('www.google.com', 80)
107
- response, data = http.post('/calendar/feeds/default/private/full', new_event, @headers)
125
+
126
+ #Get calendar url
127
+ calendar_url = if calendar
128
+ get_calendars
129
+ find_calendar(calendar).url
130
+ else
131
+ # We will use user'default calendar in this case
132
+ '/calendar/feeds/default/private/full'
133
+ end
134
+
135
+ http = Net::HTTP.new(@google_url, 80)
136
+ response, data = http.post(calendar_url, new_event, @headers)
108
137
  case response
109
138
  when Net::HTTPSuccess, Net::HTTPRedirection
110
139
  redirect_response, redirect_data = http.post(response['location'], new_event, @headers)
@@ -118,7 +147,35 @@ class GData
118
147
  response.error!
119
148
  end
120
149
  end
150
+
151
+ # Retreive user's calendar urls.
152
+ def get_calendars
153
+ http = Net::HTTP.new(@google_url, 80)
154
+ response, data = http.get("http://#{@google_url}/calendar/feeds/" + @user_id, @headers)
155
+ case response
156
+ when Net::HTTPSuccess, Net::HTTPRedirection
157
+ redirect_response, redirect_data = http.get(response['location'], @headers)
158
+ case response
159
+ when Net::HTTPSuccess, Net::HTTPRedirection
160
+ doc = REXML::Document.new redirect_data
161
+ doc.elements.each('//entry')do |e|
162
+ title = e.elements['title'].text
163
+ url = e.elements['link'].attributes['href']
164
+ @calendars << GCalendar.new(title, url.sub!("http://#{@google_url}",''))
165
+ end
166
+ return redirect_response
167
+ else
168
+ response.error!
169
+ end
170
+ else
171
+ response.error!
172
+ end
173
+ end
121
174
 
175
+ def find_calendar(x)
176
+ @calendars.find {|c| c.title.match x}
177
+ end
178
+
122
179
  # The atom event template to submit a new event
123
180
  def template(event={})
124
181
  content = <<EOF
@@ -251,6 +308,14 @@ class ICALParser
251
308
  def handle_vevent_rrule(value)
252
309
  @calendar.events.last.rrule = value
253
310
  end
311
+
312
+ def handle_vevent_description(value)
313
+ @calendar.events.last.description = value
314
+ end
315
+
316
+ def handle_vevent_location(value)
317
+ @calendar.events.last.location = value
318
+ end
254
319
  end
255
320
 
256
321
  def parse(data)
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: googlecalendar
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.4
7
- date: 2007-06-08 00:00:00 +02:00
6
+ version: 0.0.5
7
+ date: 2007-09-24 00:00:00 +02:00
8
8
  summary: Google Calendar api for Ruby
9
9
  require_paths:
10
10
  - lib