Coder Social home page Coder Social logo

dropbox_api's People

Contributors

anshu1992 avatar braui avatar czhang-blurb avatar dwhenry avatar hmnhf avatar jesus avatar joaoacflores avatar kayakyakr avatar kilgore5 avatar lukasvotypka avatar mendab1e avatar nsmmrs avatar panckreous avatar rossmeissl avatar seuros avatar simi avatar spatten avatar tomekdrazek avatar tyler-boyd avatar vtm9 avatar wakarana1 avatar wouter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dropbox_api's Issues

Cursor offset doesn't update when using `upload_session_append_v2`

I've been experimenting with the upload session API, and I think I've found a bug not covered by the current test cases.

commit = DropboxApi::Metadata::CommitInfo.new({
  "path" => "/test.txt",
  "mode" => :add
})

# Upload the first three bytes
cursor = client.upload_session_start('abc')

# Cursor offset has been correctly set to 3 at this point
expect(cursor.offset).to eq(3)

# Upload the second three bytes
client.upload_session_append_v2(cursor, 'def')

# Cursor offset *should* be set to 6 at this point, but remains 3
# expect(cursor.offset).to eq(6)

# Attempt to commit the upload
client.upload_session_finish(cursor, commit)

This raises an error:

DropboxApi::Errors::UploadSessionOffsetError:
  lookup_failed/incorrect_offset/..., correct offset: 6

This happens because the offset of the cursor never changes from 3 to 6 after the call to upload_session_append_v2.

This hack will cause the test to pass:

cursor = client.upload_session_start('abc')
client.upload_session_append_v2(cursor, 'def')

# Manually update the offset
cursor.instance_variable_set(:@offset, 6)

client.upload_session_finish(cursor, commit)

There are test cases covering upload_session_append_v2 and upload_session_finish, but never the two together, which would otherwise reveal this problem.

I believe the correct behaviour is to have upload_session_append_v2 update the cursors offset after a successful request, and I'm working on a fix for this at the moment – let me know if you have any thoughts on this in the meantime.

file downloading

when downloading file, metadata of file object was generated but file content not generated ,
I searched methods on the file metadata object but i can't succed.

HTTP 400: Error in call to API function

I'm using this gem to get a link to a folder in my Dropbox, but when I perform the following operation, I get an error.

link = @client.get_temporary_link(item_path)

Here's the error.

/Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/endpoints/base.rb:36:in `process_response': HTTP 400: Error in call to API function "files/get_temporary_link": request body: path: 'None' expected to be a string, got null (DropboxApi::Errors::HttpError)
	from /Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/endpoints/base.rb:11:in `perform_request'
	from /Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/endpoints/files/get_temporary_link.rb:14:in `block in <class:GetTemporaryLink>'
	from /Users/Frank/.gems/gems/dropbox_api-0.1.10/lib/dropbox_api/cli

The same happened with other functions, such as create_shared_link_with_settings.
What am I missing?

Release v0.1.11

  • Get all tests passing
  • Update README and show a sample on how to use upload_by_chunks
  • Write tests for chunked uploader options.
  • Document new endpoints properly.
  • Write change log.
  • Release!

Ability to revoke a token

It looks like there's currently no ability to revoke a token once a user has completed the OAuth flow. I can look into adding it if that's something you'd accept in a PR.

How to generate a link to a dropbox folder?

I've been searching through the docs and before I dive into the gem source code itself any further I would like to know the following: is it possible to generate a link to a dropbox folder with your gem?

I am building a string from DropboxApi::Metadata::Folder#path_lower, which indeed returns the url path for the folder. However, the path is missing /home, which seems to be the root of all created dropbox folders. To actually generate a url to the folder, I have to do something that I do not love:

"https://dropbox.com/home#{DropboxAPI::Client.new('/some/path/to/folder/').get_metadata('/some/path/to/folder/').path_lower}"
# => https://dropbox.com/home/some/path/to/folder/

Bad offset exception when uploading binary file with session interface

I was testing uploading via sessions and found that I got an offset error when trying to upload binary files. I believe I tracked it down to upload_session_start.rb line 34, where

"offset" => content.size

I believe that this should be

"offset" => content.bytesize

size returns the character length, whereas bytesize returns the length of the string in bytes. These sizes may not be the same if the file is not pure text.

I was able to create a new cursor with the content.bytesize and pass it to upload_session_finish and the file transferred properly.

Thanks for your work on this API. It's been a big timesaver.

Invalid value for `match_type`: {".tag"=>"both_filename_and_content"}

I may be posting this issue prematurely but all of a sudden my client is getting this error when using the search function. Nothing has changed on our end. Perhaps Dropbox just now made a change to their way their search endpoint works?

EDIT: Apparently I have discovered the error returned when Dropbox returns an undocumented match_type. There's an open PR for fixing this.

#101

Reference implementation for chunked uploads?

First off, thanks for all the hard work. This gem has helped me out a ton!

I'll be adding the upload_session_* functionality soon and was wondering if you have any ideas about the best way to handle bigger files. Do you have any examples?

Do you think determining whether the file needs to be uploaded normally or chunked seems like functionality this gem could handle automatically in the future?

Using Stone to generated routes and data types

Thanks for creating a Ruby SDK. You'll notice that our other official SDKs use a library called Stone to generate routes and data types, which makes keeping up-to-date with all our API changes easier as we regularly update our specs repo. Unfortunately, we don't have a Ruby generator, but this is a light tap that we would be delighted if a 3rd party made one :)

Incorrect Content-Length when #upload passed string

I noticed that when the #upload method is given a string (like the result of IO.read), the uploaded file is not the correct size.

result1 = service.upload('/test1.png', IO.read('/tmp/test.png'))
result1.size
=> 6208

File.open('/tmp/test.png') do |file|
  result2 = service.upload('/test2.png', file)
end
result2.size
=> 6477

File.size('/tmp/test.png')
=> 6477

I compared the content of the two files and they are identical up until test1's premature end (it is missing the last 269 bytes).

I traced the issue to here. I believe the first priority method to call should be #bytesize, which will get the proper size in bytes. I'd be happy to submit a PR if you agree.

ArgumentError: Content-Length not given and Transfer-Encoding is not `chunked'

Hello, I wasn't able to upload any file getting this exception.

ArgumentError: Content-Length not given and Transfer-Encoding is not `chunked'
from /home/retro/.rubies/ruby-2.2.6/lib/ruby/2.2.0/net/http/generic_request.rb:192:in `send_request_with_body_stream'

After a little lookup, I was able to fix this by changing build_request in ContentUpload.

When I passed one of 'Content-Length' => content.size or 'Transfer-Encoding' => 'chunked' as an additional header, everything worked as expected and file was uploaded without problems (verified by downloading and md5 hashing).

Does it make sense to include one of these headers by default or at least add new option for upload method?

I can submit PR once this will be decided.

Thanks for this awesome gem!

timeout issues

I'm having timeout issues when fetching a folder. I can use the dropbox api explorer and curl and all works fine, but as soon as I try in ruby it times out.

Any help would be greatly appreciated.

Catching 401

The lib currently throws a DropboxApi::Errors::HttpError with response code and response body as a string. There's no way to catch specific http error codes.

update to 2.x of `oauth` gem as dependency?

dropbox_api requires oauth1 gem 1.x

spec.add_dependency 'oauth2', '~> 1.1'

However, oauth gem now has a 2.0 release as of June 2022. https://rubygems.org/gems/oauth2/versions/2.0.0

Instalilng the last oauth2 1.x release produces this warning:

You have installed oauth2 version 1.4.11, which is EOL.
No further support is anticipated for the 1.4.x series.

OAuth2 version 2 is released.
There are BREAKING changes, but most will not encounter them, and upgrading should be easy!

We have made two other major migrations:
1. master branch renamed to main
2. Github has been replaced with Gitlab

Please see:
• https://gitlab.com/oauth-xx/oauth2#what-is-new-for-v20
• https://gitlab.com/oauth-xx/oauth2/-/blob/main/CHANGELOG.md
• https://groups.google.com/g/oauth-ruby/c/QA_dtrXWXaE

Please upgrade, report issues, and support the project! Thanks, |7eter l-|. l3oling

Could dropbox_api be updated to allow use of oath2 2.x, perhaps allowing both 1.x and 2.x?

