wetransfer 0.9.0.beta1 → 0.9.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b84e32a738e08a8e53b7959fe659a1d37c3bfba4cbde3fcf7760100aa46c2a10
4
- data.tar.gz: 147c343eec0216e9208bd56554e0463441dbbe557b3a2623d1d737bcfaa48a54
3
+ metadata.gz: 2464046d0465579af0bad563dcb67a80aa4cabadc0cea93ad332a525011498ef
4
+ data.tar.gz: d40ef8d567e6d8da3c409947f83e486b6dbc34e2af081c1d75d3535a61bd2dbd
5
5
  SHA512:
6
- metadata.gz: 44aa5cbf35ee63f81e33ca574b8b98bb02e21cd161796b01bb5003d92efaed4720711dd21e0d5438ae74cf82a971fccbe4770e950651a75ce8da5aef5a582ede
7
- data.tar.gz: 1aee6811bd67ba882f106339b94860ec83d54e3ab9c2ef9a7c8b417f8b72a8c0e971d903a981895ed99d10d2c8d4a2421f9e1928998cb0b662ebb00d9dea79df
6
+ metadata.gz: 5d59a3df8c90de97d1145ac16e9f6ab233960619e52d39049c3b94ea07e9abefb82f57101fa1820e13ce672d7e4845cc92439e3dc3ffb200d4c9a700310473c8
7
+ data.tar.gz: dc11d22428b4daf9373de492788d99d9a1cb73417f4e55fa9191facd443a931a0fa96d9d13bca92dada611e14f5aeb1337b2a98b6f2af8de08a3643f2c0b2708
data/README.md CHANGED
@@ -24,7 +24,7 @@ For your API key and additional info please visit our [developer portal](https:/
24
24
  Add this line to your application's Gemfile:
25
25
 
26
26
  ```ruby
27
- gem 'wetransfer', version: '0.9.0.beta1'
27
+ gem 'wetransfer', version: '0.9.0.beta2'
28
28
  ```
29
29
 
30
30
  And then execute:
@@ -1,3 +1,3 @@
1
1
  module WeTransfer
2
- VERSION = '0.9.0.beta1'
2
+ VERSION = '0.9.0.beta2'
3
3
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  'public gem pushes.'
24
24
  end
25
25
 
26
- spec.files = `git ls-files -z`.split("\x0")
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f =~ /^spec/ }
27
27
  spec.bindir = 'exe'
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wetransfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.beta1
4
+ version: 0.9.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman
@@ -196,28 +196,6 @@ files:
196
196
  - lib/we_transfer_client/transfer_builder.rb
197
197
  - lib/we_transfer_client/transfers.rb
198
198
  - lib/we_transfer_client/version.rb
199
- - spec/board_integration_spec.rb
200
- - spec/features/add_items_to_board_spec.rb
201
- - spec/features/create_board_spec.rb
202
- - spec/features/get_board_spec.rb
203
- - spec/features/transfer_spec.rb
204
- - spec/fixtures/Japan-01.jpg
205
- - spec/fixtures/Japan-02.jpg
206
- - spec/spec_helper.rb
207
- - spec/transfer_integration_spec.rb
208
- - spec/we_transfer_client/board_builder_spec.rb
209
- - spec/we_transfer_client/boards_spec.rb
210
- - spec/we_transfer_client/future_board_spec.rb
211
- - spec/we_transfer_client/future_file_spec.rb
212
- - spec/we_transfer_client/future_link_spec.rb
213
- - spec/we_transfer_client/future_transfer_spec.rb
214
- - spec/we_transfer_client/remote_board_spec.rb
215
- - spec/we_transfer_client/remote_file_spec.rb
216
- - spec/we_transfer_client/remote_link_spec.rb
217
- - spec/we_transfer_client/remote_transfer_spec.rb
218
- - spec/we_transfer_client/transfer_builder_spec.rb
219
- - spec/we_transfer_client/transfers_spec.rb
220
- - spec/we_transfer_client_spec.rb
221
199
  - wetransfer.gemspec
222
200
  homepage: https://developers.wetransfer.com
