vcita-gcal4ruby 0.7.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.
@@ -0,0 +1,205 @@
1
+ # Author:: Mike Reich (mike@seabourneconsulting.com)
2
+ # Copyright:: Copyright (C) 2010 Mike Reich
3
+ # License:: GPL v2
4
+ #--
5
+ # Licensed under the General Public License (GPL), Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ #
15
+ # Feel free to use and update, but be sure to contribute your
16
+ # code back to the project and attribute as required by the license.
17
+ #++
18
+ require 'gdata4ruby'
19
+ require 'gdata4ruby/gdata_object'
20
+ require 'gdata4ruby/utils/utils'
21
+ require 'gdata4ruby/acl/access_rule'
22
+ require 'gcal4ruby/calendar'
23
+ require 'gcal4ruby/event'
24
+ require 'gcal4ruby/recurrence'
25
+ require 'rexml/document'
26
+
27
+ module GCal4Ruby
28
+ #The service class is the main handler for all direct interactions with the
29
+ #Google Calendar API. A service represents a single user account. Each user
30
+ #account can have multiple calendars, so you'll need to find the calendar you
31
+ #want from the service, using the Calendar#find class method.
32
+ #=Usage
33
+ #
34
+ #1. Authenticate
35
+ # service = Service.new
36
+ # service.authenticate("user@gmail.com", "password")
37
+ #
38
+ #2. Get Calendar List
39
+ # calendars = service.calendars
40
+ #
41
+ class Service
42
+ @@calendar_list_feed = 'www.google.com/calendar/feeds/default/owncalendars/full'
43
+
44
+ # The type of GData4Ruby service we want to use
45
+ attr_accessor :gdata_service
46
+
47
+ # Convenience attribute contains the currently authenticated account name
48
+ attr_accessor :account
49
+
50
+ # Determines whether GCal4Ruby ensures a calendar is public. Setting this to false can increase speeds by
51
+ # 50% but can cause errors if you try to do something to a calendar that is not public and you don't have
52
+ # adequate permissions
53
+ attr_accessor :check_public
54
+
55
+ #Accepts an optional attributes hash for initialization values
56
+ def initialize(attributes = {})
57
+ # If the user has specified the type of GData4Ruby class they want, instantiate it
58
+ if(attributes.has_key?(:GData4RubyService))
59
+ @gdata_service = GData4Ruby.const_get(attributes[:GData4RubyService]).new(attributes)
60
+ end
61
+ # Otherwise use the default service
62
+ @gdata_service ||= GData4Ruby::Service.new(attributes)
63
+ attributes.each do |key, value|
64
+ if self.respond_to?("#{key}=")
65
+ self.send("#{key}=", value)
66
+ end
67
+ end
68
+ @check_public ||= true
69
+ @account ||= "default"
70
+ @debug ||= false
71
+ log("Check Public: #{check_public}")
72
+ end
73
+
74
+ def debug
75
+ return @debug
76
+ end
77
+
78
+ def debug=(value)
79
+ @debug=value
80
+ @gdata_service.debug = value
81
+ end
82
+
83
+ def log(string)
84
+ puts string if debug
85
+ end
86
+
87
+ def default_event_feed
88
+ return create_url("www.google.com/calendar/feeds/#{@account}/private/full")
89
+ end
90
+
91
+ # The authenticate method passes an for the service to use to access Google's servers
92
+ # If authentication succeeds, returns true, otherwise raises the AuthenticationFailed error.
93
+ def authenticate(options = {})
94
+ if not options.has_key?(:service)
95
+ options[:service] = 'cl'
96
+ end
97
+ @gdata_service.authenticate(options)
98
+ end
99
+
100
+ #Helper function to reauthenticate to a new Google service without having to re-set credentials.
101
+ def reauthenticate(options = {})
102
+ if not options.has_key?(:service)
103
+ options[:service] = 'cl'
104
+ end
105
+ @gdata_service.reauthenticate(options)
106
+ end
107
+
108
+ # Passes a request along from a GData4Ruby GDataObject to a GData4Ruby Base (Service) to be invoked
109
+ def send_request(request)
110
+ if not @gdata_service.authenticated?
111
+ raise GData4Ruby::NotAuthenticated
112
+ end
113
+ @gdata_service.send_request(request)
114
+ end
115
+
116
+
117
+ #Returns an array of Calendar objects for each calendar associated with
118
+ #the authenticated account.
119
+ # If you want to only load some attributes, you can pass in an array of
120
+ # string attributes via options[:fields], for example ["@gd:*", "id", "title"]
121
+ def calendars(options = {})
122
+ if(options[:fields])
123
+ params = "?fields=entry(#{options[:fields].join(",")})"
124
+ end
125
+ params ||= ""
126
+ ret = send_request(GData4Ruby::Request.new(:get, create_url(@@calendar_list_feed + params), nil, {"max-results" => "10000"}))
127
+ cals = []
128
+ REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |entry|
129
+ entry = GData4Ruby::Utils.add_namespaces(entry)
130
+ cal = Calendar.new(self, {:debug => debug})
131
+ log(entry.inspect)
132
+ cal.load(entry.to_s)
133
+ cals << cal
134
+ end
135
+ return cals
136
+ end
137
+
138
+
139
+ #Returns an array of Event objects for each event in this account
140
+ def events
141
+ ret = send_request(GData4Ruby::Request.new(:get, default_event_feed, nil, {"max-results" => "10000"}))
142
+ events = []
143
+ REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |entry|
144
+ entry = GData4Ruby::Utils.add_namespaces(entry)
145
+ event = Event.new(self, {:debug => debug})
146
+ event.load(entry.to_s)
147
+ events << event
148
+ end
149
+ return events
150
+ end
151
+
152
+ # Builds a URL
153
+ def create_url(path)
154
+ return @gdata_service.create_url(path)
155
+ end
156
+
157
+ #Helper function to return a formatted iframe embedded google calendar. Parameters are:
158
+ #1. *cals*: either an array of calendar ids, or <em>:all</em> for all calendars, or <em>:first</em> for the first (usally default) calendar
159
+ #2. *params*: a hash of parameters that affect the display of the embedded calendar. Accepts any parameter that the google iframe recognizes. Here are the most common:
160
+ # height:: the height of the embedded calendar in pixels
161
+ # width:: the width of the embedded calendar in pixels
162
+ # title:: the title to display
163
+ # bgcolor:: the background color. Limited choices, see google docs for allowable values.
164
+ # showTitle:: set to '0' to hide the title
165
+ # showDate:: set to '0' to hide the current date
166
+ # showNav:: set to '0 to hide the navigation tools
167
+ # showPrint:: set to '0' to hide the print icon
168
+ # showTabs:: set to '0' to hide the tabs
169
+ # showCalendars:: set to '0' to hide the calendars selection drop down
170
+ # showTz:: set to '0' to hide the timezone selection
171
+ # border:: the border width in pixels
172
+ # dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
173
+ # privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
174
+ # ctz:: The timezone to convert event times to
175
+ #3. *colors*: a hash of calendar ids as key and color values as associated hash values. Example: {'test@gmail.com' => '#7A367A'}
176
+ def to_iframe(cals, params = {}, colors = {})
177
+ params[:height] ||= "600"
178
+ params[:width] ||= "600"
179
+ params[:title] ||= (self.account ? self.account : '')
180
+ params[:bgcolor] ||= "#FFFFFF"
181
+ params[:border] ||= "0"
182
+ params.each{|key, value| params[key] = CGI::escape(value)}
183
+ output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}&"
184
+
185
+ if cals.is_a?(Array)
186
+ for c in cals
187
+ output += "src=#{c}&"
188
+ if colors and colors[c]
189
+ output += "color=%23#{colors[c].gsub("#", "")}&"
190
+ end
191
+ end
192
+ elsif cals == :all
193
+ cal_list = calendars()
194
+ for c in cal_list
195
+ output += "src=#{c.id}&"
196
+ end
197
+ elsif cals == :first
198
+ cal_list = calendars()
199
+ output += "src=#{cal_list[0].id}&"
200
+ end
201
+
202
+ "<iframe src='#{create_url("www.google.com/calendar/embed?"+output)}' style='#{params[:border]} px solid;' width='#{params[:width]}' height='#{params[:height]}' frameborder='#{params[:border]}' scrolling='no'></iframe>"
203
+ end
204
+ end
205
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vcita-gcal4ruby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 2
10
+ version: 0.7.2
11
+ platform: ruby
12
+ authors:
13
+ - Mike Reich
14
+ - Anthony Underwood
15
+ - David Pitman
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-12-09 00:00:00 +02:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: vcita-gdata4ruby
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 19
32
+ segments:
33
+ - 0
34
+ - 2
35
+ - 2
36
+ version: 0.2.2
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ description:
40
+ email:
41
+ - mike@seabourneconsulting.com
42
+ - email2ants@gmail.com
43
+ - ui-design@vestaldesign.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - README.md
50
+ files:
51
+ - CHANGELOG
52
+ - README.md
53
+ - lib/gcal4ruby.rb
54
+ - lib/gcal4ruby/calendar.rb
55
+ - lib/gcal4ruby/event.rb
56
+ - lib/gcal4ruby/recurrence.rb
57
+ - lib/gcal4ruby/service.rb
58
+ has_rdoc: true
59
+ homepage: https://github.com/vcita/GData4Ruby
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.6.2
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: A full featured wrapper for interacting with the Google Calendar API
92
+ test_files: []
93
+