Giter VIP home page Giter VIP logo

wetransfer_ruby_sdk's Introduction

This project is now archived as the Public WeTransfer API is no longer maintained.

WeTransfer Ruby SDK

The Ruby SDK that makes interacting with WeTransfer's Public API a breeze

This gem can be used to create transfers (as seen on WeTransfer.com) and boards (as seen in our iOS app and Android app ) alike.

For your API key and additional info please visit our developer portal.

Build Status Gem Version

Table of Contents

  1. Installation
  2. Getting started
  3. Transfers
  4. Boards
  5. Development
  6. Contributing
  7. License
  8. Code of Conduct

Installation

Add this line to your application's Gemfile:

gem 'wetransfer', version: '0.9.0.beta2'

And then execute:

bundle install

Or install it yourself as:

gem install wetransfer

Getting started

You'll need to retrieve an API key from our developer portal.

Be sure to not commit this key to Github! If you do though, you can always revoke it and create a new key from within the portal.

For configuring and storing secrets - like this API key - there are a variety of solutions. The smoothest here is creating a .env file, and use a gem like dotenv.

Now that you've got a wonderful WeTransfer API key, create a .env file in your project folder:

touch .env

You don't want the contents of this file to leave your system. Ever.

If the .env file is new, make sure to add it to your .gitignore, using the following command:

echo .env >> .gitignore

Open the file in your text editor and add this line:

WT_API_KEY=<your api key>

Make sure to replace <your api key> by your actual api key. Don't include the pointy brackets!

Great! Now you can go to your project file and use the client.

Transfers

A transfer is a collection of files that can be created once, and downloaded until it expires. Once a transfer is ready for sharing, it is closed for modifications.

# In your project file:
require 'we_transfer_client'

client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))

Now that you've got the client set up you can use create_transfer_and_upload_files to, well, create a transfer, and upload all files!

transfer = client.create_transfer_and_upload_files(message: 'All the Things') do |upload|
  upload.add_file_at(path: '/path/to/local/file.jpg')
  upload.add_file_at(path: '/path/to/another/local/file.jpg')
  upload.add_file(name: 'README.txt', io: StringIO.new("You should read All the Things!"))
end

# To get a link to your transfer, call `url` on your transfer object:
transfer.url => "https://we.tl/t-123234="

The upload will be performed at the end of the block. Depending on your file sizes and network connection speed, this might take some time.

What are you waiting for? Open that link in your browser! Chop chop.

Boards

A board is a collection of files and links, but it is open for modifications. Like your portfolio: While working, you can make adjustments to it. A board is a fantastic place for showcasing your work in progress.

Boards need a WeTransfer Client to be present, just like transfers.

# In your project file:
require 'we_transfer_client'

client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))

After you create your client, you can

Create a board and upload items

board = client.create_board(name: 'Meow', description: 'On Cats') do |items|
  items.add_file(name: 'big file.jpg', io: File.open('/path/to/huge_file.jpg', 'rb')items.add_file_at(path: '/path/to/another/file.txt')
  items.add_web_url(url: 'http://wepresent.wetransfer.com', title: 'Time well spent')
end

puts board.url # => "https://we.tl/b-923478"

You've just created a board. It is visible on the internet, to share it with anyone.

Development

You'll need to retrieve an API key from our developer portal, and as described above, store it in a local .env file. As always, do not commit this file to github! :)

After forking and cloning down the repo, run bundle install to install dependencies. Then, run bundle exec rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

git clone <your fork> ./wetransfer_ruby_sdk
cd wetransfer_ruby_sdk
bundle install

To install this gem onto your local machine, run bundle exec rake install.

To execute to ruby specs, run:

bundle exec rspec

Please note that we use rubocop to lint this gem -- be sure to run it prior to submitting a PR for maximum mergeability.

bundle exec rubocop

If any violations can be handled by rubocop, you can run auto-fix and it'll handle them for you, though do run the tests again and make sure it hasn't done something... unexpected.

bundle exec rubocop -a

For more convenience you also can run Guard, this checks all the tests and runs rubocop every time you save your files.

bundle exec guard

Hooray!

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wetransfer/wetransfer_ruby_sdk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct. More extensive contribution guidelines can be found here.

License

The gem is available as open source under the terms of the MIT License - the in-repo version of the license is here.

Code of Conduct

Everyone interacting in the WeTransfer Ruby SDK project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

wetransfer_ruby_sdk's People

Contributors

arkaitzgarro avatar arnofleming avatar avdlee avatar ballomud avatar bermannoah avatar davidenko87 avatar julik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

wetransfer_ruby_sdk's Issues

`upload_complete` for a file

Relates to #52

Have the possibility to tell the sdk that a file is completely uploaded.

The method exists, yet it is hidden behind a private interface.

Example project: WeTransfer x Messaging

One thing I think is an underrated feature of this API (and indeed WeTransfer itself) is the ability to put content in the title and message fields of a transfer. This has a lot of possibilities:

  • slightly ephemeral link based messages (with lovely WeTransfer art in the background)
  • some kind of one-time-pad encrypted message solution?
  • narrative experiment combining attached files and text in the message field
  • ???

Feel free to tackle this issue however you'd like - if you've got an idea for an example project, make the thing and let us know if we can help :-) - but this is also a good space for discussion and bouncing ideas off each other.

