fileturn 0.0.3 → 0.1.0

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 +6 -14
  2. data/.gitignore +1 -0
  3. data/README.md +49 -44
  4. data/fileturn.gemspec +1 -0
  5. data/lib/fileturn/errors.rb +14 -0
  6. data/lib/fileturn/http_client.rb +10 -8
  7. data/lib/fileturn/resources/account.rb +11 -35
  8. data/lib/fileturn/resources/conversion.rb +80 -0
  9. data/lib/fileturn/resources/resource.rb +0 -5
  10. data/lib/fileturn/version.rb +1 -1
  11. data/lib/fileturn.rb +6 -7
  12. data/spec/fileturn_spec.rb +5 -5
  13. data/spec/fixtures/vcr_cassettes/account_info.yml +24 -63
  14. data/spec/fixtures/vcr_cassettes/conversion_all_not_authorized.yml +48 -0
  15. data/spec/fixtures/vcr_cassettes/conversion_not_authorized.yml +48 -0
  16. data/spec/fixtures/vcr_cassettes/conversion_not_found.yml +48 -0
  17. data/spec/fixtures/vcr_cassettes/conversion_process_created.yml +52 -0
  18. data/spec/fixtures/vcr_cassettes/conversion_process_no_params.yml +97 -0
  19. data/spec/fixtures/vcr_cassettes/conversion_process_success.yml +50 -0
  20. data/spec/fixtures/vcr_cassettes/conversion_success.yml +50 -0
  21. data/spec/fixtures/vcr_cassettes/conversions_all.yml +50 -0
  22. data/spec/fixtures/vcr_cassettes/conversions_all_second.yml +97 -0
  23. data/spec/fixtures/vcr_cassettes/reload_.yml +52 -0
  24. data/spec/fixtures/vcr_cassettes/reload_done.yml +50 -0
  25. data/spec/resources/account_spec.rb +8 -23
  26. data/spec/resources/conversion_spec.rb +213 -0
  27. data/spec/resources/upload_spec.rb +35 -35
  28. data/spec/spec_helper.rb +1 -1
  29. data/spec/stub_http_client.rb +1 -1
  30. metadata +58 -61
  31. data/lib/fileturn/exceptions.rb +0 -30
  32. data/lib/fileturn/resources/file.rb +0 -112
  33. data/lib/fileturn/resources/notification.rb +0 -16
  34. data/spec/fixtures/vcr_cassettes/file_all.yml +0 -103
  35. data/spec/fixtures/vcr_cassettes/file_all_notifications.yml +0 -103
  36. data/spec/fixtures/vcr_cassettes/file_convert_no_params.yml +0 -87
  37. data/spec/fixtures/vcr_cassettes/file_convert_success.yml +0 -89
  38. data/spec/fixtures/vcr_cassettes/file_doesnt_upload_since_too_big.yml +0 -46
  39. data/spec/fixtures/vcr_cassettes/file_failed_.yml +0 -176
  40. data/spec/fixtures/vcr_cassettes/file_notifications.yml +0 -89
  41. data/spec/fixtures/vcr_cassettes/file_queued_.yml +0 -176
  42. data/spec/fixtures/vcr_cassettes/file_reload.yml +0 -132
  43. data/spec/fixtures/vcr_cassettes/file_success.yml +0 -89
  44. data/spec/fixtures/vcr_cassettes/file_success_.yml +0 -176
  45. data/spec/fixtures/vcr_cassettes/file_time_taken.yml +0 -176
  46. data/spec/fixtures/vcr_cassettes/file_unauthorized.yml +0 -87
  47. data/spec/fixtures/vcr_cassettes/file_upload_doc_queued.yml +0 -782
  48. data/spec/fixtures/vcr_cassettes/file_upload_not_enough_credits.yml +0 -130
  49. data/spec/fixtures/vcr_cassettes/file_upload_queued.yml +0 -203
  50. data/spec/fixtures/vcr_cassettes/upload_all.yml +0 -89
  51. data/spec/fixtures/vcr_cassettes/upload_one.yml +0 -89
  52. data/spec/fixtures/vcr_cassettes/upload_refetch.yml +0 -132
  53. data/spec/resources/file_spec.rb +0 -184
