rev-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +20 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +42 -0
  7. data/LICENSE +191 -0
  8. data/README.md +124 -0
  9. data/Rakefile +14 -0
  10. data/examples/cli.rb +200 -0
  11. data/lib/rev-api.rb +26 -0
  12. data/lib/rev-api/api.rb +311 -0
  13. data/lib/rev-api/api_serializable.rb +30 -0
  14. data/lib/rev-api/exceptions.rb +108 -0
  15. data/lib/rev-api/http_client.rb +97 -0
  16. data/lib/rev-api/models/order.rb +113 -0
  17. data/lib/rev-api/models/order_request.rb +183 -0
  18. data/lib/rev-api/version.rb +3 -0
  19. data/rev-api.gemspec +33 -0
  20. data/spec/fixtures/api_cassettes/cancel_order.yml +38 -0
  21. data/spec/fixtures/api_cassettes/cancel_order_not_allowed.yml +40 -0
  22. data/spec/fixtures/api_cassettes/get_attachment_content.yml +399 -0
  23. data/spec/fixtures/api_cassettes/get_attachment_content_as_pdf.yml +399 -0
  24. data/spec/fixtures/api_cassettes/get_attachment_content_as_text.yml +65 -0
  25. data/spec/fixtures/api_cassettes/get_attachment_content_as_youtube_transcript.yml +66 -0
  26. data/spec/fixtures/api_cassettes/get_attachment_content_unacceptable_representation.yml +42 -0
  27. data/spec/fixtures/api_cassettes/get_attachment_content_with_invalid_id.yml +42 -0
  28. data/spec/fixtures/api_cassettes/get_attachment_metadata.yml +42 -0
  29. data/spec/fixtures/api_cassettes/get_attachment_with_invalid_id.yml +40 -0
  30. data/spec/fixtures/api_cassettes/get_orders.yml +122 -0
  31. data/spec/fixtures/api_cassettes/get_tc_order.yml +44 -0
  32. data/spec/fixtures/api_cassettes/get_third_page_of_orders.yml +58 -0
  33. data/spec/fixtures/api_cassettes/get_tr_order.yml +44 -0
  34. data/spec/fixtures/api_cassettes/link_input.yml +44 -0
  35. data/spec/fixtures/api_cassettes/link_input_with_all_attributes.yml +44 -0
  36. data/spec/fixtures/api_cassettes/not_found_order.yml +42 -0
  37. data/spec/fixtures/api_cassettes/submit_tc_order_with_account_balance.yml +45 -0
  38. data/spec/fixtures/api_cassettes/submit_tc_order_with_cc_and_all_attributes.yml +46 -0
  39. data/spec/fixtures/api_cassettes/submit_tc_order_with_invalid_request.yml +45 -0
  40. data/spec/fixtures/api_cassettes/submit_tc_order_with_saved_cc.yml +45 -0
  41. data/spec/fixtures/api_cassettes/submit_tr_order.yml +44 -0
  42. data/spec/fixtures/api_cassettes/unauthorized.yml +42 -0
  43. data/spec/fixtures/api_cassettes/upload_input.yml +130 -0
  44. data/spec/fixtures/api_cassettes/upload_input_with_invalid_content_type.yml +131 -0
  45. data/spec/fixtures/sourcedocument.png +0 -0
  46. data/spec/lib/rev/api_spec.rb +24 -0
  47. data/spec/lib/rev/cancel_order_spec.rb +25 -0
  48. data/spec/lib/rev/get_attachment_content_spec.rb +79 -0
  49. data/spec/lib/rev/get_attachment_metadata_spec.rb +33 -0
  50. data/spec/lib/rev/get_order_spec.rb +68 -0
  51. data/spec/lib/rev/get_orders_spec.rb +39 -0
  52. data/spec/lib/rev/http_client_spec.rb +32 -0
  53. data/spec/lib/rev/post_inputs_spec.rb +75 -0
  54. data/spec/lib/rev/post_order_spec.rb +207 -0
  55. data/spec/spec_helper.rb +31 -0
  56. metadata +248 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWVlMzlkMWQ4YzBjZjMxODVkYmM0YWU2NTVjMWNmYWNjOWIwNTUwMw==