Add an upload progress callback

When uploading files, it's nice to have a progress callback every time a chunk has been uploaded. This should be optional (not all users will want to have this cluttering up their logs) but for testing or if you're making a CLI it's a definite quality of life improvement.

Would also help bring us into parity with the JS SDK, for when this is implemented.

Add support for blank transfers to the SDK

Through the API we allow the user to create blank transfers by issuing a create transfer request without the items hash in the body. In the current state of the SDK we do not support this functionality. We should add it! :)

Allow for custom local_identifier on files

We only expose the "name" field for file creation, but there's also local_identifier. While the built in SecureRandom.uuid generator will do for most use, some users may want to use a local identifier relevant to their own file system. (This is perhaps not as urgent with the current functionality of the API, but may become so in the future.)

N.B.: local_identifiers are hard-limited to 36 characters or less.

Move file upload responsibility

At the moment we use the client object to add items to a board or transfer (here we'll use a board as an example):

@client = WeTransfer::Client.new(api_key: "foo")
board = @client.create_board( ... )
@client.add_items(board: board)  do |builder|
  builder.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
  builder.add_file_at(path: fixtures_dir + 'Japan-01.jpg')
  builder.add_web_url(url: 'http://www.google.com', title: 'google')
end

or file uploads but we should make the transfer or board responsible for file upload, not the client.

@client = WeTransfer::Client.new(api_key: "foo")
board = @client.create_board( ... )
board.add_items do |builder| 
  builder.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
  builder.add_file_at(path: fixtures_dir + 'Japan-01.jpg')
  builder.add_web_url(url: 'http://www.google.com', title: 'google')
end

Please note that there are tests that are skipped because we don't want the original behaviour -- you should change and then implement -- search for the string "this interface is still experimental" to see them.

`create_transfer` method accessible

Relates to #52

Have a method to create a transfer and have it return an identifier.

Using that identifier, other specific methods can call actions on that transfer,

Example project: WeTransfer x Physical Space

One of the things that I think could be really fun is to create a system for tying transfers to a specific location. An example project (or even a separate gem/app/???) that creates a transfer connected to a set of coordinates or a physical space would be awesome to have, and it'd be amazing to see what people build with it / on it / around it.

Right now we don't have a DELETE endpoint available, or a method for limiting the number of downloads - but even something that works with a system like the venerable geocoder could get things started.

Feel free to tackle this issue however you'd like - if you've got an idea for an example project, make the thing and let us know if we can help :-) - but this is also a good space for discussion and bouncing ideas off each other.

Example project: WeTransfer x Twitter (bots)

No matter what the media says, twitter bots are extremely good. Projects like soft landscapes, literally anything by Darius Kazemi, the lovely and interactive Rijks Bot and so on and so forth make Twitter a much more fun place to be. So we should definitely have a starter kit for a bot that (somehow) combines the WeTransfer API with Tweets.

We need something basic but extendable we can put in the /examples directory for people to build off of, though if you'd like to create your own implementation be our guest! :) I highly recommend using the lovely twitter gem for handling the interaction with the Twitter API.

Feel free to tackle this issue however you'd like - if you've got an idea for an example project, make the thing and let us know if we can help :-) - but this is also a good space for discussion and bouncing ideas off each other.

Upload flow

Give the end user more control over the uploading flow (adding files, completing uploads, finalizing transfers)

Add support for link items to SDK

Is your feature request related to a problem? Please describe.
We now support adding link items via the API. See the docs here. We should add this capability to the SDK!

Add simplest use case possible for Transfer

In order to make adoption as easy as possible, it would make sense to have the simplest use case available to tramsfer using the ruby sdk

The steps involved could be

  1. create upload client
    • add all files to the transfer
  2. tell the client to finish the transfer (in its own time)
  3. the API returns the url that eventually holds the completed transfet

Integrate Travis CI

When this is moved to open source we can add it to travis-ci.org for automated testing goodness.

