Class: DropboxApiV2::Request
- Inherits:
-
Object
- Object
- DropboxApiV2::Request
- Defined in:
- lib/dropbox_api_v2/request.rb
Constant Summary collapse
- API_URL =
"https://api.dropboxapi.com/2"
- CONTENT_URL =
"https://content.dropboxapi.com/2"
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #base_url ⇒ Object
- #body ⇒ Object
- #content_type ⇒ Object
- #download? ⇒ Boolean
- #file_transfer? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(path, params = {}) ⇒ Request
constructor
A new instance of Request.
- #json_params ⇒ Object
- #perform ⇒ Object
- #response ⇒ Object
- #upload? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(path, params = {}) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 18 |
# File 'lib/dropbox_api_v2/request.rb', line 12 def initialize(path, params={}) @path = path @token = params.delete(:token) @body = params.delete(:body) @file_transfer = params.delete(:file_transfer) @params = params end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/dropbox_api_v2/request.rb', line 7 def path @path end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
7 8 9 |
# File 'lib/dropbox_api_v2/request.rb', line 7 def verb @verb end |
Instance Method Details
#base_url ⇒ Object
20 21 22 |
# File 'lib/dropbox_api_v2/request.rb', line 20 def base_url file_transfer? ? CONTENT_URL : API_URL end |
#body ⇒ Object
64 65 66 |
# File 'lib/dropbox_api_v2/request.rb', line 64 def body file_transfer? ? @body : json_params end |
#content_type ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/dropbox_api_v2/request.rb', line 44 def content_type if upload? "application/octet-stream" elsif download? "" else "application/json" end end |
#download? ⇒ Boolean
36 37 38 |
# File 'lib/dropbox_api_v2/request.rb', line 36 def download? !!(file_transfer? && !@body) end |
#file_transfer? ⇒ Boolean
40 41 42 |
# File 'lib/dropbox_api_v2/request.rb', line 40 def file_transfer? @file_transfer end |
#headers ⇒ Object
54 55 56 57 58 |
# File 'lib/dropbox_api_v2/request.rb', line 54 def headers headers = {"Authorization": "Bearer #{@token}", "Content-Type": content_type} headers["Dropbox-API-Arg"] = json_params if file_transfer? headers end |
#json_params ⇒ Object
28 29 30 |
# File 'lib/dropbox_api_v2/request.rb', line 28 def json_params @params.to_json end |
#perform ⇒ Object
68 69 70 71 72 |
# File 'lib/dropbox_api_v2/request.rb', line 68 def perform Curl.post(url, body) do |http| http.headers = headers end end |
#response ⇒ Object
60 61 62 |
# File 'lib/dropbox_api_v2/request.rb', line 60 def response DropboxApiV2::Response.new perform end |
#upload? ⇒ Boolean
32 33 34 |
# File 'lib/dropbox_api_v2/request.rb', line 32 def upload? !!(file_transfer? && @body) end |
#url ⇒ Object
24 25 26 |
# File 'lib/dropbox_api_v2/request.rb', line 24 def url base_url + path end |