Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 613af6d

Browse files
davidenko87arnoFleming
authored andcommitted
V2 api (#31)
* Add guard file * file rename and removed ks structs * rename to transfer spec * Rename file item to file, and remove duplicate tests * replaced ks structs with attr_accesors * Added descriptions per tests * Added board feature and made methods private * disabled remote items * Removed ks structs * added classes for handling boards * Added specs for remote board * Removed items, and renamed web_items to links * rename items to links * Cleanup of if case * add upload_file and get_board method * Handle future links uploads, remove not used parts and update put_io method with use of classes * Class attributes instea of hashes * take default arguments * Added request board method * raise errors with the file name and remove true return * Transform items from remote board to classes * Set keyword arguments for classes and make them accessible with attr_reader * Do one full test of all methods for boards * Bump version * skip transfer Tests for now * Type + spacing * single quotes * Skip transfer tests for now * add items to remote boards * Added board builder spec * add helper methods for transfers * Adding transfer functionality * wip * edited upload_file to also handle transfer files * Send empty hash instead of string for get requests * rubocop * complete_file accepts boards and transfers and transfers work now * Rescue when no block is given * change method name * Remove unsupported method * changed variable into let * Check for items on future board * Tests for future transfers * refactor of the transfer builder tests * Added tests for wetransfer_client class * bumped wetransfer_style style * Refactor nested meta-hash away. Shortened some tests while in the process * Consitency * Implement guard (#34) * Added guard and rubocop to project * added guard description to readme * remove pry calls * fixed conflicts * Extracted boards and transfers from the client * return remote board or add files to board * Version to module * change to module class wetransfer * Removed transfer/board depended methods * removed all the object related methods into the object classes * Removed private methods from client and placed them into the right classes, still some refactoring could be done. * these gems needs to be added * Restructuring the code * removed gualrdfile from gitignore * Moved transfers and boards into WT_client folder en renaming * Integration tests for boards (#35) * let’s pass down the whole object instead of the id * Before doing the request, make sure we have a auth token. * added feature tests * Pass down the board object * remove module from spec describe * moved constant more upward * added part size constant * Change to fixnum for old ruby support (2.1) * change Test for Integer to support older rubies(2.1) * Remove specific target ruby version form rubocop rules * make size output integer * Test for kind integer * no need for class * Add rubocop to guard * run guard inside group to halt if test fail * wip Add upload and create method for boards (#38) * Create a transfer and upload files with one method * add a duplicate file checker * Removed code smell and naming things/items * Spec our generic status code check * Use non-deprecated Rubies * Resolve multiple minor issues * Mark parts of our boards API experimental
1 parent e752d78 commit 613af6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1801
-528
lines changed

.rspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
--format progress
21
--order rand
3-
--color
2+
--color

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
inherit_gem:
2-
wetransfer_style: ruby/default.yml
2+
wetransfer_style: ruby/default.yml

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
sudo: false
22
language: ruby
33
rvm:
4-
- 2.1.0
5-
- 2.5.1
4+
- 2.3
5+
- 2.4
6+
- 2.5
67
- jruby-9.0
78
before_install: gem install bundler -v 1.16.1
89
cache: bundler

Guardfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
group :red_green_refactor, halt_on_fail: true do
2+
guard :rspec, cmd: 'bundle exec rspec' do
3+
watch(%r{^spec/.+_spec\.rb$})
4+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
5+
end
6+
7+
guard :rubocop, cmd: 'bundle exec rubocop' do
8+
watch(%r{^lib/(.+)\.rb$})
9+
watch(%r{^spec/(.+)\.rb$})
10+
end
11+
end

README.md

Lines changed: 81 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# WeTransfer Ruby SDK
22

3-
An open source Ruby SDK for the WeTransfer Public API
3+
The Ruby SDK that makes interacting with WeTransfer's Public API a breeze
4+
5+
This gem can be used to create transfers (as seen on WeTransfer.com) and boards (as seen in our [iOS app](https://itunes.apple.com/app/apple-store/id765359021?pt=10422800&ct=wetransfer-developer-portal&mt=8) and [Android app](https://play.google.com/store/apps/details?id=com.wetransfer.app.live&referrer=utm_source%3Dwetransfer%26utm_medium%3Ddeveloper-portal) ) alike.
46

57
For your API key and additional info please visit our [developer portal](https://developers.wetransfer.com).
68

@@ -9,12 +11,13 @@ For your API key and additional info please visit our [developer portal](https:/
911
## Table of Contents
1012

1113
1. [Installation](#installation)
12-
2. [Usage](#usage)
13-
3. [Super simple transfers](#super-simple-transfers)
14-
4. [Development](#development)
15-
5. [Contributing](#contributing)
16-
6. [License](#license)
17-
7. [Code of Conduct](#code-of-conduct)
14+
1. [Getting started](#getting-started)
15+
1. [Transfers](#transfers)
16+
1. [Boards](#boards)
17+
1. [Development](#development)
18+
1. [Contributing](#contributing)
19+
1. [License](#license)
20+
1. [Code of Conduct](#code-of-conduct)
1821

1922
## Installation
2023

@@ -26,82 +29,122 @@ gem 'wetransfer'
2629

2730
And then execute:
2831

29-
$ bundle
32+
bundle install
3033

3134
Or install it yourself as:
3235

33-
$ gem install wetransfer
34-
35-
## Usage
36+
gem install wetransfer
3637

37-
### Minimalist transfers
38+
## Getting started
3839

3940
You'll need to retrieve an API key from [our developer portal](https://developers.wetransfer.com).
4041

41-
Be sure to not commit this key to Github! If you do though, no worries, you can always revoke & create a new key from within the portal.
42+
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.
4243

43-
For configuring and storing secrets - like this API key - there are a variety of solutions. The smoothest here is creating a .env file:
44+
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](https://github.com/bkeepers/dotenv).
4445

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

47-
$ touch .env
48+
touch .env
49+
50+
You don't want the contents of this file to leave your system. Ever.
51+
52+
If the `.env` file is new, make sure to add it to your `.gitignore`, using the following command:
53+
54+
echo .env >> .gitignore
4855

49-
Check your `.gitignore` file and make sure it has `.env` listed!
56+
Open the file in your text editor and add this line:
5057

51-
Now, open the file in your text editor and add this line:
58+
WT_API_KEY=<your api key>
5259

53-
`WT_API_KEY=<your api key>` (without the <> brackets!)
60+
Make sure to replace `<your api key>` by your actual api key. Don't include the pointy brackets!
5461

55-
Great! Now you can go to your project file and create the client:
62+
Great! Now you can go to your project file and use the client.
63+
64+
## Transfers
65+
66+
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.
5667

5768
```ruby
5869
# In your project file:
5970
require 'we_transfer_client'
6071

61-
@client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'))
72+
client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
6273
```
6374

64-
Now that you've got the client set up you can use `create_transfer` to, well, create a transfer!
75+
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!
6576

6677
```ruby
67-
transfer = @client.create_transfer(name: "My wonderful transfer", description: "I'm so excited to share this") do |upload|
78+
transfer = client.create_transfer_and_upload_files(message: 'All the Things') do |upload|
6879
upload.add_file_at(path: '/path/to/local/file.jpg')
6980
upload.add_file_at(path: '/path/to/another/local/file.jpg')
70-
upload.add_file(name: 'README.txt', io: StringIO.new("This is the contents of the file"))
71-
upload.add_web_url(url: "https://www.the.url.you.want.to.share.com", title: "title of the url"))
81+
upload.add_file(name: 'README.txt', io: StringIO.new("You should read All the Things!"))
7282
end
7383

74-
transfer.shortened_url => "https://we.tl/SSBsb3ZlIHJ1Ynk="
84+
# To get a link to your transfer, call `url` on your transfer object:
85+
transfer.url => "https://we.tl/t-123234="
7586
```
7687

77-
The upload will be performed at the end of the block.
88+
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.
89+
90+
What are you waiting for? Open that link in your browser! Chop chop.
91+
92+
## Boards
93+
94+
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.
95+
96+
Boards need a WeTransfer Client to be present, just like transfers.
97+
98+
```ruby
99+
# In your project file:
100+
require 'we_transfer_client'
101+
102+
client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
103+
```
104+
105+
After you create your client, you can
106+
107+
### Create a board and upload items
108+
109+
110+
```ruby
111+
board = client.create_board(name: 'Meow', description: 'On Cats') do |items|
112+
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')
113+
items.add_web_url(url: 'http://wepresent.wetransfer.com', title: 'Time well spent')
114+
end
115+
116+
puts board.url # => "https://we.tl/b-923478"
117+
```
118+
119+
You've just created a board. It is visible on the internet, to share it with anyone.
78120

79121
## Development
122+
80123
You'll need to retrieve an API key from [our developer portal](https://developers.wetransfer.com), and as described above, store it in a local `.env` file. As always, do not commit this file to github! :)
81124

82125
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.
83126

84-
```
85-
$ git clone <your fork>
86-
$ cd wetransfer_ruby_sdk
87-
$ bundle install
88-
```
127+
git clone <your fork> ./wetransfer_ruby_sdk
128+
cd wetransfer_ruby_sdk
129+
bundle install
89130

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

92133
To execute to ruby specs, run:
93134

94-
```
95-
$ bundle exec rspec
96-
```
135+
bundle exec rspec
97136

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

100-
$ bundle exec rubocop
139+
bundle exec rubocop
140+
141+
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.
142+
143+
bundle exec rubocop -a
101144

102-
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.
145+
For more convenience you also can run Guard, this checks all the tests and runs rubocop every time you save your files.
103146

104-
$ bundle exec rubocop -a
147+
bundle exec guard
105148

106149
Hooray!
107150

@@ -115,4 +158,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
115158

116159
## Code of Conduct
117160

118-
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](https://github.com/WeTransfer/wetransfer_ruby_sdk/blob/master/.github/CODE_OF_CONDUCT.md).
161+
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](https://github.com/WeTransfer/wetransfer_ruby_sdk/blob/master/.github/CODE_OF_CONDUCT.md).

V2_README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
The process
2+
3+
In the v2 version of the Ruby SDK we have added a new feature, mutable transfers called boards.
4+
5+
Boards excists next to the transfers and will be mutable, so you can add new files or web_links to your board.
6+
7+
8+
To use the ruby sdk you have to Initailize a new client with your API-Key:
9+
10+
```
11+
client = WeTransfer::Client.new(api_key: 'your-special-api-key')
12+
```
13+
14+
### Initailize a Board
15+
16+
Once you created that new client you can call methods to create a new board, empty or as a block:
17+
18+
```
19+
board = client.create_board(name: 'File Collection', description: 'A collection of files')
20+
```
21+
or:
22+
```
23+
board = client.create_board(name: 'Dog Collection', description: 'A collection of dogs') do |item|
24+
item.add_file(name: 'dalmatian.jpg', io: File.open('path/to/dalmatian.jpg', 'r'))
25+
item.add_file(name: 'beagle.jpg', io: File.open('path/to/beagle.jpg', 'r'))
26+
item.add_file(name: 'great_dane.jpg', io: File.open('path/to/great_dane.jpg', 'r'))
27+
item.add_web_url(url: 'http://www.wetransfer.com', title: 'WeTransfer Website')
28+
end
29+
```
30+
31+
### Initialize a Transfer
32+
33+
For initializing a transfer the process is like this:
34+
35+
```ruby
36+
transfer = @client.create_transfer(name: "Dog transfer", description: "Have a look at my dogs") do |upload|
37+
upload.add_file(name: 'chihuahua.jpg', io: File.open('path/to/chihuahua.jpg', 'r'))
38+
upload.add_file(name: 'chow_chow.jpg', io: File.open('path/to/chow_chow.jpg', 'r'))
39+
end
40+
41+
transfer.shortened_url => "https://we.tl/SSBsb3ZlIHJ1Ynk="
42+
```
43+
44+
Note: For initializing a transfer you have to pass all the files directly so the backend knows what you are uploading.
45+
46+
47+
48+
### uploading the files
49+
50+
For both the transfer and board, the files are not in you transfer or collection, yet.
51+
52+
The files need to be uploaded and finalized
53+

examples/create_collection.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require_relative 'we_transfer_client'
2+
require 'dotenv'
3+
Dotenv.load
4+
5+
client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
6+
transfer = client.create_transfer(name: 'My amazing transfer', description: 'Hi there!') do |builder|
7+
builder.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
8+
builder.add_file(name: 'amazing.txt', io: StringIO.new('This is unbelievable'))
9+
builder.add_file(name: 'huge.bin', io: File.open('/path/to/local/file.jpg', 'rb'))
10+
builder.add_file_at(path: __FILE__)
11+
end
12+
13+
puts transfer.shortened_url

examples/create_transfer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'dotenv'
33
Dotenv.load
44

5-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY')) # , logger: Logger.new($stderr))
5+
client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
66
transfer = client.create_transfer(name: 'My amazing transfer', description: 'Hi there!') do |builder|
77
builder.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
88
builder.add_file(name: 'amazing.txt', io: StringIO.new('This is unbelievable'))

0 commit comments

Comments
 (0)