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,98 @@
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
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,44 @@
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,22 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FutureTransfer do
4
- it 'errors if not given all required arguments' do
5
- expect {
6
- described_class.new(name: 'nope', description: 'sorry')
7
- }.to raise_error(/missing keyword: items/)
4
+ let(:transfer) { described_class }
8
5
 
9
- expect {
10
- described_class.new(description: 'lol', items: [])
11
- }.to raise_error(/missing keyword: name/)
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
12
10
 
13
- expect {
14
- described_class.new(name: 'lol', items: [])
15
- }.to raise_error(/missing keyword: description/)
11
+ it 'throws a error when message is not given' do
12
+ expect {
13
+ transfer.new
14
+ }.to raise_error ArgumentError
15
+ end
16
16
  end
17
17
 
18
- it 'succeeds if given all required arguments' do
19
- future_transfer = described_class.new(name: 'frank', description: 'a decent bloke', items: [])
20
- expect(future_transfer).to be_kind_of(FutureTransfer)
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
21
38
  end
22
39
  end
@@ -0,0 +1,92 @@
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
@@ -0,0 +1,91 @@
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
@@ -0,0 +1,33 @@
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