@@ -1,184 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe FileTurn::File do
4
-
5
- def retrieve_successful_file
6
- @sfile ||= FileTurn::File.find(212)
7
- end
8
-
9
- def retrieve_failed_file
10
- @ffile ||= FileTurn::File.find(154)
11
- end
12
-
13
- def retrieve_queued_file
14
- @qfile ||= FileTurn::File.find(210)
15
- end
16
-
17
- def user_without_credits
18
- FileTurn.configure(:api_key => 'vGAMKzyN1pFGCNcCFsPpjjVVZtvim1zop3te2pQU')
19
- end
20
-
21
- describe '.find' do
22
- it 'raises exception if unauthorized' do
23
- VCR.use_cassette('file_unauthorized') do
24
- FileTurn.configure(:api_key => 'blah')
25
- expect { FileTurn::File.find(123) }.to raise_error(FileTurn::UnauthorizedException)
26
- end
27
- end
28
-
29
- it 'returns the file' do
30
- VCR.use_cassette('file_success') do
31
- file = FileTurn::File.find(212)
32
- file.id.should == 212
33
- file.url.should == "http://www.k12.wa.us/rti/implementation/pubdocs/SchoolBlueprint.doc"
34
- file.convert_to.should == 'pdf'
35
- file.created_at.should == DateTime.parse('2013-07-07T03:38:20Z')
36
- file.status == 'processed'
37
- file.download_url == "https://fileturn.s3.amazonaws.com/8_212.pdf?AWSAccessKeyId=AKIAIKXW3ZZ5WNURNYMA&Expires=1373259946&Signature=K60jm8kkSkXYjoEi8eVVr%2Bh1bBY%3D"
38
- end
39
- end
40
-
41
- it 'returns notifications for the file' do
42
- VCR.use_cassette('file_notifications') do
43
- file = FileTurn::File.find(212)
44
- file.notifications.count.should == 1
45
- file.notifications.first.id == 184
46
- end
47
- end
48
- end
49
-
50
- describe '.all' do
51
- it 'fetches all the files' do
52
- VCR.use_cassette('file_all') do
53
- obj = FileTurn::File.all
54
- obj.files.count.should == 20
55
- obj.current_page == 1
56
- obj.per_page == 20
57
- obj.total_pages == 3
58
- end
59
- end
60
-
61
- it 'fetches all the notifications' do
62
- VCR.use_cassette('file_all_notifications') do
63
- obj = FileTurn::File.all
64
- file = obj.files.first
65
- file.notifications.count.should == 1
66
- end
67
- end
68
- end
69
-
70
- describe '.convert' do
71
- it 'with no parameters' do
72
- VCR.use_cassette('file_convert_no_params') do
73
- expected = { 'url' => ["can't be blank"], 'convert_to' => ["can't be blank"] }
74
- response = FileTurn::File.convert({})
75
- response.errors.should == expected
76
- end
77
- end
78
-
79
- it 'properly converts a file response' do
80
- VCR.use_cassette('file_convert_success') do
81
- file = FileTurn::File.convert(:url => 'http://test.com', :convert_to => :pdf)
82
- file.queued?.should == true
83
- file.url.should == 'http://test.com'
84
- file.notifications.count.should == 0
85
- end
86
- end
87
- end
88
-
89
- describe 'upload' do
90
- it 'converts an uploaded file' do
91
- VCR.use_cassette('file_upload_queued') do
92
- file = FileTurn::File.convert(:file => File.open('README.md'), :convert_to => :pdf)
93
- file.queued?.should == true
94
- end
95
- end
96
-
97
- it 'converts and uploads a doc file' do
98
- VCR.use_cassette('file_upload_doc_queued') do
99
- file = FileTurn::File.convert(:file => File.open('./spec/data/testfile.docx'), :convert_to => :pdf)
100
- file.queued?.should == true
101
- end
102
- end
103
-
104
- it 'doesnt upload a file if there are not enough credits' do
105
- VCR.use_cassette('file_upload_not_enough_credits') do
106
- user_without_credits
107
- file = FileTurn::File.convert(:file => File.open('./spec/data/testfile.docx'), :convert_to => :pdf)
108
- file.queued?.should == nil
109
- file.errors.should == {'credits'=>['need more credits to convert files']}
110
-
111
- FileTurn::Upload.all.uploads.count.should == 0
112
- end
113
- end
114
-
115
- it 'doesnt upload since file is too big' do
116
- user_without_credits
117
- FileTurn::Account.should_receive(:max_file_size_in_bytes).and_return(0)
118
- file = FileTurn::File.convert(:file => File.open('./spec/data/testfile.docx'), :convert_to => :pdf)
119
- file.queued?.should == nil
120
- file.errors.should == {'file_size'=>['is too big']}
121
-
122
- VCR.use_cassette('file_doesnt_upload_since_too_big') do
123
- FileTurn::Upload.all.uploads.count.should == 0
124
- end
125
- end
126
- end
127
-
128
- it '#success?' do
129
- VCR.use_cassette('file_success?') do
130
- expected_results = {
131
- retrieve_successful_file => true,
132
- retrieve_failed_file => false,
133
- retrieve_queued_file => false
134
- }
135
-
136
- expected_results.each { |f, r| f.success?.should == r }
137
- end
138
- end
139
-
140
- it '#failed?' do
141
- VCR.use_cassette('file_failed?') do
142
- expected_results = {
143
- retrieve_successful_file => false,
144
- retrieve_failed_file => true,
145
- retrieve_queued_file => false
146
- }
147
-
148
- expected_results.each { |f, r| f.failed?.should == r }
149
- end
150
- end
151
-
152
- it '#queued?' do
153
- VCR.use_cassette('file_queued?') do
154
- expected_results = {
155
- retrieve_successful_file => false,
156
- retrieve_failed_file => false,
157
- retrieve_queued_file => true
158
- }
159
-
160
- expected_results.each { |f, r| f.queued?.should == r }
161
- end
162
- end
163
-
164
- it '#reload returns expected results' do
165
- VCR.use_cassette('file_reload') do
166
- retrieve_successful_file.should_receive(:parse_json_params)
167
- old_result = retrieve_successful_file.params
168
- retrieve_successful_file.reload.params.should == old_result
169
- end
170
- end
171
-
172
- it '#time_taken returns expected results' do
173
- VCR.use_cassette('file_time_taken') do
174
- expected_results = {
175
- retrieve_successful_file => 105.926075,
176
- retrieve_failed_file => nil,
177
- retrieve_queued_file => nil
178
- }
179
-
180
- expected_results.each { |f, r| f.time_taken.should == r }
181
- end
182
- end
183
-
184
- end