Class: DropboxSessionBase

Inherits:
Object
  • Object
show all
Defined in:
lib/dropbox_sdk.rb

Overview

:nodoc:

Direct Known Subclasses

DropboxOAuth2Session, DropboxSession

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale) ⇒ DropboxSessionBase

Returns a new instance of DropboxSessionBase.



155
156
157
# File 'lib/dropbox_sdk.rb', line 155

def initialize(locale)
  @locale = locale
end

Instance Attribute Details

#locale=(value) ⇒ Object (writeonly)

Sets the attribute locale

Parameters:

  • value

    the value to set the attribute locale to.



153
154
155
# File 'lib/dropbox_sdk.rb', line 153

def locale=(value)
  @locale = value
end

Instance Method Details

#do_get(path, params = nil, server = :api) ⇒ Object

:nodoc:



184
185
186
187
188
189
# File 'lib/dropbox_sdk.rb', line 184

def do_get(path, params=nil, server=:api)  # :nodoc:
  params ||= {}
  assert_authorized
  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



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/dropbox_sdk.rb', line 191

def do_http_with_body(uri, request, body)
  if body != nil
    if body.is_a?(Hash)
      request.set_form_data(Dropbox::clean_params(body))
    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:



213
214
215
216
217
218
219
# File 'lib/dropbox_sdk.rb', line 213

def do_post(path, params=nil, headers=nil, server=:api)  # :nodoc:
  params ||= {}
  assert_authorized
  uri = build_url(path, server)
  params['locale'] = @locale
  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:



221
222
223
224
225
226
# File 'lib/dropbox_sdk.rb', line 221

def do_put(path, params=nil, headers=nil, body=nil, server=:api)  # :nodoc:
  params ||= {}
  assert_authorized
  uri = build_url_with_params(path, params, server)
  do_http_with_body(uri, Net::HTTP::Put.new(uri.request_uri, headers), body)
end