fileturn 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +107 -0
  6. data/Rakefile +1 -0
  7. data/fileturn.gemspec +27 -0
  8. data/lib/fileturn/exceptions.rb +30 -0
  9. data/lib/fileturn/http_client.rb +49 -0
  10. data/lib/fileturn/resources/account.rb +46 -0
  11. data/lib/fileturn/resources/file.rb +112 -0
  12. data/lib/fileturn/resources/notification.rb +16 -0
  13. data/lib/fileturn/resources/resource.rb +17 -0
  14. data/lib/fileturn/resources/upload.rb +77 -0
  15. data/lib/fileturn/version.rb +3 -0
  16. data/lib/fileturn.rb +19 -0
  17. data/spec/.DS_Store +0 -0
  18. data/spec/data/.DS_Store +0 -0
  19. data/spec/data/testfile.docx +0 -0
  20. data/spec/fileturn_spec.rb +16 -0
  21. data/spec/fixtures/vcr_cassettes/account_info.yml +47 -0
  22. data/spec/fixtures/vcr_cassettes/file_all.yml +60 -0
  23. data/spec/fixtures/vcr_cassettes/file_all_notifications.yml +60 -0
  24. data/spec/fixtures/vcr_cassettes/file_convert_no_params.yml +44 -0
  25. data/spec/fixtures/vcr_cassettes/file_convert_success.yml +46 -0
  26. data/spec/fixtures/vcr_cassettes/file_doesnt_upload_since_too_big.yml +46 -0
  27. data/spec/fixtures/vcr_cassettes/file_failed_.yml +133 -0
  28. data/spec/fixtures/vcr_cassettes/file_notifications.yml +46 -0
  29. data/spec/fixtures/vcr_cassettes/file_queued_.yml +133 -0
  30. data/spec/fixtures/vcr_cassettes/file_reload.yml +89 -0
  31. data/spec/fixtures/vcr_cassettes/file_success.yml +46 -0
  32. data/spec/fixtures/vcr_cassettes/file_success_.yml +133 -0
  33. data/spec/fixtures/vcr_cassettes/file_time_taken.yml +133 -0
  34. data/spec/fixtures/vcr_cassettes/file_unauthorized.yml +44 -0
  35. data/spec/fixtures/vcr_cassettes/file_upload_doc_queued.yml +739 -0
  36. data/spec/fixtures/vcr_cassettes/file_upload_not_enough_credits.yml +87 -0
  37. data/spec/fixtures/vcr_cassettes/file_upload_queued.yml +160 -0
  38. data/spec/fixtures/vcr_cassettes/upload_all.yml +46 -0
  39. data/spec/fixtures/vcr_cassettes/upload_one.yml +46 -0
  40. data/spec/fixtures/vcr_cassettes/upload_refetch.yml +89 -0
  41. data/spec/resources/account_spec.rb +31 -0
  42. data/spec/resources/file_spec.rb +184 -0
  43. data/spec/resources/upload_spec.rb +41 -0
  44. data/spec/spec_helper.rb +19 -0
  45. metadata +198 -0