223
201
  licenses:
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WeTransfer::Client do
4
- let(:small_file_name) { 'Japan-02.jpg' }
5
- let(:big_file) { File.open(fixtures_dir + 'Japan-01.jpg', 'rb') }
6
- let(:client) do
7
- WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
8
- end
9
-
10
- it 'creates a board with files and web items as a block' do
11
- # Create a board with three items, one small file, one multipart file, and one web url
12
- board = client.create_board_and_upload_items(name: 'Test Board', description: 'Test description') do |b|
13
- b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
14
- b.add_file(name: 'big file', io: big_file)
15
- b.add_file_at(path: fixtures_dir + small_file_name)
16
- b.add_web_url(url: 'http://www.wetransfer.com', title: 'WeTransfer Website')
17
- end
18
-
19
- # the board url is set
20
- expect(board.url =~ %r|https://we.tl/b-|).to be_truthy
21
-
22
- expect(board.items.map(&:class)).to eq([RemoteFile, RemoteFile, RemoteFile, RemoteLink])
23
- expect(board.items[1].multipart.part_numbers).to be > 1
24
- expect(board.items.count).to be(4)
25
-
26
- # TODO: make these experimental steps public
27
- # # Add two new items to the board, one small file and one web url
28
- # client.add_items(board: board) do |b|
29
- # b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
30
- # b.add_web_url(url: 'http://www.google.com', title: 'google')
31
- # end
32
- # expect(board.items.count).to be(6)
33
-
34
- # # Check if the board includes 3 File items and 2 Link items
35
- # expect(board.items.select { |i| i.type == 'file' }.count).to be(4)
36
- # expect(board.items.select { |i| i.type == 'link' }.count).to be(2)
37
-
38
- # # Upload the Files to the Board
39
- # file_items = board.items.select { |i| i.type == 'file' }
40
- # client.upload_file(object: board, file: file_items[0], io: File.open(__FILE__, 'rb'))
41
- # client.upload_file(object: board, file: file_items[1], io: big_file)
42
- # client.upload_file(object: board, file: file_items[2], io: File.open(fixtures_dir + small_file_name, 'rb'))
43
- # client.upload_file(object: board, file: file_items[3], io: File.open(__FILE__, 'rb'))
44
-
45
- # # Complete all the files of the board
46
- # file_items.each do |item|
47
- # client.complete_file!(object: board, file: item)
48
- # end
49
-
50
- # Do a get request to see if url is available
51
- response = Faraday.get(board.url)
52
-
53
- # that should redirect us...
54
- expect(response.status).to eq(302)
55
- # ... to a board in the wetransfer domain
56
- expect(response['location']).to start_with('https://boards.wetransfer')
57
-
58
- # Check for the Boards status to be downloadable
59
- resulting_board = loop do
60
- res = client.get_board(board: board)
61
- break res if res.state != 'processing'
62
- sleep 1
63
- end
64
-
65
- expect(resulting_board.state).to eq('downloadable')
66
- expect(resulting_board.items.count).to be(4)
67
- end
68
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WeTransfer::Client::Boards do
4
- let(:client) { WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY')) }
5
- let(:board) do
6
- client.create_board(name: 'Test Board', description: 'Test Descritpion')
7
- end
8
-
9
- describe '#add_items' do
10
- before do
11
- skip "this interface is still experimental"
12
- end
13
-
14
- it 'adds items to a board' do
15
- client.add_items(board: board) do |b|
16
- b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
17
- b.add_file_at(path: fixtures_dir + 'Japan-02.jpg')
18
- b.add_web_url(url: 'http://www.google.com', title: 'google')
19
- end
20
- end
21
-
22
- it 'fails when no block is given' do
23
- expect {
24
- client.add_items(board: board)
25
- }.to raise_error ArgumentError, /No items/
26
- end
27
-
28
- it 'fails when no board is passed as keyword argument' do
29
- expect {
30
- client.add_items do |b|
31
- b.add_file_at(path: fixtures_dir + 'Japan-01.jpg')
32
- end
33
- }.to raise_error ArgumentError, /board/
34
- end
35
-
36
- it 'fails when file is not found' do
37
- expect {
38
- client.add_items(board: board) do |b|
39
- b.add_file(name: 'file_not_found.rb', io: File.open('/path/to/non-existent-file.rb', 'r'))
40
- end
41
- }.to raise_error Errno::ENOENT, /No such file/
42
- end
43
-
44
- it 'fails when board is not a existing remote board' do
45
- new_board = RemoteBoard.new(id: 123456, state: 'proccessing', url: 'https://www.we.tl/123456', name: 'fake board')
46
- expect {
47
- client.add_items(board: new_board) do |b|
48
- b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
49
- b.add_file_at(path: fixtures_dir + 'Japan-01.jpg')
50
- b.add_web_url(url: 'http://www.google.com', title: 'google')
51
- end
52
- }.to raise_error WeTransfer::Client::Error, /404 code/
53
- end
54
- end
55
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WeTransfer::Client::Boards do
4
- let(:big_file) { File.open(fixtures_dir + 'Japan-01.jpg', 'r') }
5
- let(:client) { WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY')) }
6
-
7
- describe '#create_board' do
8
- before {
9
- skip "this interface is still experimental"
10
- }
11
-
12
- it 'creates a remote board' do
13
- client.create_board(name: 'Test Board', description: 'Test Descritpion')
14
- end
15
-
16
- it 'creates a board with items' do
17
- client.create_board(name: 'Test Board', description: 'Test descrition') do |b|
18
- b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
19
- b.add_file(name: 'big file', io: big_file)
20
- b.add_web_url(url: 'http://www.wetransfer.com', title: 'WeTransfer Website')
21
- end
22
- end
23
-
24
- it 'fails when name is missing' do
25
- expect {
26
- client.create_board(name: '', description: 'Test Descritpion')
27
- }.to raise_error WeTransfer::Client::Error, /400 code/
28
- end
29
-
30
- it 'fails when file path is wrong' do
31
- expect {
32
- client.create_board(name: 'Test Board', description: 'Test descrition') do |b|
33
- b.add_file(name: 'file_not_found.rb', io: File.open('path/to/non-existing-file.rb', 'r'))
34
- end
35
- }.to raise_error Errno::ENOENT, /No such file/
36
- end
37
-
38
- it 'fails when file name is missing' do
39
- expect {
40
- client.create_board(name: 'Test Board', description: 'Test descrition') do |b|
41
- b.add_file(name: '', io: File.open(__FILE__, 'rb'))
42
- end
43
- }.to raise_error WeTransfer::Client::Error, /400 code/
44
- end
45
- end
46
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WeTransfer::Client::Boards do
4
- let(:client) do
5
- WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
6
- end
7
-
8
- let(:board) do
9
- client.create_board(name: 'Test Board', description: 'Test Descritpion')
10
- end
11
-
12
- describe '#get_board' do
13
- before do
14
- skip "this interface is still experimental"
15
- end
16
-
17
- it 'it gets a exisiting board' do
18
- client.get_board(board: board)
19
- end
20
-
21
- it 'fails when no board is given' do
22
- expect {
23
- client.get_board
24
- }.to raise_error ArgumentError, /board/
25
- end
26
-
27
- it 'fails when board doenst exists' do
28
- new_board = RemoteBoard.new(id: 123456, state: 'proccessing', url: 'https://www.we.tl/123456', name: 'fake board')
29
- expect {
30
- client.get_board(board: new_board)
31
- }.to raise_error WeTransfer::Client::Error, /404 code/
32
- end
33
- end
34
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WeTransfer::Client::Transfers do
4
- let(:client) do
5
- WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
6
- end
7
-
8
- let(:file_location) { fixtures_dir + 'Japan-02.jpg' }
9
-
10
- let(:created_transfer) do
11
- client.create_transfer(message: 'Test transfer') do |builder|
12
- builder.add_file(name: File.basename(file_location), io: File.open(file_location, 'rb'))
13
- end
14
- end
15
-
16
- describe "#create_transfer" do
17
- before do
18
- skip "this interface is still experimental"
19
- end
20
-
21
- it "is needed to add a file" do
22
- expect { client.create_transfer(message: "Transfer name") }
23
- .to raise_error(ArgumentError, /^No files were added/)
24
- end
25
-
26
- it "accepts a block to add files by their location" do
27
- client.create_transfer(message: 'Test transfer') do |builder|
28
- builder.add_file_at(path: file_location)
29
- end
30
- end
31
-
32
- it "accepts a block to add files by their io" do
33
- client.create_transfer(message: 'Test transfer') do |builder|
34
- builder.add_file(name: File.basename(file_location), io: File.open(file_location, 'rb'))
35
- end
36
- end
37
- end
38
-
39
- describe "#complete_transfer"
40
- describe "#get_transfer"
41
- end
Binary file
Binary file
@@ -1,39 +0,0 @@
1
- require 'simplecov'
2
- require 'securerandom'
3
-
4
- SimpleCov.start do
5
- add_filter '/spec/'
6
- end
7
-
8
- require 'we_transfer_client'
9
- require 'pry'
10
- require 'rspec'
11
- require 'bundler'
12
- Bundler.setup
13
- require 'tempfile'
14
- require 'dotenv'
15
- Dotenv.load
16
-
17
- module SpecHelpers
18
- def fixtures_dir
19
- __dir__ + '/fixtures/'
20
- end
21
-
22
- def test_logger
23
- Logger.new($stderr).tap { |log| log.level = Logger::WARN }
24
- end
25
- end
26
-
27
- RSpec.configure do |config|
28
- config.include SpecHelpers
29
- config.extend SpecHelpers
30
-
31
- config.expect_with :rspec do |c|
32
- c.syntax = :expect
33
- end
34
-
35
- config.filter_run :focus
36
- config.run_all_when_everything_filtered = true
37
- config.default_formatter = 'doc'
38
- config.order = :random
39
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe WeTransfer::Client do
6
- let(:client) { WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY')) }
7
- let(:file_locations) { %w[Japan-01.jpg Japan-02.jpg] }
8
-
9
- describe described_class::Transfers do
10
- pending 'creates a transfer with multiple files' do
11
- skip "this interface is still experimental"
12
- transfer = client.create_transfer(message: 'Japan: 🏯 & 🎎') do |builder|
13
- file_locations.each do |file_location|
14
- builder.add_file(name: File.basename(file_location), io: File.open(fixtures_dir + file_location, 'rb'))
15
- end
16
- end
17
-
18
- expect(transfer).to be_kind_of(RemoteTransfer)
19
-
20
- # it has an url that is not available (yet)
21
- expect(transfer.url).to be(nil)
22
- # it has no files (yet)
23
- expect(transfer.files.first.url).to be(nil)
24
- # it is in an uploading state
25
- expect(transfer.state).to eq('uploading')
26
-
27
- # TODO: uncouple file_locations and transfer.files
28
- file_locations.each_with_index do |location, index|
29
- client.upload_file(
30
- object: transfer,
31
- file: transfer.files[index],
32
- io: File.open(fixtures_dir + location, 'rb')
33
- )
34
- client.complete_file!(
35
- object: transfer,
36
- file: transfer.files[index]
37
- )
38
- end
39
-
40
- result = client.complete_transfer(transfer: transfer)
41
-
42
- # it has an url that is available
43
- expect(result.url =~ %r|^https://we.tl/t-|).to be_truthy
44
-
45
- # it is in a processing state
46
- expect(result.state).to eq('processing')
47
-
48
- response = Faraday.get(result.url)
49
- # it hits the short-url with redirect
50
- expect(response.status).to eq(302)
51
- expect(response['location']).to start_with('https://wetransfer.com/')
52
- end
53
- end
54
- end
@@ -1,66 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BoardBuilder do
4
- describe '#initialize' do
5
- it 'initializes with an empty array' do
6
- expect(subject.items.empty?).to be(true)
7
- end
8
- end
9
-
10
- describe '#add_file' do
11
- it 'returns an error when name is missing' do
12
- expect {
13
- subject.add_file(io: File.open(__FILE__, 'rb'))
14
- }.to raise_error ArgumentError, /name/
15
- end
16
-
17
- it 'returns an error when io is missing' do
18
- expect {
19
- subject.add_file(name: 'file name')
20
- }.to raise_error ArgumentError, /io/
21
- end
22
-
23
- it 'returns a error when file doesnt exists' do
24
- expect {
25
- subject.add_file(name: 'file name', io: File.open('foo', 'rb'))
26
- }.to raise_error Errno::ENOENT
27
- end
28
-
29
- it 'adds a file when name and io is given' do
30
- subject.add_file(name: 'file name', io: File.open(__FILE__, 'rb'))
31
- expect(subject.items.first).to be_kind_of(FutureFile)
32
- end
33
- end
34
-
35
- describe '#add_file_at' do
36
- before do
37
- skip "this interface is still experimental"
38
- end
39
-
40
- it 'adds a file from a path' do
41
- subject.add_file_at(path: __FILE__)
42
- expect(subject.items.first).to be_kind_of(FutureFile)
43
- end
44
-
45
- it 'throws a Error when file doesnt exists' do
46
- expect {
47
- subject.add_file_at(path: '/this/path/leads/to/nothing.exe')
48
- }.to raise_error Errno::ENOENT
49
- end
50
-
51
- it 'should call #add_file' do
52
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
53
- client.create_board(name: 'Test board', description: 'A board description') do |b|
54
- expect(b).to receive(:add_file).with(name: anything, io: kind_of(::IO))
55
- b.add_file_at(path: __FILE__)
56
- end
57
- end
58
- end
59
-
60
- describe '#add_web_url' do
61
- it 'adds a item to board when url and title are given' do
62
- subject.add_web_url(url: 'http://www.wetransfer.com', title: 'wetransfer')
63
- expect(subject.items.first).to be_kind_of(FutureLink)
64
- end
65
- end
66
- end
@@ -1,56 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require_relative '../../lib/we_transfer_client.rb'
4
-
5
- describe WeTransfer::Client::Boards do
6
- describe '#create_board_and_upload_items' do
7
- it 'creates a board and uploads the files' do
8
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
9
- board = client.create_board_and_upload_items(name: 'test', description: 'test description') do |b|
10
- b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
11
- b.add_web_url(url: 'http://www.wetransfer.com', title: 'WeTransfer Website')
12
- end
13
- expect(board).to be_kind_of(RemoteBoard)
14
- expect(board.url).to start_with('https://we.tl/')
15
- expect(board.state).to eq('downloadable')
16
- end
17
- end
18
-
19
- describe "experimental features" do
20
- before do
21
- skip "this interface is still experimental"
22
- end
23
-
24
- describe '#create_board' do
25
- it 'creates a board' do
26
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
27
- board = client.create_board(name: 'test', description: 'test description')
28
- expect(board).to be_kind_of(RemoteBoard)
29
- end
30
- end
31
-
32
- describe "#add_items" do
33
- it 'adds items to an existing board' do
34
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
35
- board = client.create_board(name: 'test', description: 'test description')
36
- updated_board = client.add_items(board: board) do |b|
37
- b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
38
- b.add_web_url(url: 'http://www.wetransfer.com', title: 'WeTransfer Website')
39
- end
40
- expect(updated_board).to be_kind_of(RemoteBoard)
41
- expect(updated_board.items.size).to eq(2)
42
- expect(updated_board.items.map(&:class)).to eq([RemoteFile, RemoteLink])
43
- end
44
- end
45
-
46
- describe "#get_board" do
47
- it 'gets board' do
48
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
49
- board = client.create_board(name: 'test', description: 'test description')
50
- board_request = client.get_board(board: board)
51
-
52
- expect(board_request).to be_kind_of(RemoteBoard)
53
- end
54
- end
55
- end
56
- end
@@ -1,98 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FutureBoard do
4
- let(:params) { { name: 'yes', description: 'A description about the board', items: [] } }
5
-
6
- describe '#initializer' do
7
- it 'raises ArgumentError when no name is given' do
8
- params.delete(:name)
9
- expect {
10
- described_class.new(params)
11
- }.to raise_exception ArgumentError, /name/
12
- end
13
-
14
- it 'accepts a blank description' do
15
- params.delete(:description)
16
- described_class.new(params)
17
- end
18
-
19
- it 'accepts a empty array as item argument' do
20
- expect(described_class.new(params).items).to be_kind_of(Array)
21
- end
22
- end
23
-
24
- describe '#to_initial_request_params' do
25
- it 'has a name' do
26
- as_params = described_class.new(params).to_initial_request_params
27
- expect(as_params[:name]).to be_kind_of(String)
28
- end
29
-
30
- it 'has a description' do
31
- as_params = described_class.new(params).to_initial_request_params
32
- expect(as_params[:description]).to be(params[:description])
33
- end
34
- end
35
-
36
- describe '#to_request_params' do
37
- it 'has a name' do
38
- as_params = described_class.new(params).to_request_params
39
- expect(as_params[:name]).to be_kind_of(String)
40
- end
41
-
42
- it 'has a description' do
43
- as_params = described_class.new(params).to_request_params
44
- expect(as_params[:description]).to be(params[:description])
45
- end
46
-
47
- it 'has items' do
48
- file = FutureFile.new(name: 'yes', io: File.open(__FILE__, 'rb'))
49
- params[:items] << file
50
- as_params = described_class.new(params).to_request_params
51
- expect(as_params[:items].count).to be(1)
52
- end
53
- end
54
-
55
- describe '#files' do
56
- it 'returns only file items' do
57
- file = FutureFile.new(name: 'yes', io: File.open(__FILE__, 'rb'))
58
- link = FutureLink.new(url: 'https://www.wetransfer.com', title: 'WeTransfer')
59
- future_board = described_class.new(params)
60
- 3.times do
61
- future_board.items << file
62
- future_board.items << link
63
- end
64
- expect(future_board.items.size).to eq(6)
65
- expect(future_board.files.size).to eq(3)
66
- end
67
- end
68
-
69
- describe '#links' do
70
- it 'returns only link items' do
71
- file = FutureFile.new(name: 'yes', io: File.open(__FILE__, 'rb'))
72
- link = FutureLink.new(url: 'https://www.wetransfer.com', title: 'WeTransfer')
73
- future_board = described_class.new(params)
74
- 3.times do
75
- future_board.items << file
76
- future_board.items << link
77
- end
78
- expect(future_board.items.size).to eq(6)
79
- expect(future_board.links.size).to eq(3)
80
- end
81
- end
82
-
83
- describe 'getters' do
84
- let(:subject) { described_class.new(params) }
85
-
86
- it '#name' do
87
- subject.name
88
- end
89
-
90
- it '#description' do
91
- subject.description
92
- end
93
-
94
- it 'items' do
95
- subject.items
96
- end
97
- end
98
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FutureFile do
4
- let(:params) { { name: 'yes', io: File.open(__FILE__, 'rb') } }
5
-
6
- describe '#initilizer' do
7
- it 'needs an :io keyword arg' do
8
- params.delete(:io)
9
-
10
- expect {
11
- described_class.new(params)
12
- }.to raise_error(ArgumentError, /io/)
13
- end
14
-
15
- it 'needs a :name keyword arg' do
16
- params.delete(:name)
17
-
18
- expect {
19
- described_class.new(params)
20
- }.to raise_error(ArgumentError, /name/)
21
- end
22
-
23
- it 'succeeds if given all arguments' do
24
- described_class.new(params)
25
- end
26
- end
27
-
28
- describe '#to_request_params' do
29
- it 'returns a hash with name and size' do
30
- as_params = described_class.new(params).to_request_params
31
-
32
- expect(as_params[:name]).to eq('yes')
33
- expect(as_params[:size]).to be_kind_of(Integer)
34
- end
35
- end
36
-
37
- describe 'getters' do
38
- let(:subject) { described_class.new(params) }
39
-
40
- it '#name' do
41
- subject.name
42
- end
43
-
44
- it '#io' do
45
- subject.io
46
- end
47
- end
48
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FutureLink do
4
- let(:params) { { url: 'http://www.wetransfer.com', title: 'WeTransfer' } }
5
-
6
- describe '#initializer' do
7
- it 'needs a :url keyword arg' do
8
- params.delete(:url)
9
- expect {
10
- described_class.new(params)
11
- }.to raise_error(ArgumentError, /url/)
12
- end
13
-
14
- it 'takes url when no title is given' do
15
- params.delete(:title)
16
- expect(described_class.new(params).title).to be(params.fetch(:url))
17
- end
18
-
19
- it 'succeeds if given all arguments' do
20
- described_class.new(params)
21
- end
22
- end
23
-
24
- describe '#to_request_params' do
25
- it 'creates params properly' do
26
- as_params = described_class.new(params).to_request_params
27
-
28
- expect(as_params[:url]).to eq('http://www.wetransfer.com')
29
- expect(as_params[:title]).to be_kind_of(String)
30
- end
31
- end
32
-
33
- describe 'getters' do
34
- let(:subject) { described_class.new(params) }
35
-
36
- it '#url' do
37
- subject.url
38
- end
39
-
40
- it '#title' do
41
- subject.title
42
- end
43
- end
44
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FutureTransfer do
4
- let(:transfer) { described_class }
5
-
6
- describe '#initialize' do
7
- it 'creates an empty array when initialized' do
8
- expect(transfer.new(message: 'transfer').files).to be_kind_of(Array)
9
- end
10
-
11
- it 'throws a error when message is not given' do
12
- expect {
13
- transfer.new
14
- }.to raise_error ArgumentError
15
- end
16
- end
17
-
18
- describe 'getters' do
19
- it 'message' do
20
- transfer.new(message: 'test').message
21
- end
22
-
23
- it 'files' do
24
- transfer.new(message: 'test').files
25
- end
26
- end
27
-
28
- describe 'to_request_params' do
29
- it 'includes the message' do
30
- new_transfer = transfer.new(message: 'test')
31
- expect(new_transfer.to_request_params[:message]).to be(new_transfer.message)
32
- end
33
-
34
- it 'includes the files as an array' do
35
- new_transfer = transfer.new(message: 'test')
36
- expect(new_transfer.to_request_params[:files]).to eq([])
37
- end
38
- end
39
- end
@@ -1,92 +0,0 @@
1
-
2
- require 'spec_helper'
3
-
4
- describe RemoteBoard do
5
- subject { described_class.new(params) }
6
-
7
- let(:params) {
8
- {
9
- id: SecureRandom.uuid,
10
- state: 'downloadable',
11
- url: 'http://wt.tl/123abcd',
12
- name: 'RemoteBoard',
13
- description: 'Test Description',
14
- items: [
15
- {
16
- id: 's7l1urvgqs1b6u9v720180911093825',
17
- name: 'board_integration_spec.rb',
18
- size: 3036,
19
- multipart: {
20
- part_numbers: 1,
21
- chunk_size: 3036
22
- },
23
- type: 'file',
24
- },
25
- {
26
- id: 'storr6ua2l1fsl8lt20180911093826',
27
- url: 'http://www.wetransfer.com',
28
- meta: {title: 'WeTransfer Website'},
29
- type: 'link',
30
- }
31
- ]
32
- }
33
- }
34
-
35
- describe '#initializer' do
36
- it 'is valid with all params' do
37
- subject
38
- end
39
-
40
- it 'is valid without description' do
41
- params.delete(:description)
42
- subject
43
- end
44
-
45
- it 'is valid without items' do
46
- params.delete(:items)
47
- subject
48
- end
49
-
50
- %i[id name state url].each do |param|
51
- it "is invalid without #{param}" do
52
- params.delete(param)
53
- expect {
54
- subject
55
- }.to raise_error ArgumentError, %r[#{param}]
56
- end
57
- end
58
-
59
- describe 'items' do
60
- it 'are instantiated' do
61
- expect(subject.items.map(&:class)).to eq([RemoteFile, RemoteLink])
62
- end
63
-
64
- it 'raises ItemTypeError if the item has a wrong type' do
65
- params[:items] = [{ type: 'foo' }]
66
- expect { subject }.to raise_error(RemoteBoard::ItemTypeError)
67
- end
68
- end
69
- end
70
-
71
- describe '#files' do
72
- it 'returns only file item' do
73
- expect(subject.items.size).to eq(2)
74
- expect(subject.files.size).to eq(1)
75
- end
76
- end
77
-
78
- describe '#links' do
79
- it 'returns only link item' do
80
- expect(subject.items.size).to eq(2)
81
- expect(subject.links.size).to eq(1)
82
- end
83
- end
84
-
85
- describe 'getters' do
86
- %i[id items url state].each do |getter|
87
- it "responds to ##{getter}" do
88
- subject.send getter
89
- end
90
- end
91
- end
92
- end
@@ -1,91 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RemoteFile do
4
- let(:params) {
5
- {
6
- id: SecureRandom.uuid,
7
- name: 'Board name',
8
- size: Random.rand(9999999),
9
- url: nil,
10
- multipart: {
11
- part_numbers: Random.rand(10),
12
- id: SecureRandom.uuid,
13
- chunk_size: RemoteBoard::CHUNK_SIZE,
14
- },
15
- type: 'file',
16
- }}
17
-
18
- describe '#initializer' do
19
- it 'initialized when no url is given' do
20
- params.delete(:url)
21
- described_class.new(params)
22
- end
23
-
24
- it 'initialized when no item is given' do
25
- params.delete(:items)
26
- described_class.new(params)
27
- end
28
-
29
- it 'fails when id is missing' do
30
- params.delete(:id)
31
- expect {
32
- described_class.new(params)
33
- }.to raise_error ArgumentError, /id/
34
- end
35
-
36
- it 'fails when state is missing' do
37
- params.delete(:size)
38
- expect {
39
- described_class.new(params)
40
- }.to raise_error ArgumentError, /size/
41
- end
42
-
43
- it 'fails when url is missing' do
44
- params.delete(:multipart)
45
- expect {
46
- described_class.new(params)
47
- }.to raise_error ArgumentError, /multipart/
48
- end
49
-
50
- it 'fails when name is missing' do
51
- params.delete(:name)
52
- expect {
53
- described_class.new(params)
54
- }.to raise_error ArgumentError, /name/
55
- end
56
-
57
- it 'must have a struct in multipart' do
58
- remote_file = described_class.new(params)
59
- expect(remote_file.multipart).to be_kind_of(Struct)
60
- end
61
-
62
- it 'multipart has partnumber, id and chunk_size keys' do
63
- remote_file = described_class.new(params)
64
- expect(remote_file.multipart.members).to eq(params[:multipart].keys)
65
- end
66
- end
67
-
68
- describe 'Getters' do
69
- let(:subject) { described_class.new(params) }
70
-
71
- it '#multipart' do
72
- subject.multipart
73
- end
74
-
75
- it '#name' do
76
- subject.name
77
- end
78
-
79
- it '#type' do
80
- subject.type
81
- end
82
-
83
- it '#id' do
84
- subject.id
85
- end
86
-
87
- it '#url' do
88
- subject.url
89
- end
90
- end
91
- end
@@ -1,33 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RemoteLink do
4
- let(:params) {
5
- {
6
- id: SecureRandom.uuid,
7
- url: 'http://www.wetransfer.com',
8
- meta: {title: 'wetransfer.com'},
9
- type: 'link',
10
- }
11
- }
12
-
13
- describe '#initialize' do
14
- attributes = %i[id url type meta]
15
-
16
- attributes.each do |atttribute|
17
- it "raises an ArgumentError when #{atttribute} is missing" do
18
- params.delete(atttribute)
19
- expect {
20
- described_class.new(params)
21
- }.to raise_error ArgumentError, %r{#{atttribute}}
22
- end
23
- end
24
- end
25
-
26
- describe 'getters' do
27
- subject { described_class.new(params) }
28
-
29
- it 'responds to #type' do
30
- expect(subject.type).to eq 'link'
31
- end
32
- end
33
- end
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RemoteTransfer do
4
- let(:params) {
5
- {
6
- id: '2ae97886522f375c1c6696799a56f0d820180912075119',
7
- state: 'uploading',
8
- message: 'Test transfer',
9
- url: nil,
10
- files:
11
- [
12
- {
13
- id: '5e3823ea8ad54f259c85b776eaf7086e20180912075119',
14
- name: 'transfer_integration_spec.rb',
15
- size: 7361,
16
- multipart: {part_numbers: 1, chunk_size: 7361},
17
- type: 'file',
18
- },
19
- {
20
- id: '43b5a6323102eced46f071f2db9ec2eb20180912075119',
21
- name: 'two_chunks',
22
- size: 6291460,
23
- multipart: {part_numbers: 2, chunk_size: 5242880},
24
- type: 'file',
25
- }
26
- ]
27
- }
28
- }
29
-
30
- describe '#initialize' do
31
- it 'fails when id is missing' do
32
- params.delete(:id)
33
- expect {
34
- described_class.new(params)
35
- }.to raise_error ArgumentError, /id/
36
- end
37
-
38
- it 'fails when state is missing' do
39
- params.delete(:state)
40
- expect {
41
- described_class.new(params)
42
- }.to raise_error ArgumentError, /state/
43
- end
44
-
45
- it 'fails when message is missing' do
46
- params.delete(:message)
47
- expect {
48
- described_class.new(params)
49
- }.to raise_error ArgumentError, /message/
50
- end
51
-
52
- it 'fails when files is a string' do
53
- params.delete(:files)
54
- params[:files] = 'Not an array'
55
- expect {
56
- described_class.new(params)
57
- }.to raise_error NoMethodError
58
- end
59
-
60
- it 'fails when files is a string' do
61
- params.delete(:files)
62
- params[:files] = 'Not an array'
63
- expect {
64
- described_class.new(params)
65
- }.to raise_error NoMethodError
66
- end
67
- end
68
-
69
- describe '#files_to_class' do
70
- it 'creates classes of remote files' do
71
- transfer = described_class.new(params)
72
- expect(transfer.files.map(&:class)).to eq([RemoteFile, RemoteFile])
73
- end
74
- end
75
-
76
- describe '#prepare_file_upload' do
77
- pending 'it retreives the upload url' do
78
- fail
79
- end
80
- end
81
-
82
- describe '#Getters' do
83
- subject { described_class.new(params) }
84
-
85
- it '#files' do
86
- subject.files
87
- end
88
-
89
- it '#url' do
90
- subject.url
91
- end
92
-
93
- it '#state' do
94
- subject.state
95
- end
96
-
97
- it '#id' do
98
- subject.id
99
- end
100
- end
101
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe TransferBuilder do
4
- let(:transfer) { described_class.new }
5
-
6
- describe '#initialze' do
7
- it 'initializes with an empty files array' do
8
- expect(transfer.files.empty?).to be(true)
9
- end
10
- end
11
-
12
- describe '#add_file' do
13
- it 'returns an error when name is missing' do
14
- expect {
15
- transfer.add_file(io: File.open(__FILE__, 'rb'))
16
- }.to raise_error ArgumentError, /name/
17
- end
18
-
19
- it 'returns an error when io is missing' do
20
- expect {
21
- transfer.add_file(name: 'file name')
22
- }.to raise_error ArgumentError, /io/
23
- end
24
-
25
- it 'returns a error when file doesnt exists' do
26
- expect {
27
- transfer.add_file(name: 'file name', io: File.open('foo', 'rb'))
28
- }.to raise_error Errno::ENOENT
29
- end
30
-
31
- it 'adds a file when name and io is given' do
32
- transfer.add_file(name: 'file name', io: File.open(__FILE__, 'rb'))
33
- expect(transfer.files.first).to be_kind_of(FutureFile)
34
- end
35
- end
36
-
37
- describe '#add_file_at' do
38
- it 'adds a file from a path' do
39
- transfer.add_file_at(path: __FILE__)
40
- expect(transfer.files.first).to be_kind_of(FutureFile)
41
- end
42
-
43
- it 'throws a Error when file doesnt exists' do
44
- expect {
45
- transfer.add_file_at(path: '/this/path/leads/to/nothing.exe')
46
- }.to raise_error Errno::ENOENT
47
- end
48
-
49
- pending 'should call #add_file' do
50
- skip "Lets not trigger status:400 errors"
51
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
52
- client.create_transfer(message: 'A transfer message') do |builder|
53
- expect(builder).to receive(:add_file).with(name: kind_of(String), io: kind_of(::File))
54
- builder.add_file_at(path: __FILE__)
55
- end
56
- end
57
- end
58
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WeTransfer::Client::Transfers do
4
- describe '#create_transfer_and_upload_files' do
5
- it 'creates a transfer and uploads the files' do
6
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
7
- transfer = client.create_transfer_and_upload_files(message: 'test description') do |b|
8
- b.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
9
- b.add_file_at(path: fixtures_dir + 'Japan-01.jpg')
10
- end
11
-
12
- expect(transfer).to be_kind_of(RemoteTransfer)
13
- expect(transfer.url).to start_with('https://we.tl/')
14
-
15
- transfer = loop do
16
- res = client.get_transfer(transfer_id: transfer.id)
17
- break res if res.state != 'processing'
18
- sleep 1
19
- end
20
-
21
- expect(transfer.state).to eq('downloadable')
22
- end
23
-
24
- it 'fails when no files are added' do
25
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY'))
26
- expect {
27
- client.create_transfer_and_upload_files(message: 'test description')
28
- }.to raise_error ArgumentError, /No files/
29
- end
30
-
31
- it 'fails with duplicate file names' do
32
- client = WeTransfer::Client.new(api_key: ENV.fetch('WT_API_KEY', logger: test_logger))
33
- expect {
34
- client.create_transfer_and_upload_files(message: 'All the (same) Things') do |builder|
35
- builder.add_file(name: 'README.txt', io: StringIO.new("A thing"))
36
- builder.add_file(name: 'README.txt', io: StringIO.new("another thing"))
37
- end
38
- }.to raise_error ArgumentError, /Duplicate file entry/
39
- end
40
- end
41
-
42
- pending '#create_transfers'
43
- pending "#complete_transfer"
44
- pending "#get_transfer"
45
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WeTransfer::Client do
4
- subject { described_class.new(params) }
5
- let(:params) { { api_key: ENV.fetch('WT_API_KEY') } }
6
-
7
- it 'exposes VERSION' do
8
- expect(WeTransfer::VERSION).to be_kind_of(String)
9
- end
10
-
11
- describe "#ensure_ok_status!" do
12
- before(:all) { Response = Struct.new(:status) }
13
-
14
- context "on success" do
15
- it "returns true if the status code is in the 2xx range" do
16
- (200..299).each do |status_code|
17
- response = Response.new(status_code)
18
- expect(subject.ensure_ok_status!(response)).to be_truthy
19
- end
20
- end
21
- end
22
-
23
- context "unsuccessful" do
24
- it "raises with a message including the status code the server returned" do
25
- response = Response.new("404")
26
- expect { subject.ensure_ok_status!(response) }
27
- .to raise_error(WeTransfer::Client::Error, %r/Response had a 404 code/)
28
-
29
- response = Response.new("Mehh")
30
- expect { subject.ensure_ok_status!(response) }
31
- .to raise_error(WeTransfer::Client::Error, %r/Response had a Mehh code/)
32
- end
33
-
34
- it "if there is a server error, it raises with information that we can retry" do
35
- (500..504).each do |status_code|
36
- response = Response.new(status_code)
37
- expect { subject.ensure_ok_status!(response) }
38
- .to raise_error(WeTransfer::Client::Error, /we could retry/)
39
- end
40
- end
41
-
42
- it "on client error, it raises with information that the server cannot understand this" do
43
- (400..499).each do |status_code|
44
- response = Response.new(status_code)
45
- expect { subject.ensure_ok_status!(response) }
46
- .to raise_error(WeTransfer::Client::Error, /server will not accept this request even if retried/)
47
- end
48
- end
49
-
50
- it "if the status code is unknown, it raises a generic error" do
51
- response = Response.new("I aint a status code")
52
- expect { subject.ensure_ok_status!(response) }
53
- .to raise_error(WeTransfer::Client::Error, /no idea what to do/)
54
- end
55
- end
56
- end
57
- end