5
+ data.tar.gz: !binary |-
6
+ N2EwOTUzY2E4MzQyODczOTIxYzI1NDU3NTY0NDQzMTNmNThlNDYzMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZWM0ZDhhYzk4NjJhYjExMDk0NWQ0NTcwMmVjYjcwZWY5OGY1YmRkMGIzZjJl
10
+ NDE4ZjAxMTc0YTk1N2ViNDIyYjY1NzkwNzkwMjkwNTc2OGE0MmQzMmRlZTFl
11
+ ZmJjYzBlNTNmMmUzM2E1ZWFhN2E5NDY3ZTVhMjBmMjg3MGFkM2M=
12
+ data.tar.gz: !binary |-
13
+ Njk4OWM0OGYzZjNmNjI2NzMwNmZmNDM3NmVkMTkzNWIyY2FmMjBhMzYxMjA3
14
+ NmQ2OGE5ZjFlOTM5NmMxMzM4NmY4YzZlYmExYzllZDdkNzMxMWRiNjMyYWI0
15
+ NzQ5MDM5NzQ3NGFiMTgxMzA4NDM2OWZjZWE1MTE0ZjQzMTJiOTE=
@@ -0,0 +1,20 @@
1
+ .DS_Store
2
+
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ coverage
8
+ InstalledFiles
9
+ lib/bundler/man
10
+ pkg
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+ doc
17
+
18
+ # YARD artifacts
19
+ .yardoc
20
+ _yardoc
@@ -0,0 +1 @@
1
+ rev-sdk
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p448
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rev-api (1.0.0)
5
+ httparty (>= 0.11.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.5)
11
+ ansi (1.4.3)
12
+ crack (0.4.1)
13
+ safe_yaml (~> 0.9.0)
14
+ httparty (0.11.0)
15
+ multi_json (~> 1.0)
16
+ multi_xml (>= 0.5.2)
17
+ multi_json (1.8.0)
18
+ multi_xml (0.5.5)
19
+ rake (10.1.0)
20
+ redcarpet (3.0.0)
21
+ rubygems-tasks (0.2.4)
22
+ safe_yaml (0.9.5)
23
+ turn (0.9.6)
24
+ ansi
25
+ vcr (2.5.0)
26
+ webmock (1.11.0)
27
+ addressable (>= 2.2.7)
28
+ crack (>= 0.3.2)
29
+ yard (0.8.7)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ rake (>= 10.1.0)
36
+ redcarpet
37
+ rev-api!
38
+ rubygems-tasks
39
+ turn (~> 0.9.6)
40
+ vcr (~> 2.5.0)
41
+ webmock (~> 1.11.0)
42
+ yard
data/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work (an example is provided in the Appendix below).
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License.
62
+
63
+ Subject to the terms and conditions of this License, each Contributor hereby
64
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+ publicly display, publicly perform, sublicense, and distribute the Work and such
67
+ Derivative Works in Source or Object form.
68
+
69
+ 3. Grant of Patent License.
70
+
71
+ Subject to the terms and conditions of this License, each Contributor hereby
72
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+ irrevocable (except as stated in this section) patent license to make, have
74
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+ such license applies only to those patent claims licensable by such Contributor
76
+ that are necessarily infringed by their Contribution(s) alone or by combination
77
+ of their Contribution(s) with the Work to which such Contribution(s) was
78
+ submitted. If You institute patent litigation against any entity (including a
79
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+ Contribution incorporated within the Work constitutes direct or contributory
81
+ patent infringement, then any patent licenses granted to You under this License
82
+ for that Work shall terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution.
85
+
86
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+ in any medium, with or without modifications, and in Source or Object form,
88
+ provided that You meet the following conditions:
89
+
90
+ You must give any other recipients of the Work or Derivative Works a copy of
91
+ this License; and
92
+ You must cause any modified files to carry prominent notices stating that You
93
+ changed the files; and
94
+ You must retain, in the Source form of any Derivative Works that You distribute,
95
+ all copyright, patent, trademark, and attribution notices from the Source form
96
+ of the Work, excluding those notices that do not pertain to any part of the
97
+ Derivative Works; and
98
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+ Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+ You may add Your own copyright statement to Your modifications and may provide
112
+ additional or different license terms and conditions for use, reproduction, or
113
+ distribution of Your modifications, or for any such Derivative Works as a whole,
114
+ provided Your use, reproduction, and distribution of the Work otherwise complies
115
+ with the conditions stated in this License.
116
+
117
+ 5. Submission of Contributions.
118
+
119
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+ for inclusion in the Work by You to the Licensor shall be under the terms and
121
+ conditions of this License, without any additional terms or conditions.
122
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+ any separate license agreement you may have executed with Licensor regarding
124
+ such Contributions.
125
+
126
+ 6. Trademarks.
127
+
128
+ This License does not grant permission to use the trade names, trademarks,
129
+ service marks, or product names of the Licensor, except as required for
130
+ reasonable and customary use in describing the origin of the Work and
131
+ reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty.
134
+
135
+ Unless required by applicable law or agreed to in writing, Licensor provides the
136
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+ including, without limitation, any warranties or conditions of TITLE,
139
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+ solely responsible for determining the appropriateness of using or
141
+ redistributing the Work and assume any risks associated with Your exercise of
142
+ permissions under this License.
143
+
144
+ 8. Limitation of Liability.
145
+
146
+ In no event and under no legal theory, whether in tort (including negligence),
147
+ contract, or otherwise, unless required by applicable law (such as deliberate
148
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special, incidental,
150
+ or consequential damages of any character arising as a result of this License or
151
+ out of the use or inability to use the Work (including but not limited to
152
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+ any and all other commercial damages or losses), even if such Contributor has
154
+ been advised of the possibility of such damages.
155
+
156
+ 9. Accepting Warranty or Additional Liability.
157
+
158
+ While redistributing the Work or Derivative Works thereof, You may choose to
159
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+ other liability obligations and/or rights consistent with this License. However,
161
+ in accepting such obligations, You may act only on Your own behalf and on Your
162
+ sole responsibility, not on behalf of any other Contributor, and only if You
163
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+ incurred by, or claims asserted against, such Contributor by reason of your
165
+ accepting any such warranty or additional liability.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work
170
+
171
+ To apply the Apache License to your work, attach the following boilerplate
172
+ notice, with the fields enclosed by brackets "[]" replaced with your own
173
+ identifying information. (Don't include the brackets!) The text should be
174
+ enclosed in the appropriate comment syntax for the file format. We also
175
+ recommend that a file or class name and description of purpose be included on
176
+ the same "printed page" as the copyright notice for easier identification within
177
+ third-party archives.
178
+
179
+ Copyright [yyyy] [name of copyright owner]
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,124 @@
1
+ rev-ruby-sdk
2
+ ------------
3
+
4
+ ### Background
5
+
6
+ Rev.com provides transcription and translation services powered by humans. The Rev.com API allows you to tap these services
7
+ with no manual steps. It's a RESTful API, documented at <http://www.rev.com/api/docs>.
8
+
9
+ The Ruby SDK for the Rev API provides a convenient Ruby wrapper for the Rev.com API. All operations of the API, as described
10
+ at <http://www.rev.com/api/operations>, are supported.
11
+
12
+ ### Install
13
+
14
+ ```shell
15
+ gem install rev-api
16
+ ```
17
+
18
+ or put it into your Gemfile.
19
+
20
+ When you need it:
21
+
22
+ ```ruby
23
+ require 'rev-api'
24
+ ```
25
+
26
+ ### Authentication
27
+
28
+ If you are building a new API client, you must first obtain a client API key, which you can do at <http://www.rev.com/api>.
29
+
30
+ All operations in the API are performed on behalf of a Rev customer, identified by their user API key. The client key / user
31
+ key pair is used to authenticate each API operation. Once you have the two keys, you can create a new Rev.com API client:
32
+
33
+
34
+ ```ruby
35
+ require 'rev-api'
36
+
37
+ rev_client = Rev.new('your_client_key', 'your_user_key')
38
+ ```
39
+
40
+ You can read more about authentication in the Rev.com API at <http://www.rev.com/api/security>
41
+
42
+ ### Sandbox
43
+
44
+ All operations can be executed against either the production or the sandbox environment. The sandbox environment allows you
45
+ to test your API client without actually paying for orders and having them worked on.
46
+
47
+ By default, the Rev.com API client executes against the production environment. To go against the sandbox instead,
48
+ initialize the client this way:
49
+
50
+ ```ruby
51
+ require 'rev-api'
52
+
53
+ rev_client = Rev.new('your_client_key', 'your_user_key', Rev::Api::SANDBOX_HOST)
54
+ ```
55
+
56
+ ### Usage
57
+
58
+ The snippets below assume you've initialized `rev_client`:
59
+
60
+ ```ruby
61
+ rev_client = Rev.new('your_client_key', 'your_user_key')
62
+ ```
63
+
64
+ #### Listing orders
65
+
66
+ ```ruby
67
+ orders_page = rev_client.get_orders_page(1); # get a single page of orders
68
+ all_orders = rev_client.get_all_orders; # get first page of orders history
69
+ ```
70
+
71
+ #### Get a single order by order number
72
+
73
+ ```ruby
74
+ some_order = rev_client.get_order('TCxxxxxxxx')
75
+ puts "Original comment: #{some_order.comments.first.text}"
76
+ ```
77
+
78
+ #### Cancel an order given an order number
79
+
80
+ ```ruby
81
+ rev_client.cancel_order('TCxxxxxxxx')
82
+ ```
83
+
84
+ #### Print out the text of all transcripts in an order
85
+
86
+ ```ruby
87
+ order = rev_client.get_order('TCxxxxxxx')
88
+
89
+ order.transcripts.each do |t|
90
+ puts rev_client.get_attachment_content_as_string t.id
91
+ puts
92
+ end
93
+ ```
94
+
95
+ Refer to `cli.rb` in the `examples` directory for a full example illustrating placing orders, handling error responses, etc.
96
+
97
+ ### Documentation
98
+
99
+ YARD documentation can be generated by running `rake yard` command, and will be placed in the `doc` directory.
100
+
101
+ You can find API documentation at <http://www.rev.com/api/docs>.
102
+
103
+ ### Support
104
+
105
+ If you have any questions or suggestions for improvement, email us directly at api[at]rev[dot]com.
106
+
107
+ ### Compatibility
108
+
109
+ - MRI 1.9.3
110
+ - MRI 2.0.0
111
+
112
+ ### Tests
113
+
114
+ Minitest suite might be run using `rake test` command.
115
+ Current stack:
116
+
117
+ - minitest
118
+ - webmock
119
+ - vcr
120
+ - turn
121
+
122
+ ### Dependencies
123
+
124
+ - httparty
@@ -0,0 +1,14 @@
1
+ require 'rake/testtask'
2
+ require 'yard'
3
+ require 'rubygems/tasks'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList['spec/lib/rev/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ YARD::Rake::YardocTask.new
11
+
12
+ Gem::Tasks.new
13
+
14
+ task :default => :test
@@ -0,0 +1,200 @@
1
+ require 'rev-api'
2
+ require 'optparse'
3
+ require 'pp'
4
+
5
+ # An example app using the official Ruby SDK for the Rev.com API
6
+ # This ruby script sets up a basic command line interface (CLI)
7
+ # that prompts a user to authenticate on the web, then
8
+ # allows them to type commands to manipulate their orders.
9
+ #
10
+ # To start, run:
11
+ # ruby examples/cli.rb --sandbox --client-key your_client_key --user-key your_user_key
12
+
13
+ class RevCLI
14
+ COMMANDS = %w{help get list transcripts dl_transcripts dl_sources place cancel}
15
+
16
+ def initialize
17
+ options = { :environment => Rev::Api::PRODUCTION_HOST, :verbatim => false, :timestamps => false }
18
+ optparse = OptionParser.new do |opts|
19
+ opts.banner = "Usage: cli.rb [options]. You will be prompted for command then."
20
+
21
+ opts.on("--client-key CLIENT-KEY", "Use CLIENT-KEY as the API Client Key for Authorization") do |client_key|
22
+ options[:client_key] = client_key
23
+ end
24
+
25
+ opts.on("--user-key USER-KEY", "Use USER-KEY as the API User Key for Authorization") do |user_key|
26
+ options[:user_key] = user_key
27
+ end
28
+
29
+ opts.on("--sandbox", "Execute against the Sandbox environment rather than production") do
30
+ options[:environment] = Rev::Api::SANDBOX_HOST
31
+ end
32
+
33
+ opts.on("--[no-]verbatim", "Request verbatim transcription") do |v|
34
+ options[:verbatim] = v
35
+ end
36
+
37
+ opts.on("--[no-]timestamps", "Request timestamps transcription") do |t|
38
+ options[:timestamps] = t
39
+ end
40
+ end
41
+ optparse.parse!
42
+
43
+ raise OptionParser::MissingArgument, "--client-key" if options[:client_key].nil?
44
+ raise OptionParser::MissingArgument, "--user-key" if options[:user_key].nil?
45
+
46
+ @rev_client = Rev.new(options[:client_key], options[:user_key], options[:environment])
47
+ end
48
+
49
+ def command_loop
50
+ puts "Enter a command or 'help' or 'exit'"
51
+ command_line = ''
52
+
53
+ while command_line.strip != 'exit'
54
+ begin
55
+ execute_command(command_line)
56
+ rescue RuntimeError => e
57
+ puts "Command Line Error! #{e.class}: #{e}"
58
+ puts e.backtrace
59
+ end
60
+ print '> '
61
+ command_line = gets.strip
62
+ end
63
+
64
+ puts 'Goodbye!'
65
+ exit(0)
66
+ end
67
+
68
+ def execute_command(cmd_line)
69
+ command = cmd_line.split
70
+ method = command.first
71
+ if COMMANDS.include? method
72
+ begin
73
+ send(method.to_sym, command[1..-1])
74
+ rescue Rev::BadRequestError => e
75
+ puts "Server returned error with code #{e.code}, message #{e.message}"
76
+ rescue Rev::ApiError => e
77
+ puts "Server returned error with message #{e.message}"
78
+ end
79
+ elsif command.first && !command.first.strip.empty?
80
+ puts 'Invalid command. Type \'help\' to see commands.'
81
+ end
82
+ end
83
+
84
+ def get(args)
85
+ order_num = args[0]
86
+ order = @rev_client.get_order order_num
87
+ pp order
88
+ end
89
+
90
+ def list(args)
91
+ orders = @rev_client.get_all_orders
92
+ orders.each { |o| puts("#{o.order_number}") }
93
+
94
+ puts 'There are no orders placed so far.' if orders.empty?
95
+ end
96
+
97
+ def transcripts(args)
98
+ begin
99
+ order_num = args[0]
100
+ order = @rev_client.get_order order_num
101
+
102
+ if order.transcripts.empty?
103
+ puts "There are no transcripts for order #{order_num}"
104
+ return
105
+ end
106
+
107
+ order.transcripts.each do |t|
108
+ puts "Contents of #{t.name}"
109
+ puts "-----------------------------------"
110
+ puts @rev_client.get_attachment_content_as_string t.id
111
+ puts
112
+ end
113
+ rescue Rev::BadRequestError => e
114
+ puts "Displaying transcripts failed with error code #{e.code}, message #{e.message}"
115
+ end
116
+ end
117
+
118
+ def dl_transcripts(args)
119
+ begin
120
+ order_num = args[0]
121
+ order = @rev_client.get_order order_num
122
+
123
+ if order.transcripts.empty?
124
+ puts "There are no transcripts for order #{order_num}"
125
+ return
126
+ end
127
+
128
+ filenames = order.transcripts.map { |t| t.name}.join(',')
129
+ puts "Downloading files: #{filenames}"
130
+ order.transcripts.each do |t|
131
+ @rev_client.save_attachment_content t.id, t.name
132
+ end
133
+ rescue Rev::BadRequestError => e
134
+ puts "Downloading transcripts failed with error code #{e.code}, message #{e.message}"
135
+ end
136
+ end
137
+
138
+ def dl_sources(args)
139
+ begin
140
+ order_num = args[0]
141
+ order = @rev_client.get_order order_num
142
+
143
+ if order.sources.empty?
144
+ puts "There are no source files for order #{order_num}"
145
+ return
146
+ end
147
+
148
+ filenames = order.sources.map { |t| t.name }.join(',')
149
+ puts "Downloading files: #{filenames}"
150
+ order.sources.each do |t|
151
+ @rev_client.save_attachment_content t.id, t.name
152
+ end
153
+ rescue Rev::BadRequestError => e
154
+ puts "Downloading sources failed with error code #{e.code}, message #{e.message}"
155
+ end
156
+ end
157
+
158
+ def cancel(args)
159
+ begin
160
+ order_num = args[0]
161
+ @rev_client.cancel_order order_num
162
+ puts "Order #{order_num} cancelled"
163
+ rescue Rev::BadRequestError => e
164
+ puts "Cancelling order failed with error code #{e.code}, message #{e.message}"
165
+ end
166
+ end
167
+
168
+ def place(args)
169
+ input_urls = args.map do |f|
170
+ puts "Uploading #{f}"
171
+ @rev_client.upload_input(f, 'audio/mpeg')
172
+ end
173
+
174
+ payment = Rev::Payment.with_credit_card_on_file
175
+ inputs = input_urls.map { |url| Rev::Input.new(:uri => url, :audio_length => 3) }
176
+ tc_options = Rev::TranscriptionOptions.new(inputs)
177
+
178
+ request = Rev::OrderRequest.new(
179
+ payment,
180
+ :transcription_options => tc_options,
181
+ :client_ref => 'XB432423',
182
+ :comment => 'Please work quickly'
183
+ )
184
+
185
+ # act!
186
+ begin
187
+ new_order = @rev_client.submit_order(request)
188
+ puts "New order: #{new_order}"
189
+ rescue Rev::BadRequestError => e
190
+ puts "Order placement failed with error code #{e.code}, message #{e.message}"
191
+ end
192
+ end
193
+
194
+ def help(*args)
195
+ puts "commands are: #{COMMANDS.join(' ')} help exit"
196
+ end
197
+ end
198
+
199
+ cli = RevCLI.new
200
+ cli.command_loop