Class: DropboxSessionBase

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

Overview

:nodoc:

Direct Known Subclasses

DropboxOAuth2Session, DropboxSession

Instance Method Summary collapse

Instance Method Details

#do_get(url, headers = nil) ⇒ Object

:nodoc:



93
94
95
96
97
98
# File 'lib/dropbox_sdk.rb', line 93

def do_get(url, headers=nil)  # :nodoc:
    assert_authorized
    uri = URI.parse(url)
    request = Net::HTTP::Get.new(uri.request_uri)
    do_http(uri, request)
end

#do_http_with_body(uri, request, body) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/dropbox_sdk.rb', line 100

def do_http_with_body(uri, request, body)
    if body != nil
        if body.is_a?(Hash)
            form_data = {}
            body.each {|k,v| form_data[k.to_s] = v if !v.nil?}
            request.set_form_data(form_data)
        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(url, headers = nil, body = nil) ⇒ Object

:nodoc:



124
125
126
127
128
# File 'lib/dropbox_sdk.rb', line 124

def do_post(url, headers=nil, body=nil)  # :nodoc:
    assert_authorized
    uri = URI.parse(url)
    do_http_with_body(uri, Net::HTTP::Post.new(uri.request_uri, headers), body)
end

#do_put(url, headers = nil, body = nil) ⇒ Object

:nodoc:



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

def do_put(url, headers=nil, body=nil)  # :nodoc:
    assert_authorized
    uri = URI.parse(url)
    do_http_with_body(uri, Net::HTTP::Put.new(uri.request_uri, headers), body)
end