gcal4ruby 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/CHANGELOG +2 -0
  2. data/lib/gcal4ruby/base.rb +87 -65
  3. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
1
  #=CHANGELOG
2
+ #=*version 0.2.10
3
+ #* Fixed library support for Google Hosted Apps accounts running in forced SSL mode.
2
4
  #==version 0.2.9
3
5
  #* Fixed small SSL redirect bug due to variable misnaming in base.rb. Fix provided by JohnMetta
4
6
  #==version 0.2.8
@@ -111,25 +111,14 @@ module GCal4Ruby
111
111
  header = auth_header(header)
112
112
  ret = nil
113
113
  location = URI.parse(url)
114
- https = get_http_object(location)
115
114
  puts "url = "+url if @debug
116
- if location.scheme == 'https'
117
- puts "SSL True" if @debug
118
- https.use_ssl = true
119
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
120
- end
121
- puts "Starting post\nHeader: #{header}\nContent: #{content}" if @debug
122
- https.start do |http|
123
- ret = http.post(location.to_s, content, header)
124
- end
115
+ ret = do_post(location, header, content)
125
116
  while ret.is_a?(Net::HTTPRedirection)
126
- puts "Redirect recieved, resending post" if @debug
127
- https.start do |http|
128
- ret = http.post(ret['location'], content, header)
129
- end
117
+ puts "Redirect received, resending post" if @debug
118
+ ret = do_post(ret['location'], header, content)
130
119
  end
131
120
  if ret.is_a?(Net::HTTPSuccess)
132
- puts "20x response recieved\nResponse: \n"+ret.read_body if @debug
121
+ puts "20x response received\nResponse: \n"+ret.read_body if @debug
133
122
  return ret
134
123
  else
135
124
  puts "invalid response received: "+ret.code if @debug
@@ -137,6 +126,21 @@ module GCal4Ruby
137
126
  end
138
127
  end
139
128
 
129
+ def do_post(url, header, content)
130
+ ret = nil
131
+ if url.is_a?(String)
132
+ location = URI.parse(url)
133
+ else
134
+ location = url
135
+ end
136
+ http = get_http_object(location)
137
+ puts "Starting post\nHeader: #{header}\n" if @debug
138
+ http.start do |ht|
139
+ ret = ht.post(location.to_s, content, header)
140
+ end
141
+ return ret
142
+ end
143
+
140
144
  # Sends an HTTP PUT request. The header should be a hash of name/value pairs.
141
145
  # Returns the Net::HTTPResponse object on succces, or raises the appropriate
142
146
  # error if a non 20x response code is received.
@@ -144,31 +148,35 @@ module GCal4Ruby
144
148
  header = auth_header(header)
145
149
  ret = nil
146
150
  location = URI.parse(url)
147
- https = get_http_object(location)
148
151
  puts "url = "+url if @debug
149
- if location.scheme == 'https'
150
- puts "SSL True" if @debug
151
- https.use_ssl = true
152
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
153
- end
154
- puts "Starting post\nHeader: #{header}\nContent: #{content}" if @debug
155
- https.start do |http|
156
- ret = http.put(location.to_s, content, header)
157
- end
152
+ ret = do_put(location, header, content)
158
153
  while ret.is_a?(Net::HTTPRedirection)
159
- puts "Redirect recieved, resending post" if @debug
160
- https.start do |http|
161
- ret = http.put(ret['location'], content, header)
162
- end
154
+ puts "Redirect received, resending post" if @debug
155
+ ret = do_put(ret['location'], header, content)
163
156
  end
164
157
  if ret.is_a?(Net::HTTPSuccess)
165
- puts "20x response recieved\nResponse: \n"+ret.read_body if @debug
158
+ puts "20x response received\nResponse: \n"+ret.read_body if @debug
166
159
  return ret
167
160
  else
168
161
  puts "invalid response received: "+ret.code if @debug
169
162
  raise HTTPPutFailed, ret.body
170
163
  end
171
164
  end
165
+
166
+ def do_put(url, header, content)
167
+ ret = nil
168
+ if url.is_a?(String)
169
+ location = URI.parse(url)
170
+ else
171
+ location = url
172
+ end
173
+ http = get_http_object(location)
174
+ puts "Starting put\nHeader: #{header}\n" if @debug
175
+ http.start do |ht|
176
+ ret = ht.put(location.to_s, content, header)
177
+ end
178
+ return ret
179
+ end
172
180
 
173
181
  # Sends an HTTP GET request. The header should be a hash of name/value pairs.
174
182
  # Returns the Net::HTTPResponse object on succces, or raises the appropriate
@@ -177,32 +185,35 @@ module GCal4Ruby
177
185
  header = auth_header(header)
178
186
  ret = nil
179
187
  location = URI.parse(url)
180
- http = get_http_object(location)
181
188
  puts "url = "+url if @debug
182
- if location.scheme == 'https'
183
- #fixed http/https misnaming via JohnMetta
184
- puts "SSL True" if @debug
185
- http.use_ssl = true
186
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
187
- end
188
- puts "Starting post\nHeader: #{header}\n" if @debug
189
- http.start do |http|
190
- ret = http.get(location.to_s, header)
191
- end
189
+ ret = do_get(location, header)
192
190
  while ret.is_a?(Net::HTTPRedirection)
193
- puts "Redirect recieved, resending get to #{ret['location']}" if @debug
194
- http.start do |http|
195
- ret = http.get(ret['location'], header)
196
- end
191
+ puts "Redirect received from #{location.to_s}, resending get to #{ret['location']}" if @debug
192
+ ret = do_get(ret['location'], header)
197
193
  end
198
194
  if ret.is_a?(Net::HTTPSuccess)
199
- puts "20x response recieved\nResponse: \n"+ret.read_body if @debug
195
+ puts "20x response received\nResponse: \n"+ret.read_body if @debug
200
196
  return ret
201
197
  else
202
- puts "Error recieved, resending get" if @debug
198
+ puts "Error received, resending get" if @debug
203
199
  raise HTTPGetFailed, ret.body
204
200
  end
205
201
  end
202
+
203
+ def do_get(url, header)
204
+ ret = nil
205
+ if url.is_a?(String)
206
+ location = URI.parse(url)
207
+ else
208
+ location = url
209
+ end
210
+ http = get_http_object(location)
211
+ puts "Starting get\nHeader: #{header}\n" if @debug
212
+ http.start do |ht|
213
+ ret = ht.get(location.to_s, header)
214
+ end
215
+ return ret
216
+ end
206
217
 
207
218
  # Sends an HTTP DELETE request. The header should be a hash of name/value pairs.
208
219
  # Returns the Net::HTTPResponse object on succces, or raises the appropriate
@@ -211,40 +222,51 @@ module GCal4Ruby
211
222
  header = auth_header(header)
212
223
  ret = nil
213
224
  location = URI.parse(url)
214
- https = get_http_object(location)
215
225
  puts "url = "+url if @debug
216
- if location.scheme == 'https'
217
- puts "SSL True" if @debug
218
- https.use_ssl = true
219
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
220
- end
221
- puts "Starting post\nHeader: #{header}\n" if @debug
222
- https.start do |http|
223
- ret = http.delete(location.to_s, header)
224
- end
226
+ ret = do_delete(location, header)
225
227
  while ret.is_a?(Net::HTTPRedirection)
226
- puts "Redirect recieved, resending post" if @debug
227
- https.start do |http|
228
- ret = http.delete(ret['location'], header)
229
- end
228
+ puts "Redirect received, resending post" if @debug
229
+ ret = do_delete(ret['location'], header)
230
230
  end
231
231
  if ret.is_a?(Net::HTTPSuccess)
232
- puts "20x response recieved\nResponse: \n"+ret.read_body if @debug
232
+ puts "20x response received\nResponse: \n"+ret.read_body if @debug
233
233
  return true
234
234
  else
235
235
  puts "invalid response received: "+ret.code if @debug
236
236
  raise HTTPDeleteFailed, ret.body
237
237
  end
238
238
  end
239
+
240
+ def do_delete(url, header)
241
+ ret = nil
242
+ if url.is_a?(String)
243
+ location = URI.parse(url)
244
+ else
245
+ location = url
246
+ end
247
+ http = get_http_object(location)
248
+ puts "Starting get\nHeader: #{header}\n" if @debug
249
+ http.start do |ht|
250
+ ret = ht.delete(location.to_s, header)
251
+ end
252
+ return ret
253
+ end
239
254
 
240
255
  private
241
256
 
242
257
  def get_http_object(location)
243
258
  if @proxy_info and @proxy_info.address
244
- return Net::HTTP.new(location.host, location.port, @proxy_info.address, @proxy_info.port, @proxy_info.username, @proxy_info.password)
259
+ http = Net::HTTP.new(location.host, location.port, @proxy_info.address, @proxy_info.port, @proxy_info.username, @proxy_info.password)
245
260
  else
246
- return Net::HTTP.new(location.host, location.port)
247
- end
261
+ http = Net::HTTP.new(location.host, location.port)
262
+ end
263
+ if location.scheme == 'https'
264
+ #fixed http/http misnaming via JohnMetta
265
+ puts "SSL True" if @debug
266
+ http.use_ssl = true
267
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
268
+ end
269
+ return http
248
270
  end
249
271
 
250
272
  def auth_header(header)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcal4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Reich
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-11 00:00:00 +10:30
12
+ date: 2010-01-11 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies: []
15
15