wetransfer 0.4.4 → 0.9.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -2
- data/.rubocop.yml +1 -1
- data/.travis.yml +3 -2
- data/Guardfile +11 -0
- data/README.md +81 -38
- data/V2_README.md +53 -0
- data/examples/create_collection.rb +13 -0
- data/examples/create_transfer.rb +1 -1
- data/lib/we_transfer_client.rb +86 -120
- data/lib/we_transfer_client/board_builder.rb +33 -0
- data/lib/we_transfer_client/boards.rb +74 -0
- data/lib/we_transfer_client/future_board.rb +32 -0
- data/lib/we_transfer_client/future_file.rb +28 -0
- data/lib/we_transfer_client/future_link.rb +28 -0
- data/lib/we_transfer_client/future_transfer.rb +11 -5
- data/lib/we_transfer_client/remote_board.rb +47 -0
- data/lib/we_transfer_client/remote_file.rb +55 -0
- data/lib/we_transfer_client/remote_link.rb +9 -0
- data/lib/we_transfer_client/remote_transfer.rb +24 -1
- data/lib/we_transfer_client/transfer_builder.rb +3 -10
- data/lib/we_transfer_client/transfers.rb +73 -0
- data/lib/we_transfer_client/version.rb +2 -2
- data/spec/board_integration_spec.rb +68 -0
- data/spec/features/add_items_to_board_spec.rb +55 -0
- data/spec/features/create_board_spec.rb +46 -0
- data/spec/features/get_board_spec.rb +34 -0
- data/spec/features/transfer_spec.rb +41 -0
- data/spec/fixtures/Japan-01.jpg +0 -0
- data/spec/fixtures/Japan-02.jpg +0 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/transfer_integration_spec.rb +54 -0
- data/spec/we_transfer_client/board_builder_spec.rb +66 -0
- data/spec/we_transfer_client/boards_spec.rb +56 -0
- data/spec/we_transfer_client/future_board_spec.rb +98 -0
- data/spec/we_transfer_client/future_file_spec.rb +48 -0
- data/spec/we_transfer_client/future_link_spec.rb +44 -0
- data/spec/we_transfer_client/future_transfer_spec.rb +30 -13
- data/spec/we_transfer_client/remote_board_spec.rb +92 -0
- data/spec/we_transfer_client/remote_file_spec.rb +91 -0
- data/spec/we_transfer_client/remote_link_spec.rb +33 -0
- data/spec/we_transfer_client/remote_transfer_spec.rb +101 -0
- data/spec/we_transfer_client/transfer_builder_spec.rb +48 -51
- data/spec/we_transfer_client/transfers_spec.rb +45 -0
- data/spec/we_transfer_client_spec.rb +51 -3
- data/wetransfer.gemspec +11 -5
- metadata +67 -27
- data/lib/we_transfer_client/future_file_item.rb +0 -16
- data/lib/we_transfer_client/future_web_item.rb +0 -18
- data/lib/we_transfer_client/remote_item.rb +0 -2
- data/spec/integration_spec.rb +0 -160
- data/spec/we_transfer_client/future_file_item_spec.rb +0 -39
- data/spec/we_transfer_client/future_web_item_spec.rb +0 -39
@@ -1,16 +0,0 @@
|
|
1
|
-
class FutureFileItem < Ks.strict(:name, :io, :local_identifier)
|
2
|
-
def initialize(**kwargs)
|
3
|
-
super(local_identifier: SecureRandom.uuid, **kwargs)
|
4
|
-
end
|
5
|
-
|
6
|
-
def to_item_request_params
|
7
|
-
# Ideally the content identifier should stay the same throughout multiple
|
8
|
-
# calls if the file contents doesn't change.
|
9
|
-
{
|
10
|
-
content_identifier: 'file',
|
11
|
-
local_identifier: local_identifier,
|
12
|
-
filename: name,
|
13
|
-
filesize: io.size,
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class FutureWebItem < Ks.strict(:url, :title, :local_identifier)
|
2
|
-
def initialize(**kwargs)
|
3
|
-
super(local_identifier: SecureRandom.uuid, **kwargs)
|
4
|
-
end
|
5
|
-
|
6
|
-
def to_item_request_params
|
7
|
-
# Ideally the content identifier should stay the same throughout multiple
|
8
|
-
# calls if the file contents doesn't change.
|
9
|
-
{
|
10
|
-
content_identifier: 'web_content',
|
11
|
-
local_identifier: local_identifier,
|
12
|
-
url: url,
|
13
|
-
meta: {
|
14
|
-
title: title
|
15
|
-
}
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
data/spec/integration_spec.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require_relative '../lib/we_transfer_client.rb'
|
4
|
-
|
5
|
-
describe WeTransferClient do
|
6
|
-
let :test_logger do
|
7
|
-
Logger.new($stderr).tap { |log| log.level = Logger::WARN }
|
8
|
-
end
|
9
|
-
|
10
|
-
let :very_large_file do
|
11
|
-
tf = Tempfile.new('test-upload')
|
12
|
-
20.times { tf << Random.new.bytes(1024 * 1024) }
|
13
|
-
tf << Random.new.bytes(rand(1..512))
|
14
|
-
tf.rewind
|
15
|
-
tf
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'is able to create a transfer start to finish, both with small and large files' do
|
19
|
-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
|
20
|
-
transfer = client.create_transfer(name: 'My amazing board', description: 'Hi there!') do |builder|
|
21
|
-
# Upload ourselves
|
22
|
-
add_result = builder.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
|
23
|
-
expect(add_result).to eq(true)
|
24
|
-
|
25
|
-
# Upload ourselves again, but using add_file_at
|
26
|
-
add_result = builder.add_file_at(path: __FILE__) # Upload ourselves again, but this time via path
|
27
|
-
expect(add_result).to eq(true)
|
28
|
-
|
29
|
-
# Upload the large file
|
30
|
-
add_result = builder.add_file(name: 'large.bin', io: very_large_file)
|
31
|
-
expect(add_result).to eq(true)
|
32
|
-
|
33
|
-
expect(add_result).to eq(true)
|
34
|
-
end
|
35
|
-
|
36
|
-
expect(transfer).to be_kind_of(RemoteTransfer)
|
37
|
-
expect(transfer.id).to be_kind_of(String)
|
38
|
-
|
39
|
-
# expect(transfer.version_identifier).to be_kind_of(String)
|
40
|
-
expect(transfer.state).to be_kind_of(String)
|
41
|
-
expect(transfer.name).to eq('My amazing board')
|
42
|
-
expect(transfer.description).to eq('Hi there!')
|
43
|
-
expect(transfer.items).to be_kind_of(Array)
|
44
|
-
expect(transfer.items.length).to eq(3)
|
45
|
-
|
46
|
-
item = transfer.items.first
|
47
|
-
expect(item).to be_kind_of(RemoteItem)
|
48
|
-
|
49
|
-
expect(transfer.shortened_url).to be_kind_of(String)
|
50
|
-
response = Faraday.get(transfer.shortened_url)
|
51
|
-
expect(response.status).to eq(302)
|
52
|
-
expect(response['location']).to start_with('https://wetransfer')
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'is able to create a transfer with no items even if passed a block' do
|
56
|
-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
|
57
|
-
response = client.create_transfer(name: 'My amazing board', description: 'Hi there!') do |builder|
|
58
|
-
end
|
59
|
-
expect(response[:size]).to eq(0)
|
60
|
-
expect(response[:items]).to eq([])
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'is able to create a transfer with no items without a block' do
|
64
|
-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
|
65
|
-
response = client.create_empty_transfer(name: 'My amazing board', description: 'Hi there!')
|
66
|
-
expect(response[:size]).to eq(0)
|
67
|
-
expect(response[:items]).to eq([])
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'refuses to create a transfer when reading an IO raises an error' do
|
71
|
-
broken = StringIO.new('hello')
|
72
|
-
def broken.read(*)
|
73
|
-
raise 'This failed somehow'
|
74
|
-
end
|
75
|
-
|
76
|
-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
|
77
|
-
expect(client).not_to receive(:faraday) # Since we will not be doing any requests - we fail earlier
|
78
|
-
expect {
|
79
|
-
client.create_transfer(name: 'My amazing board', description: 'Hi there!') do |builder|
|
80
|
-
builder.add_file(name: 'broken', io: broken)
|
81
|
-
end
|
82
|
-
}.to raise_error(/failed somehow/)
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'refuses to create a transfer when given an IO of 0 size' do
|
86
|
-
broken = StringIO.new('')
|
87
|
-
|
88
|
-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
|
89
|
-
expect {
|
90
|
-
client.create_transfer(name: 'My amazing board', description: 'Hi there!') do |builder|
|
91
|
-
builder.add_file(name: 'broken', io: broken)
|
92
|
-
end
|
93
|
-
}.to raise_error(/has a size of 0/)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'is able to create a transfer with only webcontent' do
|
97
|
-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
|
98
|
-
transfer = client.create_transfer(name: 'My collection of web content', description: 'link collection') do |builder|
|
99
|
-
10.times do
|
100
|
-
builder.add_web_url(url: 'https://www.wetransfer.com')
|
101
|
-
end
|
102
|
-
end
|
103
|
-
expect(transfer).to be_kind_of(RemoteTransfer)
|
104
|
-
expect(transfer.id).to be_kind_of(String)
|
105
|
-
|
106
|
-
# expect(transfer.version_identifier).to be_kind_of(String)
|
107
|
-
expect(transfer.state).to be_kind_of(String)
|
108
|
-
expect(transfer.name).to eq('My collection of web content')
|
109
|
-
expect(transfer.description).to eq('link collection')
|
110
|
-
expect(transfer.items).to be_kind_of(Array)
|
111
|
-
expect(transfer.items.length).to eq(10)
|
112
|
-
|
113
|
-
item = transfer.items.first
|
114
|
-
expect(item).to be_kind_of(RemoteItem)
|
115
|
-
|
116
|
-
expect(transfer.shortened_url).to be_kind_of(String)
|
117
|
-
response = Faraday.get(transfer.shortened_url)
|
118
|
-
expect(response.status).to eq(302)
|
119
|
-
expect(response['location']).to start_with('https://wetransfer')
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'is able to create a transfer with web_content and files' do
|
123
|
-
client = WeTransferClient.new(api_key: ENV.fetch('WT_API_KEY'), logger: test_logger)
|
124
|
-
transfer = client.create_transfer(name: 'Mixed Board Content', description: 'Files and Webcontent') do |builder|
|
125
|
-
# Upload ourselves
|
126
|
-
add_result = builder.add_file(name: File.basename(__FILE__), io: File.open(__FILE__, 'rb'))
|
127
|
-
expect(add_result).to eq(true)
|
128
|
-
|
129
|
-
# Upload ourselves again, but using add_file_at
|
130
|
-
add_result = builder.add_file_at(path: __FILE__) # Upload ourselves again, but this time via path
|
131
|
-
expect(add_result).to eq(true)
|
132
|
-
|
133
|
-
# Upload the large file
|
134
|
-
add_result = builder.add_file(name: 'large.bin', io: very_large_file)
|
135
|
-
expect(add_result).to eq(true)
|
136
|
-
|
137
|
-
# add url to transfer
|
138
|
-
add_result = builder.add_web_url(url: 'http://www.wetransfer.com', title: 'website used for file transfers')
|
139
|
-
expect(add_result).to eq(true)
|
140
|
-
end
|
141
|
-
|
142
|
-
expect(transfer).to be_kind_of(RemoteTransfer)
|
143
|
-
expect(transfer.id).to be_kind_of(String)
|
144
|
-
|
145
|
-
# expect(transfer.version_identifier).to be_kind_of(String)
|
146
|
-
expect(transfer.state).to be_kind_of(String)
|
147
|
-
expect(transfer.name).to eq('Mixed Board Content')
|
148
|
-
expect(transfer.description).to eq('Files and Webcontent')
|
149
|
-
expect(transfer.items).to be_kind_of(Array)
|
150
|
-
expect(transfer.items.length).to eq(4)
|
151
|
-
|
152
|
-
item = transfer.items.first
|
153
|
-
expect(item).to be_kind_of(RemoteItem)
|
154
|
-
|
155
|
-
expect(transfer.shortened_url).to be_kind_of(String)
|
156
|
-
response = Faraday.get(transfer.shortened_url)
|
157
|
-
expect(response.status).to eq(302)
|
158
|
-
expect(response['location']).to start_with('https://wetransfer')
|
159
|
-
end
|
160
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FutureFileItem do
|
4
|
-
it 'errors if not given all required arguments' do
|
5
|
-
expect {
|
6
|
-
described_class.new(name: 'nope', local_identifier: 'sorry')
|
7
|
-
}.to raise_error(/missing keyword: io/)
|
8
|
-
|
9
|
-
expect {
|
10
|
-
described_class.new(io: 'nope')
|
11
|
-
}.to raise_error(/missing keyword: name/)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'succeeds if given all arguments' do
|
15
|
-
future_file_item = described_class.new(name: 'yes', io: 'hello', local_identifier: '4815162342')
|
16
|
-
expect(future_file_item).to be_kind_of(FutureFileItem)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'succeeds if not passed a local_identifier' do
|
20
|
-
future_file_item = described_class.new(name: 'yes', io: 'hello')
|
21
|
-
expect(future_file_item).to be_kind_of(FutureFileItem)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'generates a local_identifier' do
|
25
|
-
future_file_item = described_class.new(name: 'who', io: 'ami')
|
26
|
-
expect(future_file_item).to be_kind_of(FutureFileItem)
|
27
|
-
expect(future_file_item.local_identifier).to_not be nil
|
28
|
-
expect(future_file_item.local_identifier).to be_kind_of(String)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'creates params properly' do
|
32
|
-
future_file_item = described_class.new(name: 'yes', io: 'hello')
|
33
|
-
item_as_params = future_file_item.to_item_request_params
|
34
|
-
expect(item_as_params[:content_identifier]).to eq('file')
|
35
|
-
expect(item_as_params[:local_identifier]).to be_kind_of(String)
|
36
|
-
expect(item_as_params[:filename]).to eq('yes')
|
37
|
-
expect(item_as_params[:filesize]).to eq(5)
|
38
|
-
end
|
39
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe FutureWebItem do
|
4
|
-
it 'errors if not given all required arguments' do
|
5
|
-
expect {
|
6
|
-
described_class.new(url: 'https://www.wetransfer.com', local_identifier: '321235151')
|
7
|
-
}.to raise_error(/missing keyword: title/)
|
8
|
-
|
9
|
-
expect {
|
10
|
-
described_class.new(title: 'wetransfer.com')
|
11
|
-
}.to raise_error(/missing keyword: url/)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'succeeds if given all arguments' do
|
15
|
-
future_web_item = described_class.new(url: 'https://www.wetransfer.com', title: 'wetransfer.com', local_identifier: '321235151')
|
16
|
-
expect(future_web_item).to be_kind_of(FutureWebItem)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'succeeds if not passed a local_identifier' do
|
20
|
-
future_web_item = described_class.new(url: 'https://www.wetransfer.com', title: 'wetransfer.com')
|
21
|
-
expect(future_web_item).to be_kind_of(FutureWebItem)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'generates a local_identifier' do
|
25
|
-
future_web_item = described_class.new(url: 'https://www.wetransfer.com', title: 'wetransfer.com')
|
26
|
-
expect(future_web_item).to be_kind_of(FutureWebItem)
|
27
|
-
expect(future_web_item.local_identifier).to_not be nil
|
28
|
-
expect(future_web_item.local_identifier).to be_kind_of(String)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'creates params properly' do
|
32
|
-
future_web_item = described_class.new(url: 'https://www.wetransfer.com', title: 'wetransfer.com')
|
33
|
-
item_as_params = future_web_item.to_item_request_params
|
34
|
-
expect(item_as_params[:content_identifier]).to eq('web_content')
|
35
|
-
expect(item_as_params[:local_identifier]).to be_kind_of(String)
|
36
|
-
expect(item_as_params[:url]).to eq('https://www.wetransfer.com')
|
37
|
-
expect(item_as_params[:meta][:title]).to eq('wetransfer.com')
|
38
|
-
end
|
39
|
-
end
|