Class: DropboxSessionBase
- Inherits:
-
Object
- Object
- DropboxSessionBase
- Defined in:
- lib/dropbox_sdk_v2.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#locale ⇒ Object
writeonly
Sets the attribute locale.
Instance Method Summary collapse
-
#do_get(path, params = nil, server = :api) ⇒ Object
:nodoc:.
- #do_http_with_body(uri, request, body) ⇒ Object
-
#do_post(path, params = nil, headers = nil, server = :api) ⇒ Object
:nodoc:.
-
#do_put(path, params = nil, headers = nil, body = nil, server = :api) ⇒ Object
:nodoc:.
-
#initialize(locale) ⇒ DropboxSessionBase
constructor
A new instance of DropboxSessionBase.
Constructor Details
#initialize(locale) ⇒ DropboxSessionBase
Returns a new instance of DropboxSessionBase.
154 155 156 |
# File 'lib/dropbox_sdk_v2.rb', line 154 def initialize(locale) @locale = locale end |
Instance Attribute Details
#locale=(value) ⇒ Object (writeonly)
Sets the attribute locale
152 153 154 |
# File 'lib/dropbox_sdk_v2.rb', line 152 def locale=(value) @locale = value end |
Instance Method Details
#do_get(path, params = nil, server = :api) ⇒ Object
:nodoc:
183 184 185 186 187 188 |
# File 'lib/dropbox_sdk_v2.rb', line 183 def do_get(path, params=nil, server=:api) # :nodoc: params ||= {} uri = build_url_with_params(path, params, server) do_http(uri, Net::HTTP::Get.new(uri.request_uri)) end |
#do_http_with_body(uri, request, body) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/dropbox_sdk_v2.rb', line 190 def do_http_with_body(uri, request, body) if body != nil if body.is_a?(Hash) # I don't understand why set_form_data wipes the content_type val content_type = request.content_type request.set_form_data(Dropbox::clean_params(body)) request.content_type = (content_type.nil?) ? "" : content_type elsif body.respond_to?(:read) if body.respond_to?(:length) request["Content-Length"] = body.length.to_s elsif body.respond_to?(:stat) && body.stat.respond_to?(:size) request["Content-Length"] = body.stat.size.to_s else raise ArgumentError, "Don't know how to handle 'body' (responds to 'read' but not to 'length' or 'stat.size')." end request.body_stream = body else s = body.to_s request["Content-Length"] = s.length request.body = s end end do_http(uri, request) end |
#do_post(path, params = nil, headers = nil, server = :api) ⇒ Object
:nodoc:
215 216 217 218 219 220 |
# File 'lib/dropbox_sdk_v2.rb', line 215 def do_post(path, params=nil, headers=nil, server=:api) # :nodoc: params ||= {} uri = build_url(path, server) do_http_with_body(uri, Net::HTTP::Post.new(uri.request_uri, headers), params) end |
#do_put(path, params = nil, headers = nil, body = nil, server = :api) ⇒ Object
:nodoc:
222 223 224 225 226 227 |
# File 'lib/dropbox_sdk_v2.rb', line 222 def do_put(path, params=nil, headers=nil, body=nil, server=:api) # :nodoc: params ||= {} uri = build_url_with_params(path, params, server) do_http_with_body(uri, Net::HTTP::Put.new(uri.request_uri, headers), body) end |