Chunked downloads

For getting large files from a user's Dropbox, their API allows you to specify a range of bytes--is this possible in the current dropbox_api gem's DSL?

Get Shared Links only shows 200 files

Hi,

I have recently used Get Shared Links method but is only returning 200 files. In the app folder, I had 2000 files. How can I get all of them?

Kind Regards
Andrew

Token is malformed, Expecting "Bearer <oauth2-access-token>"

i try to make the client exactly as explained inside the docs like this:

access_token = OAuth2::AccessToken.from_hash(authenticator, token_hash)

the Dropbox::Token::Save is just a module that saves the token

    client = DropboxApi::Client.new(
      access_token: access_token,
      on_token_refreshed: lambda { |new_token_hash|
        Dropbox::Token::Save.perform(new_token_hash)
      }
    )

the problem is the client gives me this error:

DropboxApi::Errors::HttpError Exception: HTTP 400: Error in call to API function "files/list_folder": Invalid authorization value in HTTP header "Authorization": "Bearer access_token=\"#<OAuth2::AccessToken:0x00007f72ce27efc8>\", on_token_refreshed=\"#<Proc:0x00007f72cdf7d6d0@(byebug):3 (lambda)>\"". Expecting "Bearer <oauth2-access-token>".
and it doesnt refresh the token and doesnt save it.

and even if i dont send the on_token_refresh the error will be :
DropboxApi::Errors::HttpError Exception: HTTP 400: Error in call to API function "files/list_folder": The given OAuth 2 access token is malformed.

looks like the DropboxApi::Client module is not accepting those correctly.
it'd be amazing if someone could help me thanks

JSON::GeneratorError: only generation of JSON objects or arrays allowed

Hi there,

I get the error message "JSON::GeneratorError: only generation of JSON objects or arrays allowed" after trying to collect account data:

client = DropboxApi::Client.new(DROPBOX_TOKEN)
client.get_current_account

I already tried to switch to a different version of execjs gem without success.

Using ruby 2.1.7 and json_pure 2.1.0 for my Rails application.

Did you see this error behaviour in any context before?

Greetings, Alex

please use more reasonable faraday restriction, allow 1.0.1?

The gemspec currently says:

` spec.add_dependency "faraday", "<= 1.0"

spec.add_dependency "faraday", "<= 1.0"

That ends up meaning any faraday version less than or equal to 1.0.0, but no greater.

This means 1.0.0 is allowed, but 1.0.1 released March 29 and containing a few bugfixes is not allowed by dropbox_api. An app using dropbox_api can use faraday 1.0.0, but not 1.0.1.

I think this is probably not what you intended? Not sure what you intended? Perhaps < 2.0, meaning allow any 0.x and any 1.x? I would advocate that, I think?

Here is the commit where you changed gemspec to say <= 1.0, I'm afraid the commit message doesn't have much guidance. 7107370

"NoMethodError: undefined method `[]' for nil:NilClass" in media_info.rb:22

I'm having the hardest time tracking down a bug in using this library for save_url and save_url_check_job_status.

I can't recreate it, but while it's running in background jobs (with sidekiq), save_url_check_job_status will throw NoMethodError: undefined method '[]' for nil:NilClass tracing to media_info.rb:22:

tag = data['metadata']['.tag']

So sometimes when save_url_check_job_status is called, data['metadata'] is nil. Is this a problem with this library, or could it be that I'm calling it in a strange way?

Cassette regeneration

I'm trying to do a small change to the gem (adding the content_hash property).

For this I need to regenerate the VCR cassettes, but it seems like this requires a base Dropbox state with some files in it (eg: file.txt, file.docx, a "folder" folder, etc). I can't seem to find these test files in the repository. Is it available somewhere?

Please upgrade dependency faraday to ~> 0.17

I have used the dropbox_api 0.1.17 in my fastlane script.

Recently, my project upgraded fastlane version to latest that also upgraded faraday to ~> 0.17.
It's caused the compatible issues of faraday.
See the changes. fastlane/fastlane@cf2ac51

I restricted fastlane version on 2.133.0 that before the commit for now.

I'll appreciate If the project could upgrade faraday's version.

How do you get the token_hash for refresh tokens?

