cielo24 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9e4dc072024de29bb1c0ae47f5c405b3540ea703
4
+ data.tar.gz: bf4e0476af267ce414663ccf50f4a8b353dab131
5
+ SHA512:
6
+ metadata.gz: 970bf712df6d087537ae83db28563e8bd1d109427adc42fdff141c99ff0ea407b3e12af1fe07bbf95120944b57752f6bfc01f02ea0d268a26792bf4aea1b538e
7
+ data.tar.gz: dfa41a39b01104ee353f6627835442e9a3e25d7ab386493d9996c4a841888a52a77adbc81cc8a18e1ed9e15dfd42a174ae44c4ca4d3d471fe2846e0de5b6072d
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cielo24.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alan Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ # Cielo24
2
+
3
+ Cielo24 is a service for creating video captions and transcripts. This library interacts with the Cielo24 API to submit and retrieve captions.
4
+
5
+ This is currently an incomplete implementation fo the Cielo24 API to solve my personal needs. Feel free to send a pull request if you want to complete more of the API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'cielo24'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cielo24
20
+
21
+ ## Usage
22
+
23
+ ### Authentication:
24
+
25
+ The Cielo24 team recommend password based authentication, so to configure your username and password:
26
+
27
+ ```
28
+ Cielo24::Client.configure(username: "user", password: "somepass")
29
+ ```
30
+
31
+ You may also authenticate through the Cielo24 sandbox with the following settings (use your own sandbox username and password):
32
+
33
+ ```
34
+ Cielo24::Client.configure(username: "treehouse", password: "p@ssw0rd",
35
+ uri: "https://sandbox.cogi.com", verify_mode: OpenSSL::SSL::VERIFY_NONE)
36
+ ```
37
+
38
+ ### Submitting a video for captioning:
39
+
40
+ ```
41
+ client = Cielo24::Client.new
42
+ job_id = client.create_job("Test Job")
43
+ client.add_media(job_id, "http://test.com/my-media.mp4")
44
+ task_id = client.perform_transcription(job_id)
45
+ ```
46
+
47
+ Captioning defaults to professional fidelity and standard priority.
48
+
49
+ ### Checking if captions are complete:
50
+
51
+ ```
52
+ client = Cielo24::Client.new
53
+ client.task_complete?(task_id)
54
+ ```
55
+
56
+ ### Downloading captions
57
+
58
+ ```
59
+ client = Cielo24::Client.new
60
+ data = client.get_caption(job_id)
61
+ ```
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cielo24/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cielo24"
8
+ spec.version = Cielo24::VERSION
9
+ spec.authors = ["Alan Johnson"]
10
+ spec.email = ["alan@teamtreehouse.com"]
11
+ spec.description = %q{Library for submitting and requesting captions from Cielo24.}
12
+ spec.summary = %q{Submit and request captions through Cielo24.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14.1"
24
+
25
+ spec.add_dependency "httpclient", "~> 2.3.4.1"
26
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'cielo24/version'
2
+ require_relative 'cielo24/authentication'
3
+ require_relative 'cielo24/jobs'
4
+ require_relative 'cielo24/client'
5
+
6
+ require 'uri'
7
+ require 'httpclient'
8
+ require 'json'
9
+
10
+ module Cielo24
11
+ end
@@ -0,0 +1,11 @@
1
+ module Cielo24
2
+ # Methods for authenticating.
3
+ module Authentication
4
+
5
+ # Public: Get a api token for this session.
6
+ def log_in(username, password)
7
+ data = get_json("/api/account/login", {username: username, password: password})
8
+ data["ApiToken"]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,83 @@
1
+ module Cielo24
2
+
3
+ # Class for interacting with the Cielo24 API.
4
+ class Client
5
+ include Cielo24::Authentication
6
+ include Cielo24::Jobs
7
+
8
+ attr_accessor :connection
9
+ attr_accessor :token
10
+
11
+ DEFAULT_URI = "https://api.cielo24.com"
12
+ VERSION = 1
13
+ VERIFY_MODE = nil
14
+
15
+ # Public: Configures the connection.
16
+ #
17
+ # options - the configuration options for use with Cielo24.
18
+ # :username - The username to use for authentication.
19
+ # :password - The password to use for authentication.
20
+ # :uri - The uri to use for requests. Defaults to the Cielo24 API URI.
21
+ def self.configure(options = {})
22
+ @options = {uri: DEFAULT_URI, version: VERSION, verify_mode: VERIFY_MODE}.merge(options)
23
+ end
24
+
25
+ # Internal: Our configuration settings for Cielo24.
26
+ def self.options
27
+ @options ||= {}
28
+ end
29
+
30
+ def initialize
31
+ self.connection = connect
32
+
33
+ # Go ahead and set up the single use token for this session
34
+ @token = log_in(self.class.options[:username], self.class.options[:password])
35
+ end
36
+
37
+ # Internal: Returns an HTTPClient connection object.
38
+ def connect
39
+ connection = HTTPClient.new
40
+ connection.cookie_manager = nil
41
+
42
+ unless self.class.options[:verify_mode] == nil
43
+ connection.ssl_config.verify_mode = self.class.options[:verify_mode]
44
+ end
45
+
46
+ return connection
47
+ end
48
+
49
+ # Internal: Makes a get request with the given parameters.
50
+ #
51
+ # path - The path to request.
52
+ # params - The parameters to include with the request.
53
+ #
54
+ # Returns the JSON for the response we received.
55
+ def get(path, params = {})
56
+ uri = URI(self.class.options[:uri])
57
+ uri.path = path
58
+
59
+ # add api version to each request
60
+ params = {v: self.class.options[:version]}.merge(params)
61
+
62
+ # add token if possible
63
+ if token
64
+ params = {api_token: token}.merge(params)
65
+ end
66
+
67
+ response = connection.get(uri, params)
68
+ if response.status_code == 200
69
+ return response.body
70
+ else
71
+ # Cielo24 always returns error messages as JSON
72
+ raise(JSON.parse(response.body)["ErrorComment"])
73
+ end
74
+ end
75
+
76
+ # Internal: Makes a request to Cielo24 and returns JSON data
77
+ def get_json(path, params)
78
+ body = get(path, params)
79
+
80
+ JSON.parse(body)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,72 @@
1
+ module Cielo24
2
+ module Jobs
3
+
4
+ # Public: Creates a new job.
5
+ #
6
+ # job_name - A human-readable name for the job to be created.
7
+ # language - An RFC 5646 Language tag indicating native job language. Defaults to ‘en’.
8
+ #
9
+ # Returns a job id for the newly created job.
10
+ def create_job(job_name, language = "en")
11
+ data = get_json("/api/job/new", {job_name: job_name, language: language})
12
+
13
+ return data["JobId"]
14
+ end
15
+
16
+ # Public: Attaches media to a job.
17
+ #
18
+ # job_id - The id of a job to attach media to.
19
+ # media_url - The URL of the media file to attach to the job.
20
+ #
21
+ # Returns the task id for the media.
22
+ def add_media(job_id, media_url)
23
+ data = get_json("/api/job/add_media", {job_id: job_id, media_url: media_url})
24
+
25
+ data["TaskId"]
26
+ end
27
+
28
+ # Public: Requests that a transcription be performed.
29
+ #
30
+ # job_id - The id of a job to attach media to.
31
+ # fidelity - Should be one of MECHANICAL, PREMIUM, or PROFESSIONAL. Default: PROFESSIONAL
32
+ # priority - Should be one of ECONOMY, STANDARD, or PRIORITY. Default: STANDARD
33
+ #
34
+ # Returns the task id for the transcription.
35
+ def perform_transcription(job_id, fidelity = "PROFESSIONAL", priority = "STANDARD")
36
+ data = get_json("/api/job/perform_transcription",
37
+ {job_id: job_id, transcription_fidelity: fidelity, priority: priority})
38
+
39
+ data["TaskId"]
40
+ end
41
+
42
+ # Public: Requests info about a particular job.
43
+ #
44
+ # job_id - The job to get info about.
45
+ #
46
+ # Returns
47
+ def job_info(job_id)
48
+ get_json("/api/job/info", {job_id: job_id})
49
+ end
50
+
51
+ # Public: Returns whether or not a task has completed.
52
+ #
53
+ # task_id - The task to check status for.
54
+ #
55
+ # Returns true if the task is complete, false otherwise.
56
+ def task_complete?(task_id)
57
+ get_json("/api/job/task_status", {task_id: task_id})["TaskStatus"] == "COMPLETED"
58
+ end
59
+
60
+ # Public: Gets the caption results from a job.
61
+ #
62
+ # job_id - The id of the job we're pulling captions for.
63
+ # caption_format - THe format for the captions. SRT, SBV, DFXP, or QT. Defaults to SRT.
64
+ # options - Additional optional parameters for requesting captions. See the Cielo24 documentation
65
+ # for the list of optional parameters.
66
+ #
67
+ # Returns the caption data as text.
68
+ def get_caption(job_id, caption_format = "SRT", options = {})
69
+ get("/api/job/get_caption", options.merge(caption_format: caption_format, job_id: job_id))
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ module Cielo24
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+
3
+ describe "Cielo24::Jobs" do
4
+
5
+ let(:client) { Cielo24::Client.new }
6
+
7
+ let(:job_id) do
8
+ stub_get_json("/api/job/new", {"JobId" => "JOB123"})
9
+ client.create_job("Test Job")
10
+ end
11
+
12
+ let(:job_with_media_id) do
13
+ stub_get_json("/api/job/add_media", {"TaskId" => "TASK123"})
14
+ client.add_media(job_id, "http://test.com/media.mp4")
15
+
16
+ job_id
17
+ end
18
+
19
+ let(:transcribed_job_id) do
20
+ stub_get_json("/api/job/perform_transcription", { "TaskId" => "TASK123"})
21
+ client.perform_transcription(job_with_media_id)
22
+
23
+ # it unfortunately takes a second to get a successful caption back from the
24
+ # sandbox
25
+ sleep(3) if test_sandbox?
26
+ end
27
+
28
+ describe "#create_job" do
29
+ it "returns the job id for the newly created job" do
30
+ stub_get_json("/api/job/new", {"JobId" => "JOB123"})
31
+ expect(client.create_job("Some New Job")).to_not be_nil
32
+ end
33
+ end
34
+
35
+ describe "#add_media" do
36
+ it "returns the task id for the media that was added" do
37
+ stub_get_json("/api/job/add_media", {"TaskId" => "TASK123"})
38
+ expect(client.add_media(job_id, "http://test.com/test_media.mp4")).to_not be_nil
39
+ end
40
+ end
41
+
42
+ describe "#perform_transcription" do
43
+ it "returns the task id for the transcription" do
44
+ stub_get_json("/api/job/perform_transcription", {"TaskId" => "TASK123"})
45
+ expect(client.perform_transcription(job_with_media_id)).to_not be_nil
46
+ end
47
+ end
48
+
49
+ describe "#task_complete?" do
50
+ it "returns true if the task has completed" do
51
+ pending("CANNOT GUARANTEE COMPLETED JOB IN SANDBOX") if test_sandbox?
52
+
53
+ stub_get_json("/api/job/task_status", {"TaskStatus" => "COMPLETED"})
54
+ expect(client.task_complete?("TASK123")).to be_true
55
+ end
56
+
57
+ it "returns false if the task hasn't completed" do
58
+ pending("CANNOT GUARANTEE INCOMPLETE JOB IN SANDBOX") if test_sandbox?
59
+
60
+ stub_get_json("/api/job/task_status", {"TaskStatus" => "INCOMPLETE"})
61
+ expect(client.task_complete?("TASK123")).to be_false
62
+ end
63
+ end
64
+
65
+ describe "get_caption" do
66
+ it "returns the captions" do
67
+ pending("SANDBOX DOESN'T ALWAYS RETURN CAPTIONS CORRECTLY") if test_sandbox?
68
+
69
+ stub_get("/api/job/get_caption", "SOME CAPTION DATA")
70
+ expect(client.get_caption(transcribed_job_id)).to_not be_nil
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,57 @@
1
+ require_relative "../lib/cielo24"
2
+
3
+ if ENV["CIELO24_SANDBOX"]
4
+ Cielo24::Client.configure(username: ENV["CIELO24_SANDBOX_USERNAME"],
5
+ password: ENV["CIELO24_SANDBOX_PASSWORD"],
6
+ uri: "https://sandbox.cogi.com", verify_mode: OpenSSL::SSL::VERIFY_NONE)
7
+ end
8
+
9
+
10
+ module Cielo24
11
+ module SpecHelpers
12
+
13
+ # Internal: Returns whether or not we're testing against the sandbox.
14
+ def test_sandbox?
15
+ !ENV["CIELO24_SANDBOX"].nil?
16
+ end
17
+
18
+ # Internal: Stubs the get_json method unless we're testing against the sandbox.
19
+ #
20
+ # path - The api path to stub.
21
+ # value - The value to return from the stubbed call.
22
+ #
23
+ # Examples:
24
+ # stub_get_json("/api/job/new", {"JobId" => "12345"})
25
+ # => get_json returns {"JobId" => "12345"}
26
+ def stub_get_json(path, value)
27
+ unless test_sandbox?
28
+ Cielo24::Client.any_instance.stub(:get_json).with(path, an_instance_of(Hash)).and_return(value)
29
+ end
30
+ end
31
+
32
+ # Internal: STubs the get method unless we're testing against the sandbox.
33
+ #
34
+ # path - The api path to stub.
35
+ # value - The value to return from the stubbed call.
36
+ #
37
+ # Examples:
38
+ # stub_get("/api/job/get_caption", "SOME CAPTION DATA")
39
+ # => get returns "SOME CAPTION DATA"
40
+ def stub_get(path, value)
41
+ unless test_sandbox?
42
+ Cielo24::Client.any_instance.stub(:get).with(path, an_instance_of(Hash)).and_return(value)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ RSpec.configure do |config|
49
+ config.include Cielo24::SpecHelpers
50
+
51
+ # Stub out logging in if needed
52
+ config.before(:each) do
53
+ unless test_sandbox?
54
+ Cielo24::Client.any_instance.stub(:log_in).and_return("FOOBARTOKEN")
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cielo24
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alan Johnson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: httpclient
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.4.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.4.1
69
+ description: Library for submitting and requesting captions from Cielo24.
70
+ email:
71
+ - alan@teamtreehouse.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - cielo24.gemspec
82
+ - lib/cielo24.rb
83
+ - lib/cielo24/authentication.rb
84
+ - lib/cielo24/client.rb
85
+ - lib/cielo24/jobs.rb
86
+ - lib/cielo24/version.rb
87
+ - spec/jobs_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.0.6
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Submit and request captions through Cielo24.
113
+ test_files:
114
+ - spec/jobs_spec.rb
115
+ - spec/spec_helper.rb
116
+ has_rdoc: