Class: GCal4Ruby::Base
- Inherits:
-
Object
- Object
- GCal4Ruby::Base
- Defined in:
- lib/gcal4ruby/base.rb
Overview
The Base class includes the basic HTTP methods for sending and receiving messages from the Google Calendar API. You shouldn’t have to use this class directly, rather access the functionality through the Service subclass.
Direct Known Subclasses
Constant Summary collapse
- AUTH_URL =
"https://www.google.com/accounts/ClientLogin"
- CALENDAR_LIST_FEED =
"http://www.google.com/calendar/feeds/default/allcalendars/full"
Instance Attribute Summary collapse
-
#debug ⇒ Object
If set to true, debug will dump all raw HTTP requests and responses.
-
#proxy_info ⇒ Object
Contains the ProxyInfo object for using a proxy server.
Instance Method Summary collapse
-
#send_delete(url, header = nil) ⇒ Object
Sends an HTTP DELETE request.
-
#send_get(url, header = nil) ⇒ Object
Sends an HTTP GET request.
-
#send_post(url, content, header = nil) ⇒ Object
Sends an HTTP POST request.
-
#send_put(url, content, header = nil) ⇒ Object
Sends an HTTP PUT request.
Instance Attribute Details
#debug ⇒ Object
If set to true, debug will dump all raw HTTP requests and responses
105 106 107 |
# File 'lib/gcal4ruby/base.rb', line 105 def debug @debug end |
#proxy_info ⇒ Object
Contains the ProxyInfo object for using a proxy server
102 103 104 |
# File 'lib/gcal4ruby/base.rb', line 102 def proxy_info @proxy_info end |
Instance Method Details
#send_delete(url, header = nil) ⇒ Object
Sends an HTTP DELETE request. The header should be a hash of name/value pairs.
Returns the Net::HTTPResponse object on succces, or raises the appropriate error if a non 20x response code is received.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/gcal4ruby/base.rb', line 209 def send_delete(url, header = nil) header = auth_header(header) ret = nil location = URI.parse(url) https = get_http_object(location) puts "url = "+url if @debug if location.scheme == 'https' puts "SSL True" if @debug https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE end puts "Starting post\nHeader: #{header}\n" if @debug https.start do |http| ret = http.delete(location.to_s, header) end while ret.is_a?(Net::HTTPRedirection) puts "Redirect recieved, resending post" if @debug https.start do |http| ret = http.delete(ret['location'], header) end end if ret.is_a?(Net::HTTPSuccess) puts "20x response recieved\nResponse: \n"+ret.read_body if @debug return true else puts "invalid response received: "+ret.code if @debug raise HTTPDeleteFailed, ret.body end end |
#send_get(url, header = nil) ⇒ Object
Sends an HTTP GET request. The header should be a hash of name/value pairs.
Returns the Net::HTTPResponse object on succces, or raises the appropriate error if a non 20x response code is received.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/gcal4ruby/base.rb', line 176 def send_get(url, header = nil) header = auth_header(header) ret = nil location = URI.parse(url) http = get_http_object(location) puts "url = "+url if @debug if location.scheme == 'https' puts "SSL True" if @debug https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE end puts "Starting post\nHeader: #{header}\n" if @debug http.start do |http| ret = http.get(location.to_s, header) end while ret.is_a?(Net::HTTPRedirection) puts "Redirect recieved, resending get to #{ret['location']}" if @debug http.start do |http| ret = http.get(ret['location'], header) end end if ret.is_a?(Net::HTTPSuccess) puts "20x response recieved\nResponse: \n"+ret.read_body if @debug return ret else puts "Error recieved, resending get" if @debug raise HTTPGetFailed, ret.body end end |
#send_post(url, content, header = nil) ⇒ Object
Sends an HTTP POST request. The header should be a hash of name/value pairs.
Returns the Net::HTTPResponse object on succces, or raises the appropriate error if a non 20x response code is received.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/gcal4ruby/base.rb', line 110 def send_post(url, content, header=nil) header = auth_header(header) ret = nil location = URI.parse(url) https = get_http_object(location) puts "url = "+url if @debug if location.scheme == 'https' puts "SSL True" if @debug https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE end puts "Starting post\nHeader: #{header}\nContent: #{content}" if @debug https.start do |http| ret = http.post(location.to_s, content, header) end while ret.is_a?(Net::HTTPRedirection) puts "Redirect recieved, resending post" if @debug https.start do |http| ret = http.post(ret['location'], content, header) end end if ret.is_a?(Net::HTTPSuccess) puts "20x response recieved\nResponse: \n"+ret.read_body if @debug return ret else puts "invalid response received: "+ret.code if @debug raise HTTPPostFailed, ret.body end end |
#send_put(url, content, header = nil) ⇒ Object
Sends an HTTP PUT request. The header should be a hash of name/value pairs.
Returns the Net::HTTPResponse object on succces, or raises the appropriate error if a non 20x response code is received.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/gcal4ruby/base.rb', line 143 def send_put(url, content, header=nil) header = auth_header(header) ret = nil location = URI.parse(url) https = get_http_object(location) puts "url = "+url if @debug if location.scheme == 'https' puts "SSL True" if @debug https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE end puts "Starting post\nHeader: #{header}\nContent: #{content}" if @debug https.start do |http| ret = http.put(location.to_s, content, header) end while ret.is_a?(Net::HTTPRedirection) puts "Redirect recieved, resending post" if @debug https.start do |http| ret = http.put(ret['location'], content, header) end end if ret.is_a?(Net::HTTPSuccess) puts "20x response recieved\nResponse: \n"+ret.read_body if @debug return ret else puts "invalid response received: "+ret.code if @debug raise HTTPPutFailed, ret.body end end |