I am making one request to authorize a user and would to save the token hash so that I can build an OAuth2::AccessToken at a later time and upload a file without user authorization. I can create the client but if on_token_refreshed is not called, how do I get the token_hash?

For example, I am calling the following once, but on_token_refreshed doesn't get called so I can't get the token hash. Do I need to construct the token_hash manually?

    access_token = authenticator.auth_code.get_token(params[:code], redirect_uri: redirect_uri)
    client = DropboxApi::Client.new(
    access_token: access_token,
    on_token_refreshed: lambda { |new_token_hash|
      # token_hash is a serializable Hash, something like this:
      # {
      #   "uid"=>"440",
      #   "token_type"=>"bearer",
      #   "scope"=>"account_info.read account_info.write...",
      #   "account_id"=>"dbid:AABOLtA1rT6rRK4vajKZ...",
      #   :access_token=>"sl.A5Ez_CBsqJILhDawHlmXSoZEhLZ4nuLFVRs6AJ...",
      #   :refresh_token=>"iMg4Me_oKYUAAAAAAAAAAapQixCgwfXOxuubCuK_...",
      #   :expires_at=>1632948328
      # }
      SomewhereSafe.save(new_token_hash)
    }
  )

Autorename option in file move endpoint

I'm looking forward to using this client but it seems not all the allowed parameters can be passed to the methods. In particular I'm looking forward to the autorename param in the files_move endpoint (https://www.dropbox.com/developers/documentation/http/documentation#files-move).

Maybe we could add a third parameter in this endpoint with an hash that would allow to pass all the non required parameters.

What do you think? Any other approach to allow these other params?

Chunked Uploads

I want to upload files in chunk using /upload_session/* endpoints.
It seems that this has not been implemented as per http://www.rubydoc.info/gems/dropbox_api/file/api_coverage.md ,

but there's a comment "Do not use this to upload a file larger than 150 MB. Instead, create an upload session with #upload_session_start()." in upload.rb which is creating the confusion, BTW I was not able to see the implementation of upload_session_start() so I assume it is not implemented till now.

Am I missing something?

Uploading large files

What is the best way to upload a large file? I see the documentation mentions something about uploading over 150MB files, but am unsure how to actually implement it. Since it takes a string, is it possible to actually accept a file stream or something so as not to load a massive file into memory and convert it to a string?

Rubydoc does not show the endpoint documentation

Hi there, I'm planning to use this gem because it seems pretty complete, or at the least, it has all the methods I need to make my own syncing script for a Discord bot I'm making.

I noticed over on the rubydoc for this gem that the documentation for the endpoint methods does not appear for all endpoints. Some, such as CreateFolder, will have their methods appear -- but others like Upload do not!

I searched a little into this and I found eb13f33, a commit where all the # @method stuff was replaced with a YARD plugin. So I looked at the documentation that rubydoc.info had for v0.1.4 of this gem, and lo-and-behold, all the endpoint documentation was there without error.

I don't know what to make of this, I think it's worth looking into however.

Generating a thumbnail output

I assume I am missing something.. I upload a file and get a thumbnail (for now, assume its a small jpeg being uploaded):

dropbox = DropboxApi::Client.new(ENV['DROPBOX_ACCESS_TOKEN'])
uploaded_file = dropbox.upload(uploaded_path, uploaded_io.read, autorename: true)
thumb = dropbox.get_thumbnail(uploaded_file.path_lower)

inspecting thumb gives me the same object as uploaded_file.. how do I get to the thumbnail?

Complete support for upload endpoint

The options for this endpoint are being ignored, the API supports 4 options:

  • mode
  • autorename
  • client_modified
  • mute

But none of them are implemented by this library.

NoMethodError raised when dropbox responds with 429

Description

Looks like Dropbox may respond with a 429 status code and no body or content type is not JSON during file chunks upload.
In this case gem failed with NoMethodError

Gem version: 0.1.21

Backtrace

NoMethodError: undefined method `[]' for nil:NilClass
  from dropbox_api/endpoints/base.rb:47:in `process_response'
  from dropbox_api/endpoints/content_upload.rb:23:in `perform_request'
  from dropbox_api/endpoints/files/upload_session_start.rb:31:in `block in <class:UploadSessionStart>'
  from dropbox_api/client.rb:36:in `block in add_endpoint'
  from dropbox_api/chunked_uploader.rb:19:in `start'
  from dropbox_api/endpoints/virtual/upload_by_chunks.rb:45:in `upload_by_chunks'

dropbox_api/endpoints/base.rb:47

45      when 429
46        error = DropboxApi::Errors::TooManyRequestsError.build(
47          raw_response.env[:api_result]['error_summary'],
48          raw_response.env[:api_result]['error']['reason']

Access data value

Hi there, thanks for the awesome job. I have an issue which I am not sure how to do.

client = DropboxApi::Client.new()
object =  client.get_temporary_link "/app/path"
#results 
#<DropboxApi::Results::GetTemporaryLinkResult:0xsada12312 @data={"metadata"=> . 
{"link"=>"http://dl.dropboxusercontent.com...}>

The question is I am not sure how to get the link from the results... I tried something like object.data['metadata']['link'] but which returns *** NoMethodError Exception: undefined method data error. What am I doing wrong?

Support for the Dropbox-API-Select-User header (for Dropbox Business)

I've written an app that uses the dropbox_api gem to list and upload files. It works great, but now I need to make it work with the Dropbox Business API.

The Dropbox Business API has a set if its own endpoints, plus a change in request behaviour for the normal Dropbox API endpoint. At this stage, I don't need the additional endpoints, just the altered request behaviour.

The change needed is to add a header – Dropbox-API-Select-User (or Dropbox-API-Select-Admin) –  which contains a team member ID (this is separate from a user ID). Using this header, I can request any of the standard API endpoints, performing each action on behalf of a user in a team.

There's a couple of approaches I can take to implementing this, and ideally I'd like to submit the work and get it accepted back to this gem, so I'm opening this issue for discussion now before I start work on it. I'd love to hear your thoughts.

Proposed solution: Expose ConnectionBuilder's connection middleware

One option would be to add a method to the client which would allow you to have access to the ConnectionBuilder's Faraday connection:

client = DropboxApi::Client.new(...)

client.middleware do |connection|
  connection.headers['Dropbox-API-Select-User'] = '...'
end

client.list_folder('/gifs')

This would be my preferred solution, as exposing the middleware would allow a user to arbitrarily add, for example, custom logging or error handling.

def build(url)
  Faraday.new(url) do |c|
    @middleware_callback.call(c) # <---

    c.authorization :Bearer, @oauth_bearer

    yield c

    c.adapter Faraday.default_adapter
  end
end

Given that some endpoints manipulate the headers, this may cause some headaches. There's also the classic problem of Faraday's middleware ordering – the ability to customise the connection will depend on where the callback gets called inside the block.

Alternative option: Pass parameter to ConnectionBuilder

Another option to solve this problem would be to pass an optional parameter to the connection builder, through the client:

client = DropboxApi::Client.new(token, select_user: '...')
client.list_folder('/gifs')

This would work by passing the select_user to the ConnectionBuilder, which would insert it something like this:

def build(url)
  Faraday.new(url) do |c|
    c.authorization :Bearer, @oauth_bearer

    if @team_member_id
      c.headers['Dropbox-API-Select-User'] = @select_user
    end

    yield c

    c.adapter Faraday.default_adapter
  end
end

Alternative option: support a parameter on each endpoint

This would basically involving patching a bunch of endpoints to allow a select_user option.

client = DropboxApi::Client.new(token)
client.list_folder('/gifs', select_user: '...')

List_folder result entries breaks for shared folder

Hello,

I found an issue when trying to iterate through a publicly shared folder. The Dropbox API documentation instructs to use the shared_link option of the list_folder request. The dropbox_api gem (unknowingly, I guess) supports this option:

result = client.list_folder('', shared_link: 'https://www.dropbox.com/sh/cut/cut')

but I'm unable to iterate through the entries:

result.entries
ArgumentError: Invalid value for `path_lower`: nil.
	from /cut/dropbox_api-0.1.12/lib/dropbox_api/metadata/base.rb:62:in `rescue in []=`

I don't know it supporting shared folders is on the roadmap. I just wanted to let you guys know that it does not work.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.