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.



142
143
144
# File 'lib/dropbox_sdk.rb', line 142

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.



140
141
142
# File 'lib/dropbox_sdk.rb', line 140

def locale=(value)
  @locale = value
end

Instance Method Details

#do_get(path, params = nil, headers = nil, content_server = false) ⇒ Object

:nodoc:



171
172
173
174
175
176
# File 'lib/dropbox_sdk.rb', line 171

def do_get(path, params=nil, headers=nil, content_server=false)  # :nodoc:
    params ||= {}
    assert_authorized
    uri = build_url_with_params(path, params, content_server)
    do_http(uri, Net::HTTP::Get.new(uri.request_uri))
end

#do_http_with_body(uri, request, body) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/dropbox_sdk.rb', line 178

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, content_server = false) ⇒ Object

:nodoc:



200
201
202
203
204
205
206
# File 'lib/dropbox_sdk.rb', line 200

def do_post(path, params=nil, headers=nil, content_server=false)  # :nodoc:
    params ||= {}
    assert_authorized
    uri = build_url(path, content_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, content_server = false) ⇒ Object

:nodoc:



208
209
210
211
212
213
# File 'lib/dropbox_sdk.rb', line 208

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