@@ -0,0 +1,87 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/api/files/upload.json?content_length=26757&content_type=docx&token=vGAMKzyN1pFGCNcCFsPpjjVVZtvim1zop3te2pQU
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.7
12
+ Content-Length:
13
+ - '0'
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 422
19
+ message: ''
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Cache-Control:
26
+ - no-cache
27
+ X-Request-Id:
28
+ - 621b3af48645fb1073e55a95b1b0c212
29
+ X-Runtime:
30
+ - '0.009850'
31
+ Server:
32
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
33
+ Date:
34
+ - Sun, 07 Jul 2013 22:46:59 GMT
35
+ Content-Length:
36
+ - '61'
37
+ Connection:
38
+ - Keep-Alive
39
+ body:
40
+ encoding: US-ASCII
41
+ string: ! '{"errors":{"credits":["need more credits to convert files"]}}'
42
+ http_version:
43
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
44
+ - request:
45
+ method: get
46
+ uri: http://localhost:3000/api/uploads.json?token=vGAMKzyN1pFGCNcCFsPpjjVVZtvim1zop3te2pQU
47
+ body:
48
+ encoding: US-ASCII
49
+ string: ''
50
+ headers:
51
+ User-Agent:
52
+ - Faraday v0.8.7
53
+ Accept-Encoding:
54
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
55
+ Accept:
56
+ - ! '*/*'
57
+ response:
58
+ status:
59
+ code: 200
60
+ message: ! 'OK '
61
+ headers:
62
+ Content-Type:
63
+ - application/json; charset=utf-8
64
+ X-Ua-Compatible:
65
+ - IE=Edge
66
+ Etag:
67
+ - ! '"b43687c602a82010e4d4591ff6b7404f"'
68
+ Cache-Control:
69
+ - max-age=0, private, must-revalidate
70
+ X-Request-Id:
71
+ - 3113fe862ccf4f4e4a458847144f6b04
72
+ X-Runtime:
73
+ - '0.016860'
74
+ Server:
75
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
76
+ Date:
77
+ - Sun, 07 Jul 2013 22:46:59 GMT
78
+ Content-Length:
79
+ - '79'
80
+ Connection:
81
+ - Keep-Alive
82
+ body:
83
+ encoding: US-ASCII
84
+ string: ! '{"uploads":[],"total_uploads":0,"current_page":1,"per_page":20,"total_pages":0}'
85
+ http_version:
86
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
87
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,160 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/api/files/upload.json?content_length=2314&content_type=md&token=67sFfjudMpXxJeioQcPSppYkoVdQD1oetqPWzMAh
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.7
12
+ Content-Length:
13
+ - '0'
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: ! 'Created '
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Etag:
26
+ - ! '"505619e4048125e38aad9ea7ed308f23"'
27
+ Cache-Control:
28
+ - max-age=0, private, must-revalidate
29
+ X-Request-Id:
30
+ - e773b8acc801ceebb9bc9288029c57cb
31
+ X-Runtime:
32
+ - '0.035095'
33
+ Server:
34
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
35
+ Date:
36
+ - Sun, 07 Jul 2013 22:46:58 GMT
37
+ Content-Length:
38
+ - '352'
39
+ Connection:
40
+ - Keep-Alive
41
+ body:
42
+ encoding: US-ASCII
43
+ string: ! '{"id":295,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QyMzoxNjo1OFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI5NSJ9LFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLDIzMTQsMjMxNF1dfQ==","signature":"Rndy0OKdyVkqKU32ZvaJQ0HxWG0=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_295","url":"https://fileturn.s3.amazonaws.com"}'
44
+ http_version:
45
+ recorded_at: Sun, 07 Jul 2013 22:46:58 GMT
46
+ - request:
47
+ method: post
48
+ uri: https://fileturn.s3.amazonaws.com/
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ! "-------------RubyMultipartPost\r\nContent-Disposition: form-data;
52
+ name=\"policy\"\r\n\r\neyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QyMzoxNjo1OFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI5NSJ9LFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLDIzMTQsMjMxNF1dfQ==\r\n-------------RubyMultipartPost\r\nContent-Disposition:
53
+ form-data; name=\"signature\"\r\n\r\nRndy0OKdyVkqKU32ZvaJQ0HxWG0=\r\n-------------RubyMultipartPost\r\nContent-Disposition:
54
+ form-data; name=\"AWSAccessKeyId\"\r\n\r\nAKIAIKXW3ZZ5WNURNYMA\r\n-------------RubyMultipartPost\r\nContent-Disposition:
55
+ form-data; name=\"key\"\r\n\r\nuploads/8_295\r\n-------------RubyMultipartPost\r\nContent-Disposition:
56
+ form-data; name=\"file\"; filename=\"README.md\"\r\nContent-Length: 2314\r\nContent-Type:
57
+ \r\nContent-Transfer-Encoding: binary\r\n\r\n# Fileturn\n\nRuby Gem Support
58
+ for [FileTurn](http://fileturn.net/) Api. FileTurn converts your files to
59
+ different formats. \n\n## Installation\n\nAdd this line to your application's
60
+ Gemfile:\n\n gem 'fileturn'\n\nAnd then execute:\n\n $ bundle\n\nOr
61
+ install it yourself as:\n\n $ gem install fileturn\n\n## Configuration\n\nRetrieve
62
+ your API Key from [Dashboard](http://fileturn.net/dashboard/api_token).\n\n\tFileTurn.configure(:api_key
63
+ => \"[YOUR KEY]\")\n\t\nThats it - now you are ready to use FileTurn.\n\n##
64
+ Usage\n\n### Converting your files\n\nThere are multiple ways to convert a
65
+ file. If your file is public, we can fetch the file and you just need to specify
66
+ the url. \n\n\tfile = FileTurn::File.convert(\n\t\t:url => \"http://crypto.stanford.edu/DRM2002/darknet5.doc\",\n\t\t:convert_to
67
+ => :pdf\n\t)\n\t\n\tunless file.errors\n\t\t# Woot done!\n\tend\n\nIf your
68
+ file is stored locally, you can use\n\n\tfile = FileTurn::File.convert(\n\t\t:file
69
+ => File.open(\"localfile.doc\"),\n\t\t:convert_to => :txt\n\t)\n\nThats all
70
+ you have to do to convert files. Upon calling that, your file will be queued
71
+ for converting. \n\n### How will i know when my file is done?\n\n#### File
72
+ Object\n\nThere are few ways to check if your file is done. You can repeatedly
73
+ call one of these:\n\n\tfile.reload.queued? \n\tfile.reload.success?\n\tfile.reload.failed?\n\nWhen
74
+ your file is done, the file object will store a download link\n\n\twhile(file.reload.queued?)\n\t\tsleep(5000)\n\tend\n\t\n\tif
75
+ file.success?\n\t\tdownload_url = file.download_url\n\t\ttime_taken_for_conversion
76
+ = file.time_taken\n\tend\n\nIn the case you get a failure, you can retrieve
77
+ the details using\n\n\tif(file.reload.failed?)\n\t\tfile.notifications.last.details\n\tend\n\n####
78
+ Notifications\n\nYou can also request notification to be sent to you whenver
79
+ the status of a file changes. Go into your [Dashboard](http://fileturn.net/dashboard/notifications)
80
+ and specify a notification url. \n\nWe will hit this notification url with
81
+ the new status of the file and the file_id. \n\n\n## Other File Options\n\nYou
82
+ can fetch information of a single file using the file_id.\n\n\tFileTurn::File.find(file_id)\n\nOr
83
+ all the files\n\t\n\tFileTurn::File.all\n\n\n## Account Details\n\nYou can
84
+ also fetch account details like how much credit you have. \n\n\tFileTurn::Account.load
85
+ # fetch data from server\n\tFileTurn::Account.credits\n\nOr you can use\n\n\tFileTurn::Account.load.credits\n\nThanks!\r\n-------------RubyMultipartPost--\r\n\r\n"
86
+ headers:
87
+ User-Agent:
88
+ - Faraday v0.8.7
89
+ Content-Type:
90
+ - multipart/form-data;boundary=-----------RubyMultipartPost
91
+ Content-Length:
92
+ - '3107'
93
+ Accept:
94
+ - ! '*/*'
95
+ response:
96
+ status:
97
+ code: 204
98
+ message: No Content
99
+ headers:
100
+ X-Amz-Id-2:
101
+ - sPneiA/uySWOci+ZpcNBTzBRouUtRF6RwHvfjObHhcEiDG13Fz7FToqc5rUejwdG
102
+ X-Amz-Request-Id:
103
+ - 9C3451E544D80A73
104
+ Date:
105
+ - Sun, 07 Jul 2013 22:44:37 GMT
106
+ Etag:
107
+ - ! '"e3ac713f2489d9c764b8272add93b75d"'
108
+ Location:
109
+ - https://fileturn.s3.amazonaws.com/uploads%2F8_295
110
+ Server:
111
+ - AmazonS3
112
+ body:
113
+ encoding: US-ASCII
114
+ string: ''
115
+ http_version:
116
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
117
+ - request:
118
+ method: post
119
+ uri: http://localhost:3000/api/files.json?convert_to=pdf&file&file_type=md&token=67sFfjudMpXxJeioQcPSppYkoVdQD1oetqPWzMAh&upload_id=295&url=https://fileturn.s3.amazonaws.com/uploads/8_295
120
+ body:
121
+ encoding: US-ASCII
122
+ string: ''
123
+ headers:
124
+ User-Agent:
125
+ - Faraday v0.8.7
126
+ Content-Length:
127
+ - '0'
128
+ Accept:
129
+ - ! '*/*'
130
+ response:
131
+ status:
132
+ code: 201
133
+ message: ! 'Created '
134
+ headers:
135
+ Content-Type:
136
+ - application/json; charset=utf-8
137
+ X-Ua-Compatible:
138
+ - IE=Edge
139
+ Etag:
140
+ - ! '"ff0e8382dc641b864622680ca9c6b9c3"'
141
+ Cache-Control:
142
+ - max-age=0, private, must-revalidate
143
+ X-Request-Id:
144
+ - 26206bcc88a1744a6a780c1110283995
145
+ X-Runtime:
146
+ - '0.028675'
147
+ Server:
148
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
149
+ Date:
150
+ - Sun, 07 Jul 2013 22:46:59 GMT
151
+ Content-Length:
152
+ - '176'
153
+ Connection:
154
+ - Keep-Alive
155
+ body:
156
+ encoding: US-ASCII
157
+ string: ! '{"id":612,"url":"https://fileturn.s3.amazonaws.com/uploads/8_295","convert_to":"pdf","created_at":"2013-07-07T22:46:59Z","status":"queued","download_url":"","notifications":[]}'
158
+ http_version:
159
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
160
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/uploads.json?token=67sFfjudMpXxJeioQcPSppYkoVdQD1oetqPWzMAh
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.7
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ! 'OK '
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Etag:
26
+ - ! '"d08ed05b1967a3848120dea9cac5abfd"'
27
+ Cache-Control:
28
+ - max-age=0, private, must-revalidate
29
+ X-Request-Id:
30
+ - 48ccf97159cc9fd80cdc9f70227a6cd4
31
+ X-Runtime:
32
+ - '0.015663'
33
+ Server:
34
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
35
+ Date:
36
+ - Sun, 07 Jul 2013 22:46:59 GMT
37
+ Content-Length:
38
+ - '7021'
39
+ Connection:
40
+ - Keep-Alive
41
+ body:
42
+ encoding: US-ASCII
43
+ string: ! '{"uploads":[{"id":19,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0MjoyMVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzE5In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"fT8UPL6JZyFFDNnvp34hu19xTOA=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_19","url":"https://fileturn.s3.amazonaws.com"},{"id":20,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0NDo0NVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzIwIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"jo5qzKc7bttffI4lvaMYtvPJTLU=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_20","url":"https://fileturn.s3.amazonaws.com"},{"id":21,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0NTozMloiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzIxIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"qr5JLPrgZwbxZrg7mLHWocjPT0M=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_21","url":"https://fileturn.s3.amazonaws.com"},{"id":22,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0Njo1N1oiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzIyIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"w8x85LquOE27301pPiXSJ4n4TU8=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_22","url":"https://fileturn.s3.amazonaws.com"},{"id":23,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0NzoxMFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzIzIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"G4J86vvrjRsbmt6gAjlFnY4nn58=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_23","url":"https://fileturn.s3.amazonaws.com"},{"id":24,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1MDoyN1oiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI0In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"VxngEVfIogyU4s0qY/WfqOBi3cY=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_24","url":"https://fileturn.s3.amazonaws.com"},{"id":25,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1MTo0NloiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI1In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"Rpm+KCeuQH8eEFvHJLM/VL+4Bls=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_25","url":"https://fileturn.s3.amazonaws.com"},{"id":26,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1Mzo0OFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI2In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"6IFA8778EX4b/99RZDeqEUIQL/U=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_26","url":"https://fileturn.s3.amazonaws.com"},{"id":27,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1NDowOVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI3In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"HQ92JSVOOj1mrjHyZvWEIPEvA+I=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_27","url":"https://fileturn.s3.amazonaws.com"},{"id":28,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1NTozNFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI4In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"Pi13kzzDw5fX5n+HP6BlRTivxe0=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_28","url":"https://fileturn.s3.amazonaws.com"},{"id":29,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1NTo1NloiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzI5In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"fua+0jX4FjeErG35xs+6pbbWJx4=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_29","url":"https://fileturn.s3.amazonaws.com"},{"id":30,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1NjowM1oiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzMwIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"s3p27gHOZzTh8C6QLVbuU1DcTEQ=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_30","url":"https://fileturn.s3.amazonaws.com"},{"id":31,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1NjoxOFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzMxIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"bBi91IEq6w2eVC4rIHLgCsXK5Kc=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_31","url":"https://fileturn.s3.amazonaws.com"},{"id":32,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1NjozN1oiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzMyIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"KhfEDSOEw1MVIL7VG/rtxdKcLgs=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_32","url":"https://fileturn.s3.amazonaws.com"},{"id":33,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1Njo0OFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzMzIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"j9aCDICySJPRJpmoSDvZm/78RGs=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_33","url":"https://fileturn.s3.amazonaws.com"},{"id":34,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1NzowNFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzM0In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"Y+IwBpUNSeXNOPZxechPfr2YY/w=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_34","url":"https://fileturn.s3.amazonaws.com"},{"id":35,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1Nzo1MFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzM1In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"7LgZIqOKMlfIAMFzrh5SfJJkoLI=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_35","url":"https://fileturn.s3.amazonaws.com"},{"id":36,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo1OToyN1oiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzM2In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"36DzSgSNJBPtaE8NIHBJE+dTBsI=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_36","url":"https://fileturn.s3.amazonaws.com"},{"id":37,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwODowMjoxN1oiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzM3In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"JXTm5t7JAg+Qe3x9uH+L3AaePtY=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_37","url":"https://fileturn.s3.amazonaws.com"},{"id":38,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwODowNDoxOVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzM4In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"ABsF7VLBIGlIvXQUpsZW0eu6Xds=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_38","url":"https://fileturn.s3.amazonaws.com"}],"total_uploads":240,"current_page":1,"per_page":20,"total_pages":12}'
44
+ http_version:
45
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
46
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/uploads/19.json?token=67sFfjudMpXxJeioQcPSppYkoVdQD1oetqPWzMAh
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.7
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ! 'OK '
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Etag:
26
+ - ! '"dc6610c293f9549d4c844add90a55b08"'
27
+ Cache-Control:
28
+ - max-age=0, private, must-revalidate
29
+ X-Request-Id:
30
+ - 5b646966a1b4b352258d3fa574712a79
31
+ X-Runtime:
32
+ - '0.010860'
33
+ Server:
34
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
35
+ Date:
36
+ - Sun, 07 Jul 2013 22:46:59 GMT
37
+ Content-Length:
38
+ - '346'
39
+ Connection:
40
+ - Keep-Alive
41
+ body:
42
+ encoding: US-ASCII
43
+ string: ! '{"id":19,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0MjoyMVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzE5In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"fT8UPL6JZyFFDNnvp34hu19xTOA=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_19","url":"https://fileturn.s3.amazonaws.com"}'
44
+ http_version:
45
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
46
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,89 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/uploads/19.json?token=67sFfjudMpXxJeioQcPSppYkoVdQD1oetqPWzMAh
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.7
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ! 'OK '
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ X-Ua-Compatible:
24
+ - IE=Edge
25
+ Etag:
26
+ - ! '"dc6610c293f9549d4c844add90a55b08"'
27
+ Cache-Control:
28
+ - max-age=0, private, must-revalidate
29
+ X-Request-Id:
30
+ - dd06664c57013d8aefc7700099de7786
31
+ X-Runtime:
32
+ - '0.010544'
33
+ Server:
34
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
35
+ Date:
36
+ - Sun, 07 Jul 2013 22:46:59 GMT
37
+ Content-Length:
38
+ - '346'
39
+ Connection:
40
+ - Keep-Alive
41
+ body:
42
+ encoding: US-ASCII
43
+ string: ! '{"id":19,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0MjoyMVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzE5In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"fT8UPL6JZyFFDNnvp34hu19xTOA=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_19","url":"https://fileturn.s3.amazonaws.com"}'
44
+ http_version:
45
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
46
+ - request:
47
+ method: get
48
+ uri: http://localhost:3000/api/uploads/19.json?token=67sFfjudMpXxJeioQcPSppYkoVdQD1oetqPWzMAh
49
+ body:
50
+ encoding: US-ASCII
51
+ string: ''
52
+ headers:
53
+ User-Agent:
54
+ - Faraday v0.8.7
55
+ Accept-Encoding:
56
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
57
+ Accept:
58
+ - ! '*/*'
59
+ response:
60
+ status:
61
+ code: 200
62
+ message: ! 'OK '
63
+ headers:
64
+ Content-Type:
65
+ - application/json; charset=utf-8
66
+ X-Ua-Compatible:
67
+ - IE=Edge
68
+ Etag:
69
+ - ! '"dc6610c293f9549d4c844add90a55b08"'
70
+ Cache-Control:
71
+ - max-age=0, private, must-revalidate
72
+ X-Request-Id:
73
+ - 34e5c079a3458e103bb7439b35090803
74
+ X-Runtime:
75
+ - '0.009202'
76
+ Server:
77
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-11-10)
78
+ Date:
79
+ - Sun, 07 Jul 2013 22:46:59 GMT
80
+ Content-Length:
81
+ - '346'
82
+ Connection:
83
+ - Keep-Alive
84
+ body:
85
+ encoding: US-ASCII
86
+ string: ! '{"id":19,"policy":"eyJleHBpcmF0aW9uIjoiMjAxMy0wNy0wN1QwNzo0MjoyMVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJmaWxldHVybiJ9LHsia2V5IjoidXBsb2Fkcy84XzE5In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsNTAwLDUwMF1dfQ==","signature":"fT8UPL6JZyFFDNnvp34hu19xTOA=","aws_access_key_id":"AKIAIKXW3ZZ5WNURNYMA","key":"uploads/8_19","url":"https://fileturn.s3.amazonaws.com"}'
87
+ http_version:
88
+ recorded_at: Sun, 07 Jul 2013 22:46:59 GMT
89
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe FileTurn::Account do
4
+ it 'retrieves account information' do
5
+ VCR.use_cassette('account_info') do
6
+ FileTurn::Account.load
7
+ FileTurn::Account.credits.should_not be_nil
8
+ FileTurn::Account.time_zone.should_not be_nil
9
+ FileTurn::Account.notification_url.should_not be_nil
10
+ FileTurn::Account.max_file_size_in_bytes.should == 1048576
11
+ FileTurn::Account.created_at.class.should == DateTime
12
+ end
13
+ end
14
+
15
+ it 'makes the call only once' do
16
+ VCR.use_cassette('account_info_once') do
17
+ FileTurn::Account.conn.should_receive(:get).once
18
+ FileTurn::Account.load
19
+ FileTurn::Account.credits
20
+ end
21
+ end
22
+
23
+ it 'makes the call only twice' do
24
+ VCR.use_cassette('account_info_twice') do
25
+ FileTurn::Account.conn.should_receive(:get).twice
26
+ FileTurn::Account.load
27
+ FileTurn::Account.load
28
+ FileTurn::Account.credits
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,184 @@
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