Move file completion responsibility

Currently, the complete_file! method lives on a WeTransfer::Client instance.

The low level responsibility for signaling that the file is complete should not be on a high object that the client is, but it should be moved to the file (RemoteFile) itself.

Implement deleting of files and links of a board

Is your feature request related to a problem? Please describe.
In the near future, the API allows deleting files and links of a board. The Ruby SDK should be able to handle that as well

Describe the solution you'd like

Describe alternatives you've considered

Additional context

See related issue: WeTransfer/wt-api-docs#96

split `create_transfer_and_upload_files` in 4 disparate parts

Currently, the SDK allows me to either do everything at once, or not at all.

I want to be able to just

  • create_transfer that just creates a transfer
  • call upload_complete for a specific file
  • requesting a part_number for a specific chunk of a file
  • finalize a transfer

Implement unit tests for client and transfers

At the moment we have one majestic suite of integration tests. Help us out by implementing unit tests! One potentially interesting thing here is that the integration tests rely on actual API calls - but doing real-live-calls for every test suite run is less than ideal. If you love test mocks this is the issue for you! (Or maybe you've got some other solution you'd like to add?)

`part_number` isolated

Relates to #52

In order to upload a specific chunk of a file, it would be helpful if the SDK would allow me to do just that

RFC: Adding boards endpoint to SDK

SDK V2

Appraoch on the V2 of the SDK


We're going to add Board end-points to the API, also the 'old' transfer end-point is changing slightly. That's why I write this RFC to discuss implementation.


Boards

We've added the boards end-point, that means you now have two options to share items.

Board's work in a more collective way, so you first create a empty board:

new_board = WeTransferClient.create_board(name: 'title', description: 'description')

To which you later can add files to with add_files and add links with add_links:

WeTransferClient.add_files(board: new_board) do |b|
  b.add_file_at(path: '/path/to/another/local/file.jpg')
  b.add_file(name: 'README.txt', io: StringIO.new("This is the contents of the file"))
end
WeTransferClient.add_links(board: [Object]) do |b|
  b.add_link(url: "https://www.the.url.you.want.to.share.com", title: "title of the url"))
end

To complete the process the following methods are needed:

  • requesting upload urls per chunk: WeTransferClient.request_upload_url(board_id: [String],file_id: [String],part_number: [Integer])
  • uploading files: WeTransferClient.upload_file(upload_url: [String] ,file_io: [File])
  • completig files: `WeTransferClient.complete_file(board_id: [Integer] ,file_id: [Integer] )

And for the GET endpoint we use: WeTransferClient.get_board(board_id: [String])


Transfers

For the transfers the flow will be:

Creating a Transfer and add files directly

transfer = WeTransferClient.create_transfer(name: [String] ,description: [String]) do |b|
  b.add_file_at(path: '/path/to/another/local/file.jpg')
  b.add_file(name: 'README.txt', io: StringIO.new("This is the contents of the file"))
end

The folowing methods will be needed to complete the process:

  • Request upload_url per file: WeTransferClient.request_upload_url(transfer_id: [String],file_id: [String] ,part_number: [Integer])
  • Upload file: WeTransferClient.upload_file(upload_url: [String] ,file_io: [File])
  • Complete file: WeTransferClient.complete_file(transfer_id: [String] ,file_id: [String] )
  • Complete transfer WeTransferClient.complete_transfer(transfer_id: [String])

And for the GET request it will be: WeTransferClient.get_transfer(transfer: [String])


Sanitize filenames in Ruby SDK

Describe the bug
We select files on their name, but we should also sanitize the names to prevent odd errors from the Transfer / Board endpoints

WeTransfer backend systems sanitize emojis (and control characters and special fs characters) from a file name. The sdk should do that as well, to bring that behavior closer to the end user, and have less surprises.

Expected behavior
We should sanitize the filenames and remove all characters that are lager then 4 bytes to prevent unforeseen errors with the Transfer endpoint

Possible Solution
filename.each_char.select{|c| c.bytes.count < 4 }.join('')

Add support for async item adding to the SDK

This is made much easier by #14 -- but essentially it is possible to add items to a transfer after the initial create step - even if you've added items to it already. This is a unique feature of our mobile app and the API. From a usability standpoint this is only possible for now if you store the transfer id generated when the transfer is created somewhere, though in the future we'll add GET functionality to the API and make your life much easier.

Here though the thing we need is a method that takes a transfer id and goes through the upload flow to add items to it.

`finalize` a transfer

relates to #52

A transfer that has had all its files (chunks) uploaded and completed can be finalized.
This method should become a public one.

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.