unbabel 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4005346914d2c63457a1b5c7169bd58cee40aee5
4
+ data.tar.gz: 3ed086012c74df6dcafe171638fc7f430fffc7d4
5
+ SHA512:
6
+ metadata.gz: 6d7a90a752d671182df26361902d00975f3aaa6439d9ff27d060abd237f5199c8c79fb8b3534bfe52638f3340c4bd056ec4f8b09d25440c082129c859d746a21
7
+ data.tar.gz: ad5da31135058fbf4d5cb64534e4fda5c2e1b5125501a6c99637a0d95102db192ceb01a9ca8226b2de73ab26b8dd01d823f6dfa3e3b49bbdcb27969bc6d35a6b
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ unbabel_api/
2
+ *.DS_Store
3
+ creds
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'pry'
7
+ gem 'pry-nav'
8
+ gem 'rspec'
9
+ gem 'webmock'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unbabel (0.0.1)
5
+ unirest (~> 1.1.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.6)
11
+ coderay (1.1.0)
12
+ crack (0.4.2)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.2.5)
15
+ json (1.8.1)
16
+ method_source (0.8.2)
17
+ mime-types (1.25.1)
18
+ pry (0.10.1)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.8.1)
21
+ slop (~> 3.4)
22
+ pry-nav (0.2.4)
23
+ pry (>= 0.9.10, < 0.11.0)
24
+ rake (10.3.2)
25
+ rdoc (4.1.2)
26
+ json (~> 1.4)
27
+ rest-client (1.6.8)
28
+ mime-types (~> 1.16)
29
+ rdoc (>= 2.4.2)
30
+ rspec (3.1.0)
31
+ rspec-core (~> 3.1.0)
32
+ rspec-expectations (~> 3.1.0)
33
+ rspec-mocks (~> 3.1.0)
34
+ rspec-core (3.1.7)
35
+ rspec-support (~> 3.1.0)
36
+ rspec-expectations (3.1.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.1.0)
39
+ rspec-mocks (3.1.3)
40
+ rspec-support (~> 3.1.0)
41
+ rspec-support (3.1.2)
42
+ safe_yaml (1.0.4)
43
+ slop (3.6.0)
44
+ unirest (1.1.2)
45
+ addressable (~> 2.3.5)
46
+ json (~> 1.8.1)
47
+ rest-client (~> 1.6.7)
48
+ webmock (1.20.0)
49
+ addressable (>= 2.3.6)
50
+ crack (>= 0.3.2)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ bundler (~> 1.7)
57
+ pry
58
+ pry-nav
59
+ rake (~> 10.0)
60
+ rspec
61
+ unbabel!
62
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Silva
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.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Unbabel Ruby Wrapper
2
+
3
+ [Unbabel](https://unbabel.com/) is a translation as a service, this is a ruby wrapper around their [API](https://github.com/Unbabel/unbabel_api).
4
+
5
+ Happy Translations!
6
+
7
+
8
+ ## Configuration
9
+
10
+ ```ruby
11
+
12
+ client = Unbabel::Client.new do |conf|
13
+ conf.username = ENV['UNBABEL_USERNAME']
14
+ conf.token = ENV['UNBABEL_TOKEN']
15
+ end
16
+
17
+ ```
18
+
19
+ # Sandbox mode
20
+
21
+ If you want to help developing this library user the following ENV variable.
22
+
23
+ ```shell
24
+ export UNBABEL_SANDBOX="true"
25
+ ```
26
+
27
+ ## Available methods
28
+
29
+ ```ruby
30
+ client.language_pairs # lists available language pairs
31
+ client.topics # lists available topics
32
+ client.tones # lists available tones
33
+ client.translations # lists translations
34
+ client.translations.find(uid) # finds a translation by unique id
35
+ client.translations.request # requests a new translation
36
+ ```
37
+
38
+ ### Sample
39
+
40
+ ```
41
+ irb(main):009:0> client.topics
42
+ => [{"topic"=>{"name"=>"politics"}}, {"topic"=>{"name"=>"gossip"}}, {"topic"=>{"name"=>"sex & relationships"}}, {"topic"=>{"name"=>"crafts"}}, {"topic"=>{"name"=>"parenting"}}, {"topic"=>{"name"=>"startups"}}, {"topic"=>{"name"=>"tech"}}, {"topic"=>{"name"=>"sports"}}]
43
+ ```
44
+
45
+ ## Available soon
46
+
47
+ - Ability of bulk request translations
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/davidslv/unbabel-ruby-wrapper/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,46 @@
1
+ module Unbabel
2
+ class Client
3
+ TEST_MODE = ENV['UNBABEL_SANDBOX'] == 'true'
4
+ SANDBOX = 'http://sandbox.unbabel.com/tapi/v2'
5
+ ENDPOINT = TEST_MODE ? SANDBOX : 'https://unbabel.com/tapi/v2'
6
+
7
+ include Unbabel::LanguangePair
8
+ include Unbabel::Topic
9
+ include Unbabel::Tone
10
+ include Unbabel::Translation
11
+
12
+ attr_accessor :username, :token
13
+
14
+
15
+ def initialize(options = {})
16
+ @username = options[:username]
17
+ @token = options[:token]
18
+
19
+ yield(self) if block_given?
20
+ validate_credentials!
21
+ Unirest.default_header('Content-Type', 'application/json')
22
+ Unirest.default_header('Authorization', "ApiKey #{@username}:#{@token}")
23
+ end
24
+
25
+ def credentials
26
+ {
27
+ username: username,
28
+ token: token
29
+ }
30
+ end
31
+
32
+ def credentials?
33
+ credentials.values.all?
34
+ end
35
+
36
+ private
37
+ # Ensures that all necessary credentials
38
+ # are set during configuration.
39
+ def validate_credentials!
40
+ credentials.each do |credential, value|
41
+ next if !value.nil? && value.is_a?(String)
42
+ fail(ArgumentError.new("Invalid #{credential}, it's value: #{value.inspect} must be a string."))
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ module Unbabel
2
+ module LanguangePair
3
+ def language_pairs
4
+ response = Unirest.get("#{Unbabel::Client::ENDPOINT}/language_pair")
5
+ response.body['objects']
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Unbabel
2
+ module Tone
3
+ def tones
4
+ response = Unirest.get("#{Unbabel::Client::ENDPOINT}/tone")
5
+ response.body['objects']
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Unbabel
2
+ module Topic
3
+ def topics
4
+ response = Unirest.get("#{Unbabel::Client::ENDPOINT}/topic")
5
+ response.body['objects']
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,38 @@
1
+ module Unbabel
2
+ module Translation
3
+
4
+ # finds a translation by it's unique id
5
+ def find(uid)
6
+ response = Unirest.get("#{Unbabel::Client::ENDPOINT}/translation/#{uid}")
7
+ response.body
8
+ end
9
+
10
+ # text (required) - the text to be translated.
11
+ # target_language (required) - the language to translate the text to.
12
+ # source_language - the language of text. If not supplemented it will be auto detected from the text.
13
+ # text_format - The format of the text to be translated [one of text,html].
14
+ # target_text - initial version of the text to be post-edited.
15
+ # uid - A unique identifier for the job. If one is not supplied the system will provide one.
16
+ # callback_url - Once the job is done the result will be posted to this endpoint.
17
+ # formality (optional) - The tone that should be used in the translation.
18
+ # instructions (optional) - Client instructions for the translator.
19
+ # topics (optional) - List of the topics of text.
20
+ def request(params = {})
21
+ response = Unirest.post("#{Unbabel::Client::ENDPOINT}/translation/",
22
+ parameters: params.to_json)
23
+ response.body
24
+ end
25
+
26
+ # status are
27
+ # 'new' - The translation has been created and is being pre-processed
28
+ # 'ready' - The translation is ready to be processed in the unbabel platform.
29
+ # 'in_progress' - The translation is being executed
30
+ # 'delivered' - The translation has already been returned to the client (either using the endpoint or query for a translation)
31
+ def translations(status = nil)
32
+ status = "?#{status}" if status
33
+
34
+ response = Unirest.get("#{Unbabel::Client::ENDPOINT}/translation/#{status}")
35
+ response.body['objects']
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Unbabel
2
+ VERSION = "0.0.1"
3
+ end
data/lib/unbabel.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'unbabel/version'
2
+ require 'unirest'
3
+
4
+ module Unbabel
5
+ require 'unbabel/language_pair'
6
+ require 'unbabel/tone'
7
+ require 'unbabel/topic'
8
+ require 'unbabel/translation'
9
+ require 'unbabel/client'
10
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Unbabel::Client do
4
+ subject { described_class }
5
+
6
+ describe '#new' do
7
+ context 'when there is username' do
8
+ it 'should raise an ArgumentError' do
9
+ expect {
10
+ subject.new
11
+ }.to raise_error(ArgumentError, /username/)
12
+ end
13
+ end
14
+
15
+ context 'when there is no token' do
16
+ it 'should raise an ArgumentError' do
17
+ expect {
18
+ subject.new(username: 'd')
19
+ }.to raise_error(ArgumentError, /token/)
20
+ end
21
+ end
22
+
23
+ context 'when there is username and token' do
24
+ it 'should not raise any ArgumentError' do
25
+ expect {
26
+ subject.new(username: 'd', token: '123')
27
+ }.to_not raise_error
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Unbabel::Topic do
4
+ end
@@ -0,0 +1,73 @@
1
+ require 'pry'
2
+
3
+ require_relative '../lib/unbabel'
4
+
5
+ require 'webmock/rspec'
6
+
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ # rspec-expectations config goes here. You can use an alternate
10
+ # assertion/expectation library such as wrong or the stdlib/minitest
11
+ # assertions if you prefer.
12
+ config.expect_with :rspec do |expectations|
13
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
14
+ end
15
+
16
+ # rspec-mocks config goes here. You can use an alternate test double
17
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
18
+ config.mock_with :rspec do |mocks|
19
+ # Prevents you from mocking or stubbing a method that does not exist on
20
+ # a real object. This is generally recommended, and will default to
21
+ # `true` in RSpec 4.
22
+ mocks.verify_partial_doubles = true
23
+ end
24
+
25
+ # The settings below are suggested to provide a good initial experience
26
+ # with RSpec, but feel free to customize to your heart's content.
27
+ =begin
28
+ # These two settings work together to allow you to limit a spec run
29
+ # to individual examples or groups you care about by tagging them with
30
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
31
+ # get run.
32
+ config.filter_run :focus
33
+ config.run_all_when_everything_filtered = true
34
+
35
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
36
+ # For more details, see:
37
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
38
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
39
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
40
+ config.disable_monkey_patching!
41
+
42
+ # This setting enables warnings. It's recommended, but in some cases may
43
+ # be too noisy due to issues in dependencies.
44
+ config.warnings = true
45
+
46
+ # Many RSpec users commonly either run the entire suite or an individual
47
+ # file, and it's useful to allow more verbose output when running an
48
+ # individual spec file.
49
+ if config.files_to_run.one?
50
+ # Use the documentation formatter for detailed output,
51
+ # unless a formatter has already been configured
52
+ # (e.g. via a command-line flag).
53
+ config.default_formatter = 'doc'
54
+ end
55
+
56
+ # Print the 10 slowest examples and example groups at the
57
+ # end of the spec run, to help surface which specs are running
58
+ # particularly slow.
59
+ config.profile_examples = 10
60
+
61
+ # Run specs in random order to surface order dependencies. If you find an
62
+ # order dependency and want to debug it, you can fix the order by providing
63
+ # the seed, which is printed after each run.
64
+ # --seed 1234
65
+ config.order = :random
66
+
67
+ # Seed global randomization in this process using the `--seed` CLI option.
68
+ # Setting this allows you to use `--seed` to deterministically reproduce
69
+ # test failures related to randomization by passing the same `--seed` value
70
+ # as the one that triggered the failure.
71
+ Kernel.srand config.seed
72
+ =end
73
+ end
data/unbabel.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'unbabel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "unbabel"
8
+ spec.version = Unbabel::VERSION
9
+ spec.authors = ["David Silva"]
10
+ spec.email = ["davidslv@gmail.com"]
11
+ spec.summary = %q{A wrapper for Unbabel API.}
12
+ spec.description = %q{Unbabel is a translation as a service, this is a ruby wrapper around their API.}
13
+ spec.homepage = "http://davidslv.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.required_ruby_version = '>= 1.9.3'
24
+ spec.add_development_dependency "rspec", '~> 3.1', '>= 3.1.0'
25
+
26
+ spec.add_runtime_dependency 'unirest', '~> 1.1', '>= 1.1.2'
27
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unbabel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Silva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-22 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.1.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.1.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: unirest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.1'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.1.2
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.1'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.1.2
81
+ description: Unbabel is a translation as a service, this is a ruby wrapper around
82
+ their API.
83
+ email:
84
+ - davidslv@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".ruby-version"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/unbabel.rb
98
+ - lib/unbabel/client.rb
99
+ - lib/unbabel/language_pair.rb
100
+ - lib/unbabel/tone.rb
101
+ - lib/unbabel/topic.rb
102
+ - lib/unbabel/translation.rb
103
+ - lib/unbabel/version.rb
104
+ - spec/lib/unbabel/client_spec.rb
105
+ - spec/lib/unbabel/topic_spec.rb
106
+ - spec/spec_helper.rb
107
+ - unbabel.gemspec
108
+ homepage: http://davidslv.com
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 1.9.3
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A wrapper for Unbabel API.
132
+ test_files:
133
+ - spec/lib/unbabel/client_spec.rb
134
+ - spec/lib/unbabel/topic_spec.rb
135
+ - spec/spec_helper.rb
136
+ has_rdoc: