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.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/.rspec +1 -2
  3. data/.rubocop.yml +1 -1
  4. data/.travis.yml +3 -2
  5. data/Guardfile +11 -0
  6. data/README.md +81 -38
  7. data/V2_README.md +53 -0
  8. data/examples/create_collection.rb +13 -0
  9. data/examples/create_transfer.rb +1 -1
  10. data/lib/we_transfer_client.rb +86 -120
  11. data/lib/we_transfer_client/board_builder.rb +33 -0
  12. data/lib/we_transfer_client/boards.rb +74 -0
  13. data/lib/we_transfer_client/future_board.rb +32 -0
  14. data/lib/we_transfer_client/future_file.rb +28 -0
  15. data/lib/we_transfer_client/future_link.rb +28 -0
  16. data/lib/we_transfer_client/future_transfer.rb +11 -5
  17. data/lib/we_transfer_client/remote_board.rb +47 -0
  18. data/lib/we_transfer_client/remote_file.rb +55 -0
  19. data/lib/we_transfer_client/remote_link.rb +9 -0
  20. data/lib/we_transfer_client/remote_transfer.rb +24 -1
  21. data/lib/we_transfer_client/transfer_builder.rb +3 -10
  22. data/lib/we_transfer_client/transfers.rb +73 -0
  23. data/lib/we_transfer_client/version.rb +2 -2
  24. data/spec/board_integration_spec.rb +68 -0
  25. data/spec/features/add_items_to_board_spec.rb +55 -0
  26. data/spec/features/create_board_spec.rb +46 -0
  27. data/spec/features/get_board_spec.rb +34 -0
  28. data/spec/features/transfer_spec.rb +41 -0
  29. data/spec/fixtures/Japan-01.jpg +0 -0
  30. data/spec/fixtures/Japan-02.jpg +0 -0
  31. data/spec/spec_helper.rb +20 -0
  32. data/spec/transfer_integration_spec.rb +54 -0
  33. data/spec/we_transfer_client/board_builder_spec.rb +66 -0
  34. data/spec/we_transfer_client/boards_spec.rb +56 -0
  35. data/spec/we_transfer_client/future_board_spec.rb +98 -0
  36. data/spec/we_transfer_client/future_file_spec.rb +48 -0
  37. data/spec/we_transfer_client/future_link_spec.rb +44 -0
  38. data/spec/we_transfer_client/future_transfer_spec.rb +30 -13
  39. data/spec/we_transfer_client/remote_board_spec.rb +92 -0
  40. data/spec/we_transfer_client/remote_file_spec.rb +91 -0
  41. data/spec/we_transfer_client/remote_link_spec.rb +33 -0
  42. data/spec/we_transfer_client/remote_transfer_spec.rb +101 -0
  43. data/spec/we_transfer_client/transfer_builder_spec.rb +48 -51
  44. data/spec/we_transfer_client/transfers_spec.rb +45 -0
  45. data/spec/we_transfer_client_spec.rb +51 -3
  46. data/wetransfer.gemspec +11 -5
  47. metadata +67 -27
  48. data/lib/we_transfer_client/future_file_item.rb +0 -16
  49. data/lib/we_transfer_client/future_web_item.rb +0 -18
  50. data/lib/we_transfer_client/remote_item.rb +0 -2
  51. data/spec/integration_spec.rb +0 -160
  52. data/spec/we_transfer_client/future_file_item_spec.rb +0 -39
  53. data/spec/we_transfer_client/future_web_item_spec.rb +0 -39
@@ -0,0 +1,101 @@
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,61 +1,58 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe TransferBuilder do
4
- it 'raises if given an item with a size of 0' do
5
- broken = StringIO.new('')
6
- expect {
7
- described_class.new.ensure_io_compliant!(broken)
8
- }.to raise_error(/The IO object given to add_file has a size of 0/)
9
- end
10
-
11
- it 'raises if IO raises an error' do
12
- broken = []
13
-
14
- expect {
15
- described_class.new.ensure_io_compliant!(broken)
16
- }.to raise_error(TransferBuilder::TransferIOError)
17
- end
18
-
19
- it 'adds a file' do
20
- transfer_builder = described_class.new
21
- transfer_builder.add_file_at(path: __FILE__)
22
- expect(transfer_builder.items.count).to eq(1)
4
+ let(:transfer) { described_class.new }
23
5
 
24
- item = transfer_builder.items.first
25
- expect(item.name).to eq('transfer_builder_spec.rb')
26
- expect(item.io).to be_kind_of(File)
27
- expect(item.local_identifier).to be_kind_of(String)
6
+ describe '#initialze' do
7
+ it 'initializes with an empty files array' do
8
+ expect(transfer.files.empty?).to be(true)
9
+ end
28
10
  end
29
11
 
30
- it 'should add a url' do
31
- transfer_builder = described_class.new
32
- transfer_builder.add_web_url(url: 'https://www.wetransfer.com/')
33
- expect(transfer_builder.items.count).to eq(1)
34
-
35
- item = transfer_builder.items.first
36
- expect(item.url).to eq('https://www.wetransfer.com/')
37
- expect(item.local_identifier).to be_kind_of(String)
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
38
35
  end
39
36
 
40
- it 'should user url for the title when none is given' do
41
- transfer_builder = described_class.new
42
- transfer_builder.add_web_url(url: 'https://www.wetransfer.com/')
43
- expect(transfer_builder.items.count).to eq(1)
44
-
45
- item = transfer_builder.items.first
46
-
47
- expect(item.title).to eq('https://www.wetransfer.com/')
48
- expect(item.local_identifier).to be_kind_of(String)
49
- end
50
-
51
- it 'should pass title as webcontent title' do
52
- transfer_builder = described_class.new
53
- transfer_builder.add_web_url(url: 'https://www.wetransfer.com/', title: 'awesome website for file transfering')
54
- expect(transfer_builder.items.count).to eq(1)
55
-
56
- item = transfer_builder.items.first
57
- expect(item.url).to eq('https://www.wetransfer.com/')
58
- expect(item.title).to eq('awesome website for file transfering')
59
- expect(item.local_identifier).to be_kind_of(String)
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
60
57
  end
61
58
  end
@@ -0,0 +1,45 @@
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,9 +1,57 @@
1
1
  require 'spec_helper'
2
2
 
3
- require_relative '../lib/we_transfer_client.rb'
3
+ describe WeTransfer::Client do
4
+ subject { described_class.new(params) }
5
+ let(:params) { { api_key: ENV.fetch('WT_API_KEY') } }
4
6
 
5
- describe WeTransferClient do
6
7
  it 'exposes VERSION' do
7
- expect(WeTransferClient::VERSION).to be_kind_of(String)
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
8
56
  end
9
57
  end
@@ -5,9 +5,9 @@ require 'we_transfer_client/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'wetransfer'
8
- spec.version = WeTransferClient::VERSION
9
- spec.authors = ['Noah Berman', 'David Bosveld']
10
- spec.email = ['noah@wetransfer.com', 'david@wetransfer.com', 'developers@wetransfer.com']
8
+ spec.version = WeTransfer::VERSION
9
+ spec.authors = ['Noah Berman', 'David Bosveld', 'Arno Fleming']
10
+ spec.email = ['noah@wetransfer.com', 'david@wetransfer.com', 'developers@wetransfer.com', 'arno@wetransfer.com']
11
11
 
12
12
  spec.summary = "A Ruby SDK for WeTransfer's Public API"
13
13
  spec.description = "Ruby bindings for using WeTransfer's Public API."
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ['lib']
30
30
 
31
31
  spec.add_dependency 'faraday', '~> 0.12'
32
- spec.add_dependency 'ks', '~> 0.0.1'
33
32
 
34
33
  spec.add_development_dependency 'dotenv', '~> 2.2'
35
34
  spec.add_development_dependency 'bundler', '~> 1.16'
@@ -37,5 +36,12 @@ Gem::Specification.new do |spec|
37
36
  spec.add_development_dependency 'rake', '~> 10.0'
38
37
  spec.add_development_dependency 'rspec', '~> 3.0'
39
38
  spec.add_development_dependency 'simplecov', '~> 0.15'
40
- spec.add_development_dependency 'wetransfer_style', '0.5.0'
39
+ spec.add_development_dependency 'wetransfer_style', '0.6.0'
40
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
41
+ spec.add_development_dependency 'guard-rubocop', '~> 1.3'
41
42
  end
43
+
44
+ # spec.add_development_dependency 'guard-flay'
45
+ # spec.add_development_dependency 'guard-flog'
46
+ # spec.add_development_dependency 'flay', '~> 2.4'
47
+ # spec.add_development_dependency 'flog'
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wetransfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.9.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman
8
8
  - David Bosveld
9
+ - Arno Fleming
9
10
  autorequire:
10
11
  bindir: exe
11
12
  cert_chain: []
12
- date: 2018-07-31 00:00:00.000000000 Z
13
+ date: 2018-10-03 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: faraday
@@ -25,20 +26,6 @@ dependencies:
25
26
  - - "~>"
26
27
  - !ruby/object:Gem::Version
27
28
  version: '0.12'
28
- - !ruby/object:Gem::Dependency
29
- name: ks
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: 0.0.1
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: 0.0.1
42
29
  - !ruby/object:Gem::Dependency
43
30
  name: dotenv
44
31
  requirement: !ruby/object:Gem::Requirement
@@ -129,19 +116,48 @@ dependencies:
129
116
  requirements:
130
117
  - - '='
131
118
  - !ruby/object:Gem::Version
132
- version: 0.5.0
119
+ version: 0.6.0
133
120
  type: :development
134
121
  prerelease: false
135
122
  version_requirements: !ruby/object:Gem::Requirement
136
123
  requirements:
137
124
  - - '='
138
125
  - !ruby/object:Gem::Version
139
- version: 0.5.0
126
+ version: 0.6.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: guard-rspec
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '4.7'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - "~>"
139
+ - !ruby/object:Gem::Version
140
+ version: '4.7'
141
+ - !ruby/object:Gem::Dependency
142
+ name: guard-rubocop
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '1.3'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - "~>"
153
+ - !ruby/object:Gem::Version
154
+ version: '1.3'
140
155
  description: Ruby bindings for using WeTransfer's Public API.
141
156
  email:
142
157
  - noah@wetransfer.com
143
158
  - david@wetransfer.com
144
159
  - developers@wetransfer.com
160
+ - arno@wetransfer.com
145
161
  executables: []
146
162
  extensions: []
147
163
  extra_rdoc_files: []
@@ -157,26 +173,50 @@ files:
157
173
  - ".rubocop.yml"
158
174
  - ".travis.yml"
159
175
  - Gemfile
176
+ - Guardfile
160
177
  - LICENSE.txt
161
178
  - README.md
162
179
  - Rakefile
180
+ - V2_README.md
163
181
  - bin/console
164
182
  - bin/setup
183
+ - examples/create_collection.rb
165
184
  - examples/create_transfer.rb
166
185
  - lib/we_transfer_client.rb
167
- - lib/we_transfer_client/future_file_item.rb
186
+ - lib/we_transfer_client/board_builder.rb
187
+ - lib/we_transfer_client/boards.rb
188
+ - lib/we_transfer_client/future_board.rb
189
+ - lib/we_transfer_client/future_file.rb
190
+ - lib/we_transfer_client/future_link.rb
168
191
  - lib/we_transfer_client/future_transfer.rb
169
- - lib/we_transfer_client/future_web_item.rb
170
- - lib/we_transfer_client/remote_item.rb
192
+ - lib/we_transfer_client/remote_board.rb
193
+ - lib/we_transfer_client/remote_file.rb
194
+ - lib/we_transfer_client/remote_link.rb
171
195
  - lib/we_transfer_client/remote_transfer.rb
172
196
  - lib/we_transfer_client/transfer_builder.rb
197
+ - lib/we_transfer_client/transfers.rb
173
198
  - lib/we_transfer_client/version.rb
174
- - spec/integration_spec.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
175
206
  - spec/spec_helper.rb
176
- - spec/we_transfer_client/future_file_item_spec.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
177
213
  - spec/we_transfer_client/future_transfer_spec.rb
178
- - spec/we_transfer_client/future_web_item_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
179
218
  - spec/we_transfer_client/transfer_builder_spec.rb
219
+ - spec/we_transfer_client/transfers_spec.rb
180
220
  - spec/we_transfer_client_spec.rb
181
221
  - wetransfer.gemspec
182
222
  homepage: https://developers.wetransfer.com
@@ -195,12 +235,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
235
  version: '0'
196
236
  required_rubygems_version: !ruby/object:Gem::Requirement
197
237
  requirements:
198
- - - ">="
238
+ - - ">"
199
239
  - !ruby/object:Gem::Version
200
- version: '0'
240
+ version: 1.3.1
201
241
  requirements: []
202
242
  rubyforge_project:
203
- rubygems_version: 2.6.14
243
+ rubygems_version: 2.7.7
204
244
  signing_key:
205
245
  specification_version: 4
206
246
  summary: A Ruby SDK for WeTransfer's Public API