rev-api 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -1
- data/.gitignore +21 -21
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +8 -8
- data/Gemfile +3 -3
- data/LICENSE +191 -191
- data/README.md +132 -132
- data/Rakefile +13 -13
- data/examples/cli.rb +270 -270
- data/lib/rev-api.rb +25 -25
- data/lib/rev-api/api.rb +326 -326
- data/lib/rev-api/api_serializable.rb +30 -30
- data/lib/rev-api/exceptions.rb +100 -100
- data/lib/rev-api/http_client.rb +97 -97
- data/lib/rev-api/models/order.rb +138 -138
- data/lib/rev-api/models/order_request.rb +222 -228
- data/lib/rev-api/version.rb +3 -3
- data/rev-api.gemspec +34 -34
- data/spec/fixtures/api_cassettes/cancel_order.yml +38 -38
- data/spec/fixtures/api_cassettes/cancel_order_not_allowed.yml +40 -40
- data/spec/fixtures/api_cassettes/get_attachment_content.yml +399 -399
- data/spec/fixtures/api_cassettes/get_attachment_content_as_pdf.yml +399 -399
- data/spec/fixtures/api_cassettes/get_attachment_content_as_text.yml +65 -65
- data/spec/fixtures/api_cassettes/get_attachment_content_as_youtube_transcript.yml +66 -66
- data/spec/fixtures/api_cassettes/get_attachment_content_unacceptable_representation.yml +42 -42
- data/spec/fixtures/api_cassettes/get_attachment_content_with_invalid_id.yml +42 -42
- data/spec/fixtures/api_cassettes/get_attachment_metadata.yml +42 -42
- data/spec/fixtures/api_cassettes/get_attachment_with_invalid_id.yml +40 -40
- data/spec/fixtures/api_cassettes/get_orders.yml +122 -122
- data/spec/fixtures/api_cassettes/get_orders_with_clientRef.yml +41 -41
- data/spec/fixtures/api_cassettes/get_tc_order.yml +44 -44
- data/spec/fixtures/api_cassettes/get_third_page_of_orders.yml +58 -58
- data/spec/fixtures/api_cassettes/get_tr_order.yml +44 -44
- data/spec/fixtures/api_cassettes/link_input.yml +44 -44
- data/spec/fixtures/api_cassettes/link_input_with_all_attributes.yml +44 -44
- data/spec/fixtures/api_cassettes/link_input_with_spaces_in_filename.yml +45 -45
- data/spec/fixtures/api_cassettes/not_found_order.yml +42 -42
- data/spec/fixtures/api_cassettes/submit_cp_order.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_su_order.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tc_order_with_account_balance.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tc_order_with_invalid_request.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tc_order_without_specifying_payment.yml +45 -45
- data/spec/fixtures/api_cassettes/submit_tr_order.yml +44 -44
- data/spec/fixtures/api_cassettes/unauthorized.yml +42 -42
- data/spec/fixtures/api_cassettes/upload_input.yml +90 -90
- data/spec/fixtures/api_cassettes/upload_input_with_invalid_content_type.yml +91 -91
- data/spec/lib/rev/api_spec.rb +24 -24
- data/spec/lib/rev/cancel_order_spec.rb +24 -24
- data/spec/lib/rev/exceptions_spec.rb +8 -8
- data/spec/lib/rev/get_attachment_content_spec.rb +79 -79
- data/spec/lib/rev/get_attachment_metadata_spec.rb +33 -33
- data/spec/lib/rev/get_order_spec.rb +67 -67
- data/spec/lib/rev/get_orders_spec.rb +61 -61
- data/spec/lib/rev/http_client_spec.rb +32 -32
- data/spec/lib/rev/models/order_request_spec.rb +6 -14
- data/spec/lib/rev/models/order_spec.rb +58 -58
- data/spec/lib/rev/post_inputs_spec.rb +94 -94
- data/spec/lib/rev/post_order_spec.rb +195 -195
- data/spec/spec_helper.rb +49 -49
- metadata +39 -82
data/README.md
CHANGED
@@ -1,132 +1,132 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/rev-api.png)](http://badge.fury.io/rb/rev-api)
|
2
|
-
[![Build Status](https://secure.travis-ci.org/revdotcom/rev-ruby-sdk.png?branch=master)](https://secure.travis-ci.org/revdotcom/rev-ruby-sdk)
|
3
|
-
[![Dependency Status](https://gemnasium.com/revdotcom/rev-ruby-sdk.png?travis)](https://gemnasium.com/revdotcom/rev-ruby-sdk)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/revdotcom/rev-ruby-sdk.png)](https://codeclimate.com/github/revdotcom/rev-ruby-sdk)
|
5
|
-
[![Coverage Status](https://coveralls.io/repos/revdotcom/rev-ruby-sdk/badge.png)](https://coveralls.io/r/revdotcom/rev-ruby-sdk)
|
6
|
-
|
7
|
-
[Reference](https://www.rev.com/api/docs) | [RDocs](http://rubydoc.info/github/revdotcom/rev-ruby-sdk/master/frames)
|
8
|
-
|
9
|
-
rev-ruby-sdk
|
10
|
-
------------
|
11
|
-
|
12
|
-
### Background
|
13
|
-
|
14
|
-
Rev.com provides transcription and translation services powered by humans. The Rev.com API allows you to tap these services
|
15
|
-
with no manual steps. It's a RESTful API, documented at <https://www.rev.com/api/docs>.
|
16
|
-
|
17
|
-
The Ruby SDK for the Rev API provides a convenient Ruby wrapper for the Rev.com API. All operations of the API, as described
|
18
|
-
at <https://www.rev.com/api/operations>, are supported.
|
19
|
-
|
20
|
-
### Install
|
21
|
-
|
22
|
-
```shell
|
23
|
-
gem install rev-api
|
24
|
-
```
|
25
|
-
|
26
|
-
or put it into your Gemfile.
|
27
|
-
|
28
|
-
When you need it:
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
require 'rev-api'
|
32
|
-
```
|
33
|
-
|
34
|
-
### Authentication
|
35
|
-
|
36
|
-
If you are building a new API client, you must first obtain a client API key, which you can do at <https://www.rev.com/api>.
|
37
|
-
|
38
|
-
All operations in the API are performed on behalf of a Rev customer, identified by their user API key. The client key / user
|
39
|
-
key pair is used to authenticate each API operation. Once you have the two keys, you can create a new Rev.com API client:
|
40
|
-
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
require 'rev-api'
|
44
|
-
|
45
|
-
rev_client = Rev.new('your_client_key', 'your_user_key')
|
46
|
-
```
|
47
|
-
|
48
|
-
You can read more about authentication in the Rev.com API at <https://www.rev.com/api/security>
|
49
|
-
|
50
|
-
### Sandbox
|
51
|
-
|
52
|
-
All operations can be executed against either the production or the sandbox environment. The sandbox environment allows you
|
53
|
-
to test your API client without actually paying for orders and having them worked on.
|
54
|
-
|
55
|
-
By default, the Rev.com API client executes against the production environment. To go against the sandbox instead,
|
56
|
-
initialize the client this way:
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
require 'rev-api'
|
60
|
-
|
61
|
-
rev_client = Rev.new('your_client_key', 'your_user_key', Rev::Api::SANDBOX_HOST)
|
62
|
-
```
|
63
|
-
|
64
|
-
### Usage
|
65
|
-
|
66
|
-
The snippets below assume you've initialized `rev_client`:
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
rev_client = Rev.new('your_client_key', 'your_user_key')
|
70
|
-
```
|
71
|
-
|
72
|
-
#### Listing orders
|
73
|
-
|
74
|
-
```ruby
|
75
|
-
orders_page = rev_client.get_orders_page(1); # get a single page of orders
|
76
|
-
all_orders = rev_client.get_all_orders; # get first page of orders history
|
77
|
-
orders_by_client_ref = rev_client.get_orders_by_client_ref('some_ref'); # get orders with reference id of 'some_ref'
|
78
|
-
```
|
79
|
-
|
80
|
-
#### Get a single order by order number
|
81
|
-
|
82
|
-
```ruby
|
83
|
-
some_order = rev_client.get_order('TCxxxxxxxx')
|
84
|
-
puts "Original comment: #{some_order.comments.first.text}"
|
85
|
-
```
|
86
|
-
|
87
|
-
#### Cancel an order given an order number
|
88
|
-
|
89
|
-
```ruby
|
90
|
-
rev_client.cancel_order('TCxxxxxxxx')
|
91
|
-
```
|
92
|
-
|
93
|
-
#### Print out the text of all transcripts in an order
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
order = rev_client.get_order('TCxxxxxxx')
|
97
|
-
|
98
|
-
order.transcripts.each do |t|
|
99
|
-
puts rev_client.get_attachment_content_as_string t.id
|
100
|
-
puts
|
101
|
-
end
|
102
|
-
```
|
103
|
-
|
104
|
-
Refer to `cli.rb` in the `examples` directory for a full example illustrating placing orders, handling error responses, etc.
|
105
|
-
|
106
|
-
### Documentation
|
107
|
-
|
108
|
-
[YARD documentation](http://rubydoc.info/github/revdotcom/rev-ruby-sdk/master/frames) can be generated locally by running `rake yard` command, and will be placed in the `doc` directory.
|
109
|
-
|
110
|
-
You can find API documentation at <https://www.rev.com/api/docs>.
|
111
|
-
|
112
|
-
### Support
|
113
|
-
|
114
|
-
If you have any questions or suggestions for improvement, email us directly at api[at]rev[dot]com.
|
115
|
-
|
116
|
-
### Compatibility
|
117
|
-
|
118
|
-
- MRI 2.0.0
|
119
|
-
|
120
|
-
### Tests
|
121
|
-
|
122
|
-
Minitest suite might be run using `rake test` command.
|
123
|
-
Current stack:
|
124
|
-
|
125
|
-
- minitest
|
126
|
-
- webmock
|
127
|
-
- vcr
|
128
|
-
- turn
|
129
|
-
|
130
|
-
### Dependencies
|
131
|
-
|
132
|
-
- httparty
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/rev-api.png)](http://badge.fury.io/rb/rev-api)
|
2
|
+
[![Build Status](https://secure.travis-ci.org/revdotcom/rev-ruby-sdk.png?branch=master)](https://secure.travis-ci.org/revdotcom/rev-ruby-sdk)
|
3
|
+
[![Dependency Status](https://gemnasium.com/revdotcom/rev-ruby-sdk.png?travis)](https://gemnasium.com/revdotcom/rev-ruby-sdk)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/revdotcom/rev-ruby-sdk.png)](https://codeclimate.com/github/revdotcom/rev-ruby-sdk)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/revdotcom/rev-ruby-sdk/badge.png)](https://coveralls.io/r/revdotcom/rev-ruby-sdk)
|
6
|
+
|
7
|
+
[Reference](https://www.rev.com/api/docs) | [RDocs](http://rubydoc.info/github/revdotcom/rev-ruby-sdk/master/frames)
|
8
|
+
|
9
|
+
rev-ruby-sdk
|
10
|
+
------------
|
11
|
+
|
12
|
+
### Background
|
13
|
+
|
14
|
+
Rev.com provides transcription and translation services powered by humans. The Rev.com API allows you to tap these services
|
15
|
+
with no manual steps. It's a RESTful API, documented at <https://www.rev.com/api/docs>.
|
16
|
+
|
17
|
+
The Ruby SDK for the Rev API provides a convenient Ruby wrapper for the Rev.com API. All operations of the API, as described
|
18
|
+
at <https://www.rev.com/api/operations>, are supported.
|
19
|
+
|
20
|
+
### Install
|
21
|
+
|
22
|
+
```shell
|
23
|
+
gem install rev-api
|
24
|
+
```
|
25
|
+
|
26
|
+
or put it into your Gemfile.
|
27
|
+
|
28
|
+
When you need it:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'rev-api'
|
32
|
+
```
|
33
|
+
|
34
|
+
### Authentication
|
35
|
+
|
36
|
+
If you are building a new API client, you must first obtain a client API key, which you can do at <https://www.rev.com/api>.
|
37
|
+
|
38
|
+
All operations in the API are performed on behalf of a Rev customer, identified by their user API key. The client key / user
|
39
|
+
key pair is used to authenticate each API operation. Once you have the two keys, you can create a new Rev.com API client:
|
40
|
+
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'rev-api'
|
44
|
+
|
45
|
+
rev_client = Rev.new('your_client_key', 'your_user_key')
|
46
|
+
```
|
47
|
+
|
48
|
+
You can read more about authentication in the Rev.com API at <https://www.rev.com/api/security>
|
49
|
+
|
50
|
+
### Sandbox
|
51
|
+
|
52
|
+
All operations can be executed against either the production or the sandbox environment. The sandbox environment allows you
|
53
|
+
to test your API client without actually paying for orders and having them worked on.
|
54
|
+
|
55
|
+
By default, the Rev.com API client executes against the production environment. To go against the sandbox instead,
|
56
|
+
initialize the client this way:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'rev-api'
|
60
|
+
|
61
|
+
rev_client = Rev.new('your_client_key', 'your_user_key', Rev::Api::SANDBOX_HOST)
|
62
|
+
```
|
63
|
+
|
64
|
+
### Usage
|
65
|
+
|
66
|
+
The snippets below assume you've initialized `rev_client`:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
rev_client = Rev.new('your_client_key', 'your_user_key')
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Listing orders
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
orders_page = rev_client.get_orders_page(1); # get a single page of orders
|
76
|
+
all_orders = rev_client.get_all_orders; # get first page of orders history
|
77
|
+
orders_by_client_ref = rev_client.get_orders_by_client_ref('some_ref'); # get orders with reference id of 'some_ref'
|
78
|
+
```
|
79
|
+
|
80
|
+
#### Get a single order by order number
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
some_order = rev_client.get_order('TCxxxxxxxx')
|
84
|
+
puts "Original comment: #{some_order.comments.first.text}"
|
85
|
+
```
|
86
|
+
|
87
|
+
#### Cancel an order given an order number
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
rev_client.cancel_order('TCxxxxxxxx')
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Print out the text of all transcripts in an order
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
order = rev_client.get_order('TCxxxxxxx')
|
97
|
+
|
98
|
+
order.transcripts.each do |t|
|
99
|
+
puts rev_client.get_attachment_content_as_string t.id
|
100
|
+
puts
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
Refer to `cli.rb` in the `examples` directory for a full example illustrating placing orders, handling error responses, etc.
|
105
|
+
|
106
|
+
### Documentation
|
107
|
+
|
108
|
+
[YARD documentation](http://rubydoc.info/github/revdotcom/rev-ruby-sdk/master/frames) can be generated locally by running `rake yard` command, and will be placed in the `doc` directory.
|
109
|
+
|
110
|
+
You can find API documentation at <https://www.rev.com/api/docs>.
|
111
|
+
|
112
|
+
### Support
|
113
|
+
|
114
|
+
If you have any questions or suggestions for improvement, email us directly at api[at]rev[dot]com.
|
115
|
+
|
116
|
+
### Compatibility
|
117
|
+
|
118
|
+
- MRI 2.0.0
|
119
|
+
|
120
|
+
### Tests
|
121
|
+
|
122
|
+
Minitest suite might be run using `rake test` command.
|
123
|
+
Current stack:
|
124
|
+
|
125
|
+
- minitest
|
126
|
+
- webmock
|
127
|
+
- vcr
|
128
|
+
- turn
|
129
|
+
|
130
|
+
### Dependencies
|
131
|
+
|
132
|
+
- httparty
|
data/Rakefile
CHANGED
@@ -1,14 +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
|
-
|
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
14
|
task :default => :test
|
data/examples/cli.rb
CHANGED
@@ -1,270 +1,270 @@
|
|
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 get_by_client_ref list transcripts captions dl_transcripts dl_captions dl_sources place_tc place_cp 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 get_by_client_ref(args)
|
98
|
-
# client ref can contain spaces, so we have to join client ref from pieces
|
99
|
-
if (args.last == '0' || args.last.to_i > 0)
|
100
|
-
client_ref = args[0..-2].join(' ')
|
101
|
-
else
|
102
|
-
client_ref = args.join(' ')
|
103
|
-
end
|
104
|
-
|
105
|
-
client_ref = client_ref.gsub('\'', '').gsub('"', '')
|
106
|
-
page = args.last.nil? ? 0: args.last.to_i
|
107
|
-
|
108
|
-
orders_first_page = @rev_client.get_orders_by_client_ref(client_ref, page)
|
109
|
-
puts "Found #{orders_first_page.total_count} order(s), showing page #{page}. Pass page number as second argument"
|
110
|
-
orders_first_page.orders.each { |o| puts ("#{o.client_ref}: #{o.order_number}") }
|
111
|
-
|
112
|
-
puts "There are no orders associated with the given client reference: #{client_ref}" if orders_first_page.orders.empty?
|
113
|
-
end
|
114
|
-
|
115
|
-
def transcripts(args)
|
116
|
-
begin
|
117
|
-
order_num = args[0]
|
118
|
-
order = @rev_client.get_order order_num
|
119
|
-
|
120
|
-
if order.transcripts.empty?
|
121
|
-
puts "There are no transcripts for order #{order_num}"
|
122
|
-
return
|
123
|
-
end
|
124
|
-
|
125
|
-
order.transcripts.each do |t|
|
126
|
-
puts "Contents of #{t.name}"
|
127
|
-
puts "-----------------------------------"
|
128
|
-
puts @rev_client.get_attachment_content_as_string t.id
|
129
|
-
puts
|
130
|
-
end
|
131
|
-
rescue Rev::BadRequestError => e
|
132
|
-
puts "Displaying transcripts failed with error code #{e.code}, message #{e.message}"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def captions(args)
|
137
|
-
begin
|
138
|
-
order_num = args[0]
|
139
|
-
order = @rev_client.get_order order_num
|
140
|
-
|
141
|
-
if order.captions.empty?
|
142
|
-
puts "There are no captions for order #{order_num}"
|
143
|
-
return
|
144
|
-
end
|
145
|
-
|
146
|
-
order.captions.each do |t|
|
147
|
-
puts "Contents of #{t.name}"
|
148
|
-
puts "-----------------------------------"
|
149
|
-
puts @rev_client.get_attachment_content(t.id).body
|
150
|
-
puts
|
151
|
-
end
|
152
|
-
rescue Rev::BadRequestError => e
|
153
|
-
puts "Displaying captions failed with error code #{e.code}, message #{e.message}"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def dl_transcripts(args)
|
158
|
-
begin
|
159
|
-
order_num = args[0]
|
160
|
-
order = @rev_client.get_order order_num
|
161
|
-
|
162
|
-
if order.transcripts.empty?
|
163
|
-
puts "There are no transcripts for order #{order_num}"
|
164
|
-
return
|
165
|
-
end
|
166
|
-
|
167
|
-
filenames = order.transcripts.map { |t| t.name}.join(',')
|
168
|
-
puts "Downloading files: #{filenames}"
|
169
|
-
order.transcripts.each do |t|
|
170
|
-
@rev_client.save_attachment_content t.id, t.name
|
171
|
-
end
|
172
|
-
rescue Rev::BadRequestError => e
|
173
|
-
puts "Downloading transcripts failed with error code #{e.code}, message #{e.message}"
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
def dl_captions(args)
|
178
|
-
begin
|
179
|
-
order_num = args[0]
|
180
|
-
order = @rev_client.get_order order_num
|
181
|
-
|
182
|
-
if order.captions.empty?
|
183
|
-
puts "There are no captions for order #{order_num}"
|
184
|
-
return
|
185
|
-
end
|
186
|
-
|
187
|
-
filenames = order.captions.map { |t| t.name}.join(',')
|
188
|
-
puts "Downloading files: #{filenames}"
|
189
|
-
order.captions.each do |t|
|
190
|
-
@rev_client.save_attachment_content t.id, t.name
|
191
|
-
end
|
192
|
-
rescue Rev::BadRequestError => e
|
193
|
-
puts "Downloading captions failed with error code #{e.code}, message #{e.message}"
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
def dl_sources(args)
|
198
|
-
begin
|
199
|
-
order_num = args[0]
|
200
|
-
order = @rev_client.get_order order_num
|
201
|
-
|
202
|
-
if order.sources.empty?
|
203
|
-
puts "There are no source files for order #{order_num}"
|
204
|
-
return
|
205
|
-
end
|
206
|
-
|
207
|
-
filenames = order.sources.map { |t| t.name }.join(',')
|
208
|
-
puts "Downloading files: #{filenames}"
|
209
|
-
order.sources.each do |t|
|
210
|
-
@rev_client.save_attachment_content t.id, t.name
|
211
|
-
end
|
212
|
-
rescue Rev::BadRequestError => e
|
213
|
-
puts "Downloading sources failed with error code #{e.code}, message #{e.message}"
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
def cancel(args)
|
218
|
-
begin
|
219
|
-
order_num = args[0]
|
220
|
-
@rev_client.cancel_order order_num
|
221
|
-
puts "Order #{order_num} cancelled"
|
222
|
-
rescue Rev::BadRequestError => e
|
223
|
-
puts "Cancelling order failed with error code #{e.code}, message #{e.message}"
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
def place_tc(args)
|
228
|
-
input_urls = upload(args, 'audio/mpeg')
|
229
|
-
inputs = input_urls.map { |url| Rev::Input.new(:uri => url, :audio_length_seconds => 180) }
|
230
|
-
tc_options = Rev::TranscriptionOptions.new(inputs)
|
231
|
-
place_helper(inputs, { :transcription_options => tc_options })
|
232
|
-
end
|
233
|
-
|
234
|
-
def place_cp(args)
|
235
|
-
input_urls = upload(args, 'video/mpeg')
|
236
|
-
inputs = input_urls.map { |url| Rev::Input.new(:uri => url, :video_length_seconds => 180) }
|
237
|
-
cp_options = Rev::CaptionOptions.new(inputs, {:output_file_formats => [Rev::CaptionOptions::OUTPUT_FILE_FORMATS[:scc]] })
|
238
|
-
place_helper(inputs, { :caption_options => cp_options })
|
239
|
-
end
|
240
|
-
|
241
|
-
def help(*args)
|
242
|
-
puts "commands are: #{COMMANDS.join(' ')} exit"
|
243
|
-
end
|
244
|
-
|
245
|
-
private
|
246
|
-
|
247
|
-
def upload(args, type)
|
248
|
-
input_urls = args.map do |f|
|
249
|
-
puts "Uploading #{f}"
|
250
|
-
@rev_client.upload_input(f, type)
|
251
|
-
end
|
252
|
-
input_urls
|
253
|
-
end
|
254
|
-
|
255
|
-
def place_helper(inputs, options)
|
256
|
-
options = options.merge({ :client_ref => 'XB432423', :comment => 'Please work quickly' })
|
257
|
-
request = Rev::OrderRequest.new(options)
|
258
|
-
|
259
|
-
begin
|
260
|
-
new_order = @rev_client.submit_order(request)
|
261
|
-
puts "New order: #{new_order}"
|
262
|
-
rescue Rev::BadRequestError => e
|
263
|
-
puts "Order placement failed with error code #{e.code}, message #{e.message}"
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
end
|
268
|
-
|
269
|
-
cli = RevCLI.new
|
270
|
-
cli.command_loop
|
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 get_by_client_ref list transcripts captions dl_transcripts dl_captions dl_sources place_tc place_cp 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 get_by_client_ref(args)
|
98
|
+
# client ref can contain spaces, so we have to join client ref from pieces
|
99
|
+
if (args.last == '0' || args.last.to_i > 0)
|
100
|
+
client_ref = args[0..-2].join(' ')
|
101
|
+
else
|
102
|
+
client_ref = args.join(' ')
|
103
|
+
end
|
104
|
+
|
105
|
+
client_ref = client_ref.gsub('\'', '').gsub('"', '')
|
106
|
+
page = args.last.nil? ? 0: args.last.to_i
|
107
|
+
|
108
|
+
orders_first_page = @rev_client.get_orders_by_client_ref(client_ref, page)
|
109
|
+
puts "Found #{orders_first_page.total_count} order(s), showing page #{page}. Pass page number as second argument"
|
110
|
+
orders_first_page.orders.each { |o| puts ("#{o.client_ref}: #{o.order_number}") }
|
111
|
+
|
112
|
+
puts "There are no orders associated with the given client reference: #{client_ref}" if orders_first_page.orders.empty?
|
113
|
+
end
|
114
|
+
|
115
|
+
def transcripts(args)
|
116
|
+
begin
|
117
|
+
order_num = args[0]
|
118
|
+
order = @rev_client.get_order order_num
|
119
|
+
|
120
|
+
if order.transcripts.empty?
|
121
|
+
puts "There are no transcripts for order #{order_num}"
|
122
|
+
return
|
123
|
+
end
|
124
|
+
|
125
|
+
order.transcripts.each do |t|
|
126
|
+
puts "Contents of #{t.name}"
|
127
|
+
puts "-----------------------------------"
|
128
|
+
puts @rev_client.get_attachment_content_as_string t.id
|
129
|
+
puts
|
130
|
+
end
|
131
|
+
rescue Rev::BadRequestError => e
|
132
|
+
puts "Displaying transcripts failed with error code #{e.code}, message #{e.message}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def captions(args)
|
137
|
+
begin
|
138
|
+
order_num = args[0]
|
139
|
+
order = @rev_client.get_order order_num
|
140
|
+
|
141
|
+
if order.captions.empty?
|
142
|
+
puts "There are no captions for order #{order_num}"
|
143
|
+
return
|
144
|
+
end
|
145
|
+
|
146
|
+
order.captions.each do |t|
|
147
|
+
puts "Contents of #{t.name}"
|
148
|
+
puts "-----------------------------------"
|
149
|
+
puts @rev_client.get_attachment_content(t.id).body
|
150
|
+
puts
|
151
|
+
end
|
152
|
+
rescue Rev::BadRequestError => e
|
153
|
+
puts "Displaying captions failed with error code #{e.code}, message #{e.message}"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def dl_transcripts(args)
|
158
|
+
begin
|
159
|
+
order_num = args[0]
|
160
|
+
order = @rev_client.get_order order_num
|
161
|
+
|
162
|
+
if order.transcripts.empty?
|
163
|
+
puts "There are no transcripts for order #{order_num}"
|
164
|
+
return
|
165
|
+
end
|
166
|
+
|
167
|
+
filenames = order.transcripts.map { |t| t.name}.join(',')
|
168
|
+
puts "Downloading files: #{filenames}"
|
169
|
+
order.transcripts.each do |t|
|
170
|
+
@rev_client.save_attachment_content t.id, t.name
|
171
|
+
end
|
172
|
+
rescue Rev::BadRequestError => e
|
173
|
+
puts "Downloading transcripts failed with error code #{e.code}, message #{e.message}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def dl_captions(args)
|
178
|
+
begin
|
179
|
+
order_num = args[0]
|
180
|
+
order = @rev_client.get_order order_num
|
181
|
+
|
182
|
+
if order.captions.empty?
|
183
|
+
puts "There are no captions for order #{order_num}"
|
184
|
+
return
|
185
|
+
end
|
186
|
+
|
187
|
+
filenames = order.captions.map { |t| t.name}.join(',')
|
188
|
+
puts "Downloading files: #{filenames}"
|
189
|
+
order.captions.each do |t|
|
190
|
+
@rev_client.save_attachment_content t.id, t.name
|
191
|
+
end
|
192
|
+
rescue Rev::BadRequestError => e
|
193
|
+
puts "Downloading captions failed with error code #{e.code}, message #{e.message}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def dl_sources(args)
|
198
|
+
begin
|
199
|
+
order_num = args[0]
|
200
|
+
order = @rev_client.get_order order_num
|
201
|
+
|
202
|
+
if order.sources.empty?
|
203
|
+
puts "There are no source files for order #{order_num}"
|
204
|
+
return
|
205
|
+
end
|
206
|
+
|
207
|
+
filenames = order.sources.map { |t| t.name }.join(',')
|
208
|
+
puts "Downloading files: #{filenames}"
|
209
|
+
order.sources.each do |t|
|
210
|
+
@rev_client.save_attachment_content t.id, t.name
|
211
|
+
end
|
212
|
+
rescue Rev::BadRequestError => e
|
213
|
+
puts "Downloading sources failed with error code #{e.code}, message #{e.message}"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def cancel(args)
|
218
|
+
begin
|
219
|
+
order_num = args[0]
|
220
|
+
@rev_client.cancel_order order_num
|
221
|
+
puts "Order #{order_num} cancelled"
|
222
|
+
rescue Rev::BadRequestError => e
|
223
|
+
puts "Cancelling order failed with error code #{e.code}, message #{e.message}"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def place_tc(args)
|
228
|
+
input_urls = upload(args, 'audio/mpeg')
|
229
|
+
inputs = input_urls.map { |url| Rev::Input.new(:uri => url, :audio_length_seconds => 180) }
|
230
|
+
tc_options = Rev::TranscriptionOptions.new(inputs)
|
231
|
+
place_helper(inputs, { :transcription_options => tc_options })
|
232
|
+
end
|
233
|
+
|
234
|
+
def place_cp(args)
|
235
|
+
input_urls = upload(args, 'video/mpeg')
|
236
|
+
inputs = input_urls.map { |url| Rev::Input.new(:uri => url, :video_length_seconds => 180) }
|
237
|
+
cp_options = Rev::CaptionOptions.new(inputs, {:output_file_formats => [Rev::CaptionOptions::OUTPUT_FILE_FORMATS[:scc]] })
|
238
|
+
place_helper(inputs, { :caption_options => cp_options })
|
239
|
+
end
|
240
|
+
|
241
|
+
def help(*args)
|
242
|
+
puts "commands are: #{COMMANDS.join(' ')} exit"
|
243
|
+
end
|
244
|
+
|
245
|
+
private
|
246
|
+
|
247
|
+
def upload(args, type)
|
248
|
+
input_urls = args.map do |f|
|
249
|
+
puts "Uploading #{f}"
|
250
|
+
@rev_client.upload_input(f, type)
|
251
|
+
end
|
252
|
+
input_urls
|
253
|
+
end
|
254
|
+
|
255
|
+
def place_helper(inputs, options)
|
256
|
+
options = options.merge({ :client_ref => 'XB432423', :comment => 'Please work quickly' })
|
257
|
+
request = Rev::OrderRequest.new(options)
|
258
|
+
|
259
|
+
begin
|
260
|
+
new_order = @rev_client.submit_order(request)
|
261
|
+
puts "New order: #{new_order}"
|
262
|
+
rescue Rev::BadRequestError => e
|
263
|
+
puts "Order placement failed with error code #{e.code}, message #{e.message}"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
cli = RevCLI.new
|
270
|
+
cli.command_loop
|