lingo24 0.1.0

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: 2108dfb28535b1d57e5529dba1bec79fda5cbae8
4
+ data.tar.gz: 988e42902edcbd3fb4ffcdbb197ae5857aaa37d6
5
+ SHA512:
6
+ metadata.gz: fc81e23d638c1a3cdb20470287a242146cf84846ec151287a4275304dcbf75ec2407270c4bce46be1bba59b7b7f622f50657f510b84da4fb561918306cec25e9
7
+ data.tar.gz: 47431caffa64bbbc407b4abe2a0ec15499e974b91028899f9378e97bf253e3ff4d218988fafc21b4273a45681447a94267a2566d8997cd37f7597f745556e204
@@ -0,0 +1,15 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lingo24.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Lingo24 Limited
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,50 @@
1
+ # Lingo24 Ruby Library for the [Lingo24 Translation API](https://developer.lingo24.com)
2
+
3
+ We love languages at Lingo24. Every day we work hard to translate documents, websites, tools and products, helping people all over the world communicate with one another.
4
+
5
+ Translating your content can be challenging, but we aim to make it very simple through easy to use tools, friendly people, and great technology.
6
+
7
+ In terms of translation, **[Lingo24](http://www.lingo24.com)** offers a range of professional human-translation and premium machine translation services, all of which can accessed via our translation APIs.
8
+
9
+ This is a Ruby interface to make using our APIs simpler.
10
+
11
+ At present the client library only provides support for our [Premium Machine Translation API](https://developer.lingo24.com/premium-machine-translation-api). Support will soon be added for our professional human-translation API.
12
+
13
+
14
+ ## Installation & Requirements
15
+
16
+ Installing the Lingo24 _gem_ is trivial, simply run the following from your command line:
17
+
18
+ ```sh
19
+ $ gem install lingo24
20
+ ```
21
+
22
+ ## Tests
23
+
24
+ We have bundled a range of tests using _rspec_ which you can read to understand how to use our API.
25
+
26
+ To run these tests you need to configure the _user_key_ within the specification file so you can call against the live API.
27
+
28
+ ## Questions, Comments, Complaints, Compliments?
29
+
30
+ If you have questions or comments and would like to reach us directly, please feel free to do so at the following outlets. We love hearing from developers!
31
+
32
+ * Email: api [at] lingo24 dot com
33
+ * Forum: [Lingo24 Developer Portal](https://developer.lingo24.com/forum)
34
+
35
+ If you come across any issues with the library, please file them on the project’s [Bitbucket issue tracker](https://bitbucket.org/lingo24/lingo24-ruby/issues).
36
+
37
+ ## Accessing Our Premium Machine Translation API
38
+ To get started with the API you first have to authenticate. You do this by using the authentication information you received when you signed up on the [Lingo24 Developer Portal](https://developer.lingo24.com).
39
+
40
+ ```ruby
41
+ require ‘lingo24’
42
+
43
+ lingo24 = Lingo24::PremiumMTAPI.new('your_user_key')
44
+ ```
45
+ If you do not have an _user_key_ please go to our [plans](https://developer.lingo24.com/plans) page to sign up for one of our access plans. This includes our free Premium Machine Translation _Taster_ plan, with free access to translate 100,000 between English, French and Spanish.
46
+
47
+
48
+ Once you have done this you are free to use the methods exposed via the API wrapper to translate text, fetch source languages and fetch target languages.
49
+
50
+ As the library is fully _rdoc_ compliant, you can browse the documentation to understand more about the methods available. You can also view the methods available on the online [Lingo24 API documentation](https://developer.lingo24.com/premium-machine-translation-api).
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new do |t|
5
+ end
6
+ task :default => :spec
7
+
@@ -0,0 +1,6 @@
1
+ require_relative 'lingo24/version'
2
+ require_relative 'lingo24/exception'
3
+ require_relative 'lingo24/language'
4
+ require_relative 'lingo24/premium_mt_api'
5
+
6
+
@@ -0,0 +1,24 @@
1
+ module Lingo24
2
+
3
+ # Custom +Exception+ class for errors returned from the Lingo24 Translation APIs.
4
+ class Exception < :: StandardError
5
+ attr_accessor :code
6
+
7
+ # Creates a new +Language+.
8
+ #
9
+ # Parameters:
10
+ # <tt>code</tt> - a string containing the status code of the message.
11
+ # <tt>msg</tt> - a string containing the exception message.
12
+ def initialize(code, msg)
13
+ @code = code
14
+ @message = msg
15
+ end
16
+
17
+ # Overrides default +message+ to return the exception's message.
18
+ def message
19
+ @message
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,24 @@
1
+ module Lingo24
2
+
3
+ # Model class for the Language's returned from the Lingo24 Translation APIs.
4
+ class Language
5
+ attr_reader :code, :name
6
+
7
+ # Creates a new +Language+.
8
+ #
9
+ # Parameters:
10
+ # <tt>code</tt> - a string containing the ISO-639-1 code for the language.
11
+ # <tt>name</tt> - a string containing the friendly name for the language.
12
+ def initialize(code, name)
13
+ @code = code
14
+ @name = name
15
+ end
16
+
17
+ # Overrides default +to_s+ to return a friendly display of the object.
18
+ def to_s
19
+ "(" + code + ": " + name + ")"
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,127 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Lingo24
5
+
6
+ # +PremiumMTAPI+ is an API wrapper for the Lingo24 Premium Machine Translation API
7
+ # (https://developer.lingo24.com/premium-machine-translation-api).
8
+ #
9
+ # Machine Translation (MT) is a cost-effective, quick translation option for large volumes of content, or cases where
10
+ # it is not feasible to use a professional human translator.
11
+ #
12
+ # The Lingo24 Premium Machine Translation API provides direct, secure, high volume access to our Premium Machine
13
+ # Translation Engines. Encrypted using SSL and with no data storage at Lingo24, you can translate safely with no data
14
+ # privacy concerns.
15
+ #
16
+ # We have developed a range of Premium MT engines focusing on specific language combinations and subject areas,
17
+ # including Law, Information Technology, Pharmaceuticals, Business, IT and many more. This focused approach results in
18
+ # much higher-quality output than generic engines from big-name translators, with the API selecting the best suited
19
+ # engine based on the content of the text for translation. Ideal for those scenarios where no post-editing is required, such as gisting (getting a basic understanding of a source text), real-time translation (tweets, IM chat, etc) or sentiment analysis, the Premium MT API enables easy access to raw machine translation.
20
+ #
21
+ class PremiumMTAPI
22
+ BASE_API_URL = "https://api.lingo24.com/mt/v1/"
23
+
24
+ public
25
+ # Creates a new API client to handle calls to the Lingo24 Premium Machine Translation API.
26
+ #
27
+ # Parameters:
28
+ # <tt>user_key</tt> - a string containing the user_key issued by the Lingo24 developer portal for your application.
29
+ def initialize(user_key)
30
+ @user_key = user_key
31
+ end
32
+
33
+ # Synchronous call to translate text using the Lingo24 Premium Machine Translation API. When calling this method
34
+ # the text sent is analysed and routed to the engine most likely to produce the highest quality output.
35
+ #
36
+ # NOTE: Customers who have custom engines for specific business domains will have these prioritised ahead of Lingo24
37
+ # vertical engines.
38
+ #
39
+ # Options:
40
+ # <tt>text</tt> - a string for translation
41
+ # <tt>source</tt> - a string containing the ISO-639-1 code for the source language
42
+ # <tt>target</tt> - a string containing the ISO-639-1 code for the target language
43
+ def translate(text, source, target)
44
+ params = {:q => text, :source => source, :target => target, :user_key => @user_key}
45
+ handle_request('translate', params, 'translation')
46
+ end
47
+
48
+ # Synchronous call to translate text using the Lingo24 Premium Machine Translation API. When calling this method
49
+ # the text sent is analysed and routed to the engine most likely to produce the highest quality output.
50
+ #
51
+ # NOTE: Customers who have custom engines for specific business domains will have these prioritised ahead of Lingo24
52
+ # vertical engines.
53
+ #
54
+ # Options:
55
+ # <tt>text</tt> - a string for translation
56
+ # <tt>source</tt> - a +Lingo24::Language+ containing the source language
57
+ # <tt>target</tt> - a +Lingo24::Language+ containing the target language
58
+ def translate_language(text, source, target)
59
+ params = {:q => text, :source => source.code, :target => target.code, :user_key => @user_key}
60
+ handle_request('translate', params, 'translation')
61
+ end
62
+
63
+ # Synchronous call to translate text using a specific Lingo24 Premium Machine Translation engine. This method is
64
+ # typically used by customers who have a custom engine and want to ignore the automatic classification..
65
+ #
66
+ # Options:
67
+ # <tt>text</tt> - a string for translation
68
+ # <tt>source</tt> - a +Lingo24::Language+ containing the source language
69
+ # <tt>target</tt> - a +Lingo24::Language+ containing the target language
70
+ def translate_specific(text, id)
71
+ params = {:q => text, :id => id, :user_key => @user_key}
72
+ handle_request('translate', params, 'translation')
73
+ end
74
+
75
+ ##
76
+ # Returns a list of the supported source languages for +PremiumMTAPI+. This method will return a list containing
77
+ # +Lingo24::Language+ objects which provide access to both the ISO-639-1 code as well as a friendly name.
78
+ #
79
+ # If the +target+ is nil, the list will contain all possible source languages.
80
+ # If the +target+ is set, the list will contain only the source languages that
81
+ # can generate the target language.
82
+ def get_source_langs(target = nil)
83
+ if (target.nil?)
84
+ params = { :user_key => @user_key }
85
+ else
86
+ params = { :user_key => @user_key, :target => target }
87
+ end
88
+ source_langs = handle_request('sourcelangs', params, 'source_langs')
89
+ source_langs.map { |code, name| Lingo24::Language.new(code, name) }
90
+ end
91
+
92
+ ##
93
+ # Returns a list of the supported target languages for +PremiumMTAPI+. This method will return a list containing
94
+ # +Lingo24::Language+ objects which provide access to both the ISO-639-1 code as well as a friendly name.
95
+ #
96
+ # If +source+ is nil, the list will contain all possible target languages.
97
+ # If +source+ is set, the list will contain only the target languages that
98
+ # can generate the source language.
99
+ def get_target_langs(source = nil)
100
+ if (source.nil?)
101
+ params = { :user_key => @user_key }
102
+ else
103
+ params = { :user_key => @user_key, :source => source }
104
+ end
105
+ target_langs = handle_request('targetlangs', params, 'target_langs')
106
+ target_langs.map { |code, name| Lingo24::Language.new(code, name) }
107
+ end
108
+
109
+ private
110
+ # Private method to handle the interaction between the client library and the Lingo24 API.
111
+ def handle_request(method, params, field)
112
+ response = Faraday.post BASE_API_URL + method, params do |request|
113
+ request.options[:timeout] = 300
114
+ request.options[:open_timeout] = 120
115
+ end
116
+ if (response.status.equal? '200')
117
+ raise Lingo24::Exception.new(response.status, response.body)
118
+ elsif (JSON.parse(response.body)['errors'])
119
+ raise Lingo24::Exception.new('500', JSON.parse(response.body)['errors'][0])
120
+ else
121
+ JSON.parse(response.body)[field]
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ end
@@ -0,0 +1,3 @@
1
+ module Lingo24
2
+ VERSION = "0.1.0"
3
+ end
@@ -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 'lingo24/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lingo24"
8
+ spec.version = Lingo24::VERSION
9
+ spec.authors = ["David Meikle"]
10
+ spec.email = ["api@lingo24.com"]
11
+ spec.summary = %q{A client library for interfacing with the Lingo24's Translation APIs.}
12
+ spec.description = %q{Lingo24 offer various APIs that allow you to access our translation services, including our business translation and premium machine translation services. The Lingo24 gem lets you interface with the APIs (found at https://developer.lingo24.com/) to allow you to easily integrate them within your application.}
13
+ spec.homepage = "https://developer.lingo24.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{^(spec|test|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.add_development_dependency "rspec", "~> 3.1"
24
+
25
+ spec.add_dependency "faraday", "~> 0.9"
26
+ spec.add_dependency "json", "~> 1.8"
27
+ end
@@ -0,0 +1,65 @@
1
+ require 'rspec'
2
+ require './lib/lingo24'
3
+
4
+ # Replace this with your Application's +user_key+ from the Lingo24 Developer Portal (https://developer.lingo24.com)
5
+ USER_KEY = '<your_user_key>'
6
+
7
+ # Specification file for the +Lingo24::PremiumMTAPI+ class
8
+ describe Lingo24::PremiumMTAPI do
9
+
10
+ it 'should translate a string with source and target supplied' do
11
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
12
+ r = translator.translate('Love your language', 'en', 'es')
13
+ expect(r.size).to be > 0
14
+ end
15
+
16
+ it 'should translate a string with a specifc engine' do
17
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
18
+ r = translator.translate_specific('Love your language', 'ugc-ro-en')
19
+ expect(r.size).to be > 0
20
+ end
21
+
22
+ it 'if you translate using a specific engine but supply the wrong id, it should raise an Lingo24::Exception' do
23
+ begin
24
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
25
+ r = translator.translate_specific('Love your language', 'ugc-roen')
26
+ fail('No Lingo24::Exception raised')
27
+ rescue Lingo24::Exception => detail
28
+ expect(detail.code).to eql('500')
29
+ end
30
+
31
+ end
32
+
33
+ it 'should provide a list of available source languages' do
34
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
35
+ r = translator.get_source_langs()
36
+ expect(r.size).to be > 0
37
+ end
38
+
39
+ it 'should provide a list of available source languages, filtered by the target language' do
40
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
41
+ a = translator.get_source_langs('de')
42
+ b = translator.get_source_langs()
43
+ expect(b.size).to be > a.size
44
+ end
45
+
46
+ it 'should provide a list of available target languages' do
47
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
48
+ r = translator.get_target_langs()
49
+ expect(r.size).to be > 0
50
+ end
51
+
52
+ it 'should provide a list of available target languages, filtered by the source language' do
53
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
54
+ a = translator.get_target_langs('de')
55
+ b = translator.get_target_langs()
56
+ expect(b.size).to be > a.size
57
+ end
58
+
59
+ it 'should translate a string using Lingo24::Language objects for source and target' do
60
+ translator = Lingo24::PremiumMTAPI.new(USER_KEY)
61
+ r = translator.translate_language('Love your language', Lingo24::Language.new('en', 'English'), Lingo24::Language.new('es', 'Spanish'))
62
+ expect(r.size).to be > 0
63
+ end
64
+
65
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lingo24
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Meikle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-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.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
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ description: Lingo24 offer various APIs that allow you to access our translation services,
84
+ including our business translation and premium machine translation services. The
85
+ Lingo24 gem lets you interface with the APIs (found at https://developer.lingo24.com/)
86
+ to allow you to easily integrate them within your application.
87
+ email:
88
+ - api@lingo24.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - .gitignore
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/lingo24.rb
99
+ - lib/lingo24/exception.rb
100
+ - lib/lingo24/language.rb
101
+ - lib/lingo24/premium_mt_api.rb
102
+ - lib/lingo24/version.rb
103
+ - lingo24.gemspec
104
+ - spec/premium_mt_api_spec.rb
105
+ homepage: https://developer.lingo24.com
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A client library for interfacing with the Lingo24's Translation APIs.
129
+ test_files:
130
+ - spec/premium_mt_api_spec.rb