googlecalendar 0.0.3 → 0.0.4
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/CHANGELOG +4 -0
- data/lib/googlecalendar.rb +97 -2
- metadata +3 -3
data/CHANGELOG
CHANGED
data/lib/googlecalendar.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'net/http'
|
2
|
+
require 'net/https'
|
2
3
|
require 'uri'
|
3
4
|
|
4
5
|
class Calendar
|
@@ -52,6 +53,100 @@ class Event
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
56
|
+
#
|
57
|
+
# Make it east to use some of the convenience methods using https
|
58
|
+
#
|
59
|
+
module Net
|
60
|
+
class HTTPS < HTTP
|
61
|
+
def initialize(address, port = nil)
|
62
|
+
super(address, port)
|
63
|
+
self.use_ssl = true
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#A ruby class to wrap calls to the Google Data API
|
69
|
+
#More informations
|
70
|
+
#_Google calendar API: http://code.google.com/apis/calendar/developers_guide_protocol.html_
|
71
|
+
class GData
|
72
|
+
|
73
|
+
#Log into google data, this method needs to be call once before using other methods of the class
|
74
|
+
#* Email The user's email address.
|
75
|
+
#* Passwd The user's password.
|
76
|
+
#* source Identifies your client application. Should take the form companyName-applicationName-versionID
|
77
|
+
#*Warning* Replace the default value with something like:
|
78
|
+
#+companyName-applicationName-versionID+
|
79
|
+
def login(email, pwd, source='googlecalendar.rubyforge.org-googlecalendar-default')
|
80
|
+
# 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'),
|
83
|
+
{ 'Email' => email,
|
84
|
+
'Passwd' => pwd,
|
85
|
+
'source' => source,
|
86
|
+
'service' => 'cl'})
|
87
|
+
response.error! unless response.kind_of? Net::HTTPSuccess
|
88
|
+
@token = response.body.split(/=/).last
|
89
|
+
@headers = {
|
90
|
+
'Authorization' => "GoogleLogin auth=#{@token}",
|
91
|
+
'Content-Type' => 'application/atom+xml'
|
92
|
+
}
|
93
|
+
return @token
|
94
|
+
end
|
95
|
+
|
96
|
+
#'event' param is a hash containing
|
97
|
+
#* :title
|
98
|
+
#* :content
|
99
|
+
#* :author
|
100
|
+
#* :email
|
101
|
+
#* :where
|
102
|
+
#* :startTime '2007-06-06T15:00:00.000Z'
|
103
|
+
#* :endTime '2007-06-06T17:00:00.000Z'
|
104
|
+
def new_event(event={})
|
105
|
+
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)
|
108
|
+
case response
|
109
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
110
|
+
redirect_response, redirect_data = http.post(response['location'], new_event, @headers)
|
111
|
+
case response
|
112
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
113
|
+
return redirect_response
|
114
|
+
else
|
115
|
+
response.error!
|
116
|
+
end
|
117
|
+
else
|
118
|
+
response.error!
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# The atom event template to submit a new event
|
123
|
+
def template(event={})
|
124
|
+
content = <<EOF
|
125
|
+
<?xml version="1.0"?>
|
126
|
+
<entry xmlns='http://www.w3.org/2005/Atom'
|
127
|
+
xmlns:gd='http://schemas.google.com/g/2005'>
|
128
|
+
<category scheme='http://schemas.google.com/g/2005#kind'
|
129
|
+
term='http://schemas.google.com/g/2005#event'></category>
|
130
|
+
<title type='text'>#{event[:title]}</title>
|
131
|
+
<content type='text'>#{event[:content]}</content>
|
132
|
+
<author>
|
133
|
+
<name>#{event[:author]}</name>
|
134
|
+
<email>#{event[:email]}</email>
|
135
|
+
</author>
|
136
|
+
<gd:transparency
|
137
|
+
value='http://schemas.google.com/g/2005#event.opaque'>
|
138
|
+
</gd:transparency>
|
139
|
+
<gd:eventStatus
|
140
|
+
value='http://schemas.google.com/g/2005#event.confirmed'>
|
141
|
+
</gd:eventStatus>
|
142
|
+
<gd:where valueString='#{event[:where]}'></gd:where>
|
143
|
+
<gd:when startTime='#{event[:startTime]}'
|
144
|
+
endTime='#{event[:endTime]}'></gd:when>
|
145
|
+
</entry>
|
146
|
+
EOF
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
55
150
|
class ICALParser
|
56
151
|
attr_reader :calendar
|
57
152
|
|
@@ -163,8 +258,8 @@ def parse(data)
|
|
163
258
|
parser.parse(data)
|
164
259
|
end
|
165
260
|
|
166
|
-
def scan(ical_url)
|
167
|
-
Net::HTTP.start(
|
261
|
+
def scan(ical_url, base_url='www.google.com')
|
262
|
+
Net::HTTP.start(base_url, 80) do |http|
|
168
263
|
response, data = http.get(ical_url)
|
169
264
|
case response
|
170
265
|
when Net::HTTPSuccess, Net::HTTPRedirection
|
metadata
CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: googlecalendar
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.0.4
|
7
|
+
date: 2007-06-08 00:00:00 +02:00
|
8
8
|
summary: Google Calendar api for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: cogito@rubyforge.org
|
12
12
|
homepage: http://benjamin.francisoud.googlepages.com/googlecalendar
|
13
13
|
rubyforge_project: googlecalendar
|
14
|
-
description: "The Google Calendar project provides: Export features (text file, simple html page
|
14
|
+
description: "The Google Calendar project provides: Export features (text file, simple html page), Ruby api's to connect to google calendars, A plugin for Ruby On Rails."
|
15
15
|
autorequire: googlecalendar
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|