cloudapp 1.1.0 → 2.0.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/CHANGELOG.md +3 -0
  2. data/Gemfile.lock +18 -34
  3. data/README.md +2 -1
  4. data/Rakefile +5 -1
  5. data/cloudapp.gemspec +50 -41
  6. data/lib/cloudapp/account.rb +111 -0
  7. data/lib/cloudapp/authorized_representation.rb +17 -0
  8. data/lib/cloudapp/collection_json/item.rb +20 -0
  9. data/lib/cloudapp/collection_json/representation.rb +74 -0
  10. data/lib/cloudapp/collection_json/template.rb +17 -0
  11. data/lib/cloudapp/collection_json/tint.rb +11 -0
  12. data/lib/cloudapp/collection_json.rb +3 -0
  13. data/lib/cloudapp/drop.rb +22 -6
  14. data/lib/cloudapp/drop_collection.rb +22 -0
  15. data/lib/cloudapp/service.rb +172 -0
  16. data/lib/cloudapp/token.rb +27 -0
  17. data/lib/cloudapp.rb +5 -1
  18. data/man/cloudapp.1 +202 -45
  19. data/man/cloudapp.1.html +114 -42
  20. data/man/cloudapp.1.ronn +125 -45
  21. data/spec/cassettes/create_bookmark.yml +255 -0
  22. data/spec/cassettes/create_bookmark_with_name.yml +266 -0
  23. data/spec/cassettes/create_bookmark_with_privacy.yml +277 -0
  24. data/spec/cassettes/delete_drop.yml +383 -0
  25. data/spec/cassettes/list_drops.yml +139 -0
  26. data/spec/cassettes/list_drops_with_bad_token.yml +57 -0
  27. data/spec/cassettes/list_drops_with_filter.yml +209 -0
  28. data/spec/cassettes/list_drops_with_href.yml +287 -0
  29. data/spec/cassettes/list_drops_with_href_and_filter.yml +287 -0
  30. data/spec/cassettes/list_drops_with_href_and_limit.yml +287 -0
  31. data/spec/cassettes/list_drops_with_limit.yml +211 -0
  32. data/spec/cassettes/list_drops_with_nil_href.yml +139 -0
  33. data/spec/cassettes/purge_drops.yml +1103 -0
  34. data/spec/cassettes/recover_drop.yml +628 -0
  35. data/spec/cassettes/rename_drop.yml +367 -0
  36. data/spec/cassettes/setup_drops.yml +968 -0
  37. data/spec/cassettes/token_for_account.yml +127 -0
  38. data/spec/cassettes/token_for_account_with_bad_credentials.yml +115 -0
  39. data/spec/cassettes/trash_drop.yml +478 -0
  40. data/spec/cassettes/update_drop_bookmark_url.yml +379 -0
  41. data/spec/cassettes/update_file.yml +573 -0
  42. data/spec/cassettes/upload_file.yml +470 -0
  43. data/spec/cassettes/upload_file_with_name.yml +484 -0
  44. data/spec/cassettes/upload_file_with_privacy.yml +495 -0
  45. data/spec/cassettes/view_drop.yml +73 -0
  46. data/spec/cloudapp/account_spec.rb +166 -0
  47. data/spec/cloudapp/authorized_representation_spec.rb +32 -0
  48. data/spec/cloudapp/collection_json/item_spec.rb +45 -0
  49. data/spec/cloudapp/collection_json/representation_spec.rb +118 -0
  50. data/spec/cloudapp/collection_json/template_spec.rb +53 -0
  51. data/spec/cloudapp/drop_collection_spec.rb +63 -0
  52. data/spec/cloudapp/drop_spec.rb +81 -51
  53. data/spec/cloudapp/service_spec.rb +357 -0
  54. data/spec/cloudapp/token_spec.rb +33 -0
  55. data/spec/integration_spec.rb +100 -0
  56. data/spec/support/stub_class_or_module.rb +6 -3
  57. data/spec/support/vcr.rb +21 -5
  58. metadata +84 -106
  59. data/bin/cloudapp +0 -184
  60. data/lib/cloudapp/config.rb +0 -39
  61. data/lib/cloudapp/drop_content.rb +0 -34
  62. data/lib/cloudapp/drop_presenter.rb +0 -80
  63. data/lib/cloudapp/drop_service.rb +0 -255
  64. data/lib/cloudapp/identity.rb +0 -14
  65. data/spec/cassettes/DropContent/download.yml +0 -116
  66. data/spec/cassettes/DropService/create_bookmark.yml +0 -105
  67. data/spec/cassettes/DropService/create_bookmark_with_bad_credentials.yml +0 -39
  68. data/spec/cassettes/DropService/create_bookmark_with_name.yml +0 -105
  69. data/spec/cassettes/DropService/create_private_bookmark.yml +0 -105
  70. data/spec/cassettes/DropService/create_public_bookmark.yml +0 -105
  71. data/spec/cassettes/DropService/drop.yml +0 -81
  72. data/spec/cassettes/DropService/list_drops.yml +0 -135
  73. data/spec/cassettes/DropService/list_drops_with_bad_credentials.yml +0 -39
  74. data/spec/cassettes/DropService/list_drops_with_limit.yml +0 -117
  75. data/spec/cassettes/DropService/list_trash.yml +0 -111
  76. data/spec/cassettes/DropService/list_trash_with_bad_credentials.yml +0 -39
  77. data/spec/cassettes/DropService/retrieve_token.yml +0 -42
  78. data/spec/cassettes/DropService/retrieve_token_with_bad_credentials.yml +0 -43
  79. data/spec/cassettes/DropService/upload_file.yml +0 -291
  80. data/spec/cassettes/DropService/upload_public_file.yml +0 -293
  81. data/spec/cloudapp/config_spec.rb +0 -59
  82. data/spec/cloudapp/drop_content_spec.rb +0 -21
  83. data/spec/cloudapp/drop_presenter_spec.rb +0 -120
  84. data/spec/cloudapp/drop_service_spec.rb +0 -400
  85. data/spec/cloudapp/identity_spec.rb +0 -27
  86. data/spec/support/fakefs_rspec.rb +0 -5
  87. data/spec/support/vcr_rspec.rb +0 -9
@@ -1,400 +0,0 @@
1
- require 'helper'
2
- require 'support/fakefs_rspec'
3
- require 'support/vcr_rspec'
4
-
5
- require 'cloudapp/drop_service'
6
-
7
- describe CloudApp::DropService do
8
- let(:token) { '8762f6679f8d001016b2' }
9
-
10
- describe '.using_token' do
11
- subject { CloudApp::DropService.using_token(token) }
12
-
13
- it 'returns a service authenticated with given token' do
14
- VCR.use_cassette('DropService/list_drops') {
15
- subject.drops
16
- }
17
- end
18
- end
19
-
20
- describe '.retrieve_token' do
21
- subject {
22
- VCR.use_cassette('DropService/retrieve_token') {
23
- CloudApp::DropService.retrieve_token 'arthur@dent.com', 'towel'
24
- }
25
- }
26
-
27
- it 'returns the token from the given account' do
28
- subject.should eql(token)
29
- end
30
- end
31
-
32
- describe '#drop' do
33
- let(:service) { CloudApp::DropService.new }
34
-
35
- describe 'retrieving a drop' do
36
- let(:url) { 'http://cl.ly/C23W' }
37
- subject {
38
- VCR.use_cassette('DropService/drop',
39
- match_requests_on: [:method, :uri, :body, :headers]) {
40
- service.drop url
41
- }
42
- }
43
-
44
- it 'returns the drop' do
45
- subject.should be_a(CloudApp::Drop)
46
- end
47
-
48
- it 'parses the response' do
49
- subject.id.should == 12142483
50
- end
51
- end
52
-
53
- describe 'retrieving a nonexistent drop' do
54
- let(:url) { 'http://cl.ly/nonexistent' }
55
- subject {
56
- VCR.use_cassette('DropService/drop',
57
- match_requests_on: [:method, :uri, :body, :headers]) {
58
- service.drop url
59
- }
60
- }
61
-
62
- it 'returns nil' do
63
- subject.should be_nil
64
- end
65
- end
66
- end
67
-
68
- describe '#download_drop', :fakefs do
69
- let(:service) { CloudApp::DropService.new }
70
- let(:url) { 'http://cl.ly/C23W' }
71
- let(:options) { {} }
72
- let(:content) { 'content' }
73
- let(:content_url) { 'http://cl.ly/C23W/drop_presenter.rb' }
74
- let(:drop) { stub :drop, content: content,
75
- content_url: content_url,
76
- has_content?: true }
77
-
78
- before do
79
- CloudApp::DropContent.stub download: content
80
- service.stub drop: drop
81
- end
82
-
83
- it 'fetches the drop' do
84
- CloudApp::DropContent.should_receive(:download).with(drop)
85
- service.download_drop url, options
86
- end
87
-
88
- it 'returns the content' do
89
- service.download_drop(url, options).should eq(content)
90
- end
91
-
92
- it 'saves the file to the current directory using the remote filename' do
93
- service.download_drop url, options
94
- downloaded = File.open('drop_presenter.rb') {|f| f.read }
95
-
96
- downloaded.should eq(content)
97
- end
98
-
99
- describe 'to a path' do
100
- let(:options) {{ to: '/tmp/file.txt' }}
101
-
102
- it 'saves the file to the given path' do
103
- service.download_drop url, options
104
- File.exist?(options[:to]).should be_true
105
- end
106
- end
107
-
108
- describe 'to an existing file' do
109
- let(:options) {{ to: '/tmp/file.txt' }}
110
- before do
111
- Dir.mkdir '/tmp'
112
- File.open(options[:to], 'w', 0600) {|file| file << 'existing' }
113
- end
114
-
115
- it 'overwrites the file' do
116
- service.download_drop url, options
117
- downloaded = File.open(options[:to]) {|f| f.read }
118
-
119
- downloaded.should eq(content)
120
- end
121
- end
122
-
123
- describe 'an unexpanded path' do
124
- let(:options) {{ to: '~/file.txt' }}
125
- before do
126
- FileUtils.mkdir_p File.expand_path('~')
127
- end
128
-
129
- it 'saves the file to the expanded directory' do
130
- service.download_drop url, options
131
- saved_path = File.expand_path(options[:to])
132
-
133
- File.exist?(saved_path).should be_true
134
- end
135
- end
136
-
137
- describe 'to an existing directory' do
138
- let(:options) {{ to: '/tmp' }}
139
- before do
140
- Dir.mkdir '/tmp'
141
- end
142
-
143
- it 'raises an exception' do
144
- -> { service.download_drop url, options }.
145
- should raise_exception(Errno::EISDIR)
146
- end
147
- end
148
-
149
- describe 'a bookmark' do
150
- let(:drop) { stub :drop, has_content?: false }
151
-
152
- it 'raises an exception' do
153
- -> { service.download_drop url, options }.
154
- should raise_exception(CloudApp::DropService::NO_CONTENT)
155
- end
156
-
157
- it "doesn't save a file" do
158
- FakeFS::FileSystem.files.should be_empty
159
- end
160
- end
161
-
162
- describe 'a file with URL-encoded name' do
163
- let(:content_url) { 'http://cl.ly/C23W/screen%20shot.png' }
164
-
165
- it 'decodes the filename' do
166
- service.download_drop url, options
167
-
168
- File.exist?('screen shot.png').should be_true
169
- end
170
- end
171
-
172
- describe 'a nonexistent drop' do
173
- let(:drop) { nil }
174
-
175
- it 'raises an exception' do
176
- -> { service.download_drop url, options }.
177
- should raise_exception(CloudApp::DropService::NO_CONTENT)
178
- end
179
-
180
- it "doesn't save a file" do
181
- FakeFS::FileSystem.files.should be_empty
182
- end
183
- end
184
- end
185
-
186
- describe '#drops' do
187
- let(:service) { CloudApp::DropService.using_token token }
188
-
189
- describe 'listing drops' do
190
- subject { VCR.use_cassette('DropService/list_drops') { service.drops }}
191
-
192
- it 'has 20 drops' do
193
- subject.should have(20).items
194
- end
195
-
196
- it 'creates Drops' do
197
- subject.each {|drop| drop.should be_a(CloudApp::Drop) }
198
- end
199
- end
200
-
201
- describe 'listing trash' do
202
- subject { VCR.use_cassette('DropService/list_trash') { service.trash }}
203
-
204
- it 'has 2 drops' do
205
- subject.should have(2).items
206
- end
207
-
208
- it 'creates Drops' do
209
- subject.each {|drop| drop.should be_a(CloudApp::Drop) }
210
- end
211
- end
212
-
213
- describe 'limiting drops list' do
214
- let(:limit) { 5 }
215
-
216
- subject {
217
- VCR.use_cassette('DropService/list_drops_with_limit') {
218
- service.drops limit
219
- }
220
- }
221
-
222
- it 'has the given number of drops' do
223
- subject.should have(limit).items
224
- end
225
- end
226
- end
227
-
228
- describe '#create' do
229
- let(:service) { CloudApp::DropService.using_token token }
230
- let(:url) { 'http://getcloudapp.com' }
231
- let(:name) { 'CloudApp' }
232
-
233
- describe 'creating a bookmark' do
234
- subject {
235
- VCR.use_cassette('DropService/create_bookmark') {
236
- service.create url: url
237
- }
238
- }
239
-
240
- it 'is a Drop' do
241
- subject.should be_a(CloudApp::Drop)
242
- end
243
-
244
- it 'has the given url' do
245
- subject.redirect_url.should eq(url)
246
- end
247
-
248
- it 'has no name' do
249
- subject.name.should_not be
250
- end
251
- end
252
-
253
- describe 'creating a bookmark with a name' do
254
- subject {
255
- VCR.use_cassette('DropService/create_bookmark_with_name') {
256
- service.create url: url, name: name
257
- }
258
- }
259
-
260
- it 'has the given url' do
261
- subject.redirect_url.should eq(url)
262
- end
263
-
264
- it 'has the given name' do
265
- subject.name.should eq(name)
266
- end
267
- end
268
-
269
- describe 'creating a public bookmark' do
270
- subject {
271
- VCR.use_cassette('DropService/create_public_bookmark') {
272
- service.create url: url, name: name, private: false
273
- }
274
- }
275
-
276
- it 'is public' do
277
- subject.should be_public
278
- end
279
- end
280
-
281
- describe 'creating a private bookmark' do
282
- subject {
283
- VCR.use_cassette('DropService/create_private_bookmark') {
284
- service.create url: url, name: name, private: true
285
- }
286
- }
287
-
288
- it 'is private' do
289
- subject.should be_private
290
- end
291
- end
292
-
293
- describe 'uploading a file' do
294
- let(:path) do
295
- Pathname('../../support/files/favicon.ico').expand_path(__FILE__)
296
- end
297
-
298
- subject {
299
- VCR.use_cassette('DropService/upload_file') {
300
- service.create path: path
301
- }
302
- }
303
-
304
- it 'is a Drop' do
305
- subject.should be_a(CloudApp::Drop)
306
- end
307
-
308
- it 'has a remote url' do
309
- subject.remote_url.
310
- should eq('http://f.cl.ly/items/0P3c3c1V3v1H3I3p3x0k/favicon.ico')
311
- end
312
-
313
- it 'has the name of the file' do
314
- subject.name.should eq('favicon.ico')
315
- end
316
- end
317
-
318
- describe 'uploading a public file' do
319
- let(:path) do
320
- Pathname('../../support/files/favicon.ico').expand_path(__FILE__)
321
- end
322
-
323
- subject {
324
- VCR.use_cassette('DropService/upload_public_file') {
325
- service.create path: path, private: false
326
- }
327
- }
328
-
329
- it 'is public' do
330
- subject.should be_public
331
- end
332
- end
333
- end
334
-
335
- describe '#destroy' do
336
- it 'trashes a drop'
337
- it 'destroys a trashed drop'
338
- end
339
-
340
- describe '#restore' do
341
- it 'restores a drop from the trash'
342
- end
343
-
344
- describe 'with bad authentication' do
345
- let(:token) { 'bad-token' }
346
- let(:service) { CloudApp::DropService.using_token token }
347
-
348
- describe '.retrieve_token' do
349
- subject {
350
- VCR.use_cassette('DropService/retrieve_token_with_bad_credentials') {
351
- CloudApp::DropService.retrieve_token 'ford@prefect.com', 'earthling'
352
- }
353
- }
354
-
355
- it 'raises an unauthorized error' do
356
- lambda { subject }.
357
- should raise_error(CloudApp::DropService::UNAUTHORIZED)
358
- end
359
- end
360
-
361
- describe '#drops' do
362
- subject {
363
- VCR.use_cassette('DropService/list_drops_with_bad_credentials') {
364
- service.drops
365
- }
366
- }
367
-
368
- it 'raises an unauthorized error' do
369
- lambda { subject }.
370
- should raise_error(CloudApp::DropService::UNAUTHORIZED)
371
- end
372
- end
373
-
374
- describe '#trash' do
375
- subject {
376
- VCR.use_cassette('DropService/list_trash_with_bad_credentials') {
377
- service.trash
378
- }
379
- }
380
-
381
- it 'raises an unauthorized error' do
382
- lambda { subject }.
383
- should raise_error(CloudApp::DropService::UNAUTHORIZED)
384
- end
385
- end
386
-
387
- describe '#create' do
388
- subject {
389
- VCR.use_cassette('DropService/create_bookmark_with_bad_credentials') {
390
- service.create url: 'http://getcloudapp.com'
391
- }
392
- }
393
-
394
- it 'raises an unauthorized error' do
395
- lambda { subject }.
396
- should raise_error(CloudApp::DropService::UNAUTHORIZED)
397
- end
398
- end
399
- end
400
- end
@@ -1,27 +0,0 @@
1
- require 'helper'
2
-
3
- require 'cloudapp/identity'
4
-
5
- describe CloudApp::Identity do
6
- let(:email) { 'arthur@dent.com' }
7
- let(:password) { 'towel' }
8
-
9
- describe '.initialize' do
10
- it 'accepts an email and password' do
11
- identity = CloudApp::Identity.new email, password
12
-
13
- identity.email .should eq(email)
14
- identity.password.should eq(password)
15
- end
16
- end
17
-
18
- describe '.from_config' do
19
- let(:config) {{ email: email, password: password }}
20
- subject { CloudApp::Identity.from_config config }
21
-
22
- it 'returns an identity' do
23
- subject.email .should eq(email)
24
- subject.password.should eq(password)
25
- end
26
- end
27
- end
@@ -1,5 +0,0 @@
1
- require 'fakefs/spec_helpers'
2
-
3
- RSpec.configure do |c|
4
- c.include FakeFS::SpecHelpers, fakefs: true
5
- end
@@ -1,9 +0,0 @@
1
- require 'support/vcr'
2
-
3
- VCR.configure do |c|
4
- c.configure_rspec_metadata!
5
- end
6
-
7
- RSpec.configure do |c|
8
- c.treat_symbols_as_metadata_keys_with_true_values = true
9
- end