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.



100
101
102
# File 'lib/dropbox_sdk.rb', line 100

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.



98
99
100
# File 'lib/dropbox_sdk.rb', line 98

def locale=(value)
  @locale = value
end

Instance Method Details

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

:nodoc:



129
130
131
132
133
134
# File 'lib/dropbox_sdk.rb', line 129

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



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/dropbox_sdk.rb', line 136

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:



158
159
160
161
162
163
164
# File 'lib/dropbox_sdk.rb', line 158

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:



166
167
168
169
170
171
# File 'lib/dropbox_sdk.rb', line 166

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