deepl-rb 0.0.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: 821de95f90b5bb4a436628dab27d4dbd4e7f12c1
4
+ data.tar.gz: 64ed5806cab9cc33ff66ea06af54726ceb7a6ace
5
+ SHA512:
6
+ metadata.gz: e66573231bdb82961e72fa0ad620196f452dca86cbbc5405665b422f0df4549eef7ad3ad8fe572a0c0c4eebf071469fbe02b44c7cd49bc8edb7f452d620008d6
7
+ data.tar.gz: 76aca2cc48dd0544919775b79a8fdbe3c009664d54a0424e619ec5b27cdf65e9bc81889d2a60eb48ef177b7b2cfce60b5ca307ad119f35056f65b07e37e679cc
@@ -0,0 +1,39 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ working_directory: ~/deepl-rb
5
+ docker:
6
+ - image: circleci/ruby:2.4-node
7
+ steps:
8
+ - checkout
9
+
10
+ # Restore bundle cache
11
+ - type: cache-restore
12
+ name: Restore bundle cache
13
+ key: deepl-rb-bundle-{{ checksum "Gemfile.lock" }}
14
+
15
+ - run:
16
+ name: Bundle Install
17
+ command: bundle install --path vendor/bundle
18
+
19
+ # Store bundle cache
20
+ - type: cache-save
21
+ name: Store bundle cache
22
+ key: deepl-rb-bundle-{{ checksum "Gemfile.lock" }}
23
+ paths:
24
+ - vendor/bundle
25
+
26
+ # Run rspec
27
+ - type: shell
28
+ command: |
29
+ bundle exec rspec $(circleci tests glob "spec/**/*_spec.rb" |
30
+ circleci tests split --split-by=timings)
31
+
32
+ # Run rubocop
33
+ - type: shell
34
+ command: |
35
+ bundle exec rubocop
36
+
37
+ # Save test results for timing analysis
38
+ - store_test_results:
39
+ path: test_results
@@ -0,0 +1,17 @@
1
+ # Custom rubocop configuration
2
+
3
+ AllCops:
4
+ DisplayCopNames: true
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - "**/*_spec.rb"
9
+
10
+ Metrics/LineLength:
11
+ Max: 120
12
+
13
+ Style/Documentation:
14
+ Enabled: false
15
+
16
+ Style/ModuleFunction:
17
+ EnforcedStyle: extend_self
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ # Gem management
5
+ gem 'juwelier'
6
+ end
7
+
8
+ group :test do
9
+ # Test
10
+ gem 'rspec'
11
+ gem 'rubocop'
12
+ gem 'simplecov'
13
+ gem 'vcr'
14
+ gem 'webmock'
15
+ end
@@ -0,0 +1,113 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.5.2)
5
+ public_suffix (>= 2.0.2, < 4.0)
6
+ ast (2.3.0)
7
+ builder (3.2.3)
8
+ crack (0.4.3)
9
+ safe_yaml (~> 1.0.0)
10
+ descendants_tracker (0.0.4)
11
+ thread_safe (~> 0.3, >= 0.3.1)
12
+ diff-lcs (1.3)
13
+ docile (1.1.5)
14
+ faraday (0.12.2)
15
+ multipart-post (>= 1.2, < 3)
16
+ git (1.3.0)
17
+ github_api (0.18.2)
18
+ addressable (~> 2.4)
19
+ descendants_tracker (~> 0.0.4)
20
+ faraday (~> 0.8)
21
+ hashie (~> 3.5, >= 3.5.2)
22
+ oauth2 (~> 1.0)
23
+ hashdiff (0.3.7)
24
+ hashie (3.5.6)
25
+ highline (1.7.10)
26
+ json (2.1.0)
27
+ juwelier (2.4.7)
28
+ builder
29
+ bundler
30
+ git
31
+ github_api
32
+ highline
33
+ kamelcase (~> 0)
34
+ nokogiri
35
+ psych
36
+ rake
37
+ rdoc
38
+ semver2
39
+ jwt (1.5.6)
40
+ kamelcase (0.0.1)
41
+ semver2 (~> 3)
42
+ mini_portile2 (2.3.0)
43
+ multi_json (1.12.2)
44
+ multi_xml (0.6.0)
45
+ multipart-post (2.0.0)
46
+ nokogiri (1.8.1)
47
+ mini_portile2 (~> 2.3.0)
48
+ oauth2 (1.4.0)
49
+ faraday (>= 0.8, < 0.13)
50
+ jwt (~> 1.0)
51
+ multi_json (~> 1.3)
52
+ multi_xml (~> 0.5)
53
+ rack (>= 1.2, < 3)
54
+ parallel (1.12.0)
55
+ parser (2.4.0.2)
56
+ ast (~> 2.3)
57
+ powerpack (0.1.1)
58
+ psych (2.2.2)
59
+ public_suffix (3.0.1)
60
+ rack (2.0.3)
61
+ rainbow (2.2.2)
62
+ rake
63
+ rake (12.3.0)
64
+ rdoc (5.0.0)
65
+ rspec (3.7.0)
66
+ rspec-core (~> 3.7.0)
67
+ rspec-expectations (~> 3.7.0)
68
+ rspec-mocks (~> 3.7.0)
69
+ rspec-core (3.7.0)
70
+ rspec-support (~> 3.7.0)
71
+ rspec-expectations (3.7.0)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.7.0)
74
+ rspec-mocks (3.7.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.7.0)
77
+ rspec-support (3.7.0)
78
+ rubocop (0.51.0)
79
+ parallel (~> 1.10)
80
+ parser (>= 2.3.3.1, < 3.0)
81
+ powerpack (~> 0.1)
82
+ rainbow (>= 2.2.2, < 3.0)
83
+ ruby-progressbar (~> 1.7)
84
+ unicode-display_width (~> 1.0, >= 1.0.1)
85
+ ruby-progressbar (1.9.0)
86
+ safe_yaml (1.0.4)
87
+ semver2 (3.4.2)
88
+ simplecov (0.15.1)
89
+ docile (~> 1.1.0)
90
+ json (>= 1.8, < 3)
91
+ simplecov-html (~> 0.10.0)
92
+ simplecov-html (0.10.2)
93
+ thread_safe (0.3.6)
94
+ unicode-display_width (1.3.0)
95
+ vcr (4.0.0)
96
+ webmock (3.1.1)
97
+ addressable (>= 2.3.6)
98
+ crack (>= 0.3.2)
99
+ hashdiff
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ juwelier
106
+ rspec
107
+ rubocop
108
+ simplecov
109
+ vcr
110
+ webmock
111
+
112
+ BUNDLED WITH
113
+ 1.15.4
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright © `2018` `Daniel Herzog`
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the “Software”), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,102 @@
1
+ [![Gem Version](https://badge.fury.io/rb/deepl-rb.svg)](https://badge.fury.io/rb/deepl-rb) [![Dependency Status](https://gemnasium.com/badges/github.com/wikiti/deepl-rb.svg)](https://gemnasium.com/github.com/wikiti/deepl-rb) [![CircleCI](https://circleci.com/gh/wikiti/deepl-rb.svg?style=shield)](https://circleci.com/gh/wikiti/deepl-rb)
2
+
3
+ # DeepL for ruby
4
+
5
+ A simple ruby wrapper for the [DeepL translation API (v1)](https://www.deepl.com/docs/api-reference.html).
6
+
7
+ ## Installation
8
+
9
+ Install this gem with
10
+
11
+ ```sh
12
+ gem install deepl-rb
13
+ ```
14
+
15
+ Or add it to your Gemfile:
16
+
17
+ ```rb
18
+ gem 'deepl-rb'
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Setup an environment variable named `DEEPL_AUTH_KEY` with your authentication key:
24
+
25
+ ```sh
26
+ export DEEPL_AUTH_KEY="your-api-token"
27
+ ```
28
+
29
+ Alternatively, you can configure the API client within a ruby block:
30
+
31
+ ```rb
32
+ DeepL.configure do |config|
33
+ config.auth_key = 'your-api-token'
34
+ end
35
+ ```
36
+
37
+ You can also configure the api host:
38
+
39
+ ```rb
40
+ DeepL.configure do |config|
41
+ config.auth_key = 'your-api-token'
42
+ config.host = 'https://test-api.deepl.com' # Default value is 'https://api.deepl.com'
43
+ end
44
+ ```
45
+
46
+ ### Translate
47
+
48
+ To translate a simple text, use the `translate` method:
49
+
50
+ ```rb
51
+ item = DeepL.translate 'This is my text', 'EN', 'ES'
52
+
53
+ puts item.class
54
+ # => DeepL::Resources::Text
55
+ puts item.text
56
+ # => 'Este es mi texto'
57
+ ```
58
+
59
+ You can also auto-detect source language by skipping it with `nil`:
60
+
61
+ ```rb
62
+ item = DeepL.translate 'This is my text', nil, 'ES'
63
+
64
+ puts item.detected_source_language
65
+ # => 'EN'
66
+ ```
67
+
68
+ You can also translate a list of texts by passing an array as an argument:
69
+
70
+ ```rb
71
+ texts = ['Sample text', 'Another text']
72
+ items = DeepL.translate texts, 'EN', 'ES'
73
+
74
+ puts items.class
75
+ # => Array
76
+ puts items.first.class
77
+ # => DeepL::Resources::Text
78
+ ```
79
+
80
+ ## Development
81
+
82
+ Clone the repository, and install its dependencies:
83
+
84
+ ```sh
85
+ git clone https://github.com/wikiti/deepl-rb
86
+ cd deepl-rb
87
+ bundle install
88
+ ```
89
+
90
+ To run tests (rspec and rubocop), use
91
+
92
+ ```
93
+ bundle exec rake test
94
+ ```
95
+
96
+ ## Contributors
97
+
98
+ This project has been developed by:
99
+
100
+ | Avatar | Name | Nickname | Email |
101
+ | ------ | ---- | -------- | ----- |
102
+ | ![](http://www.gravatar.com/avatar/2ae6d81e0605177ba9e17b19f54e6b6c.jpg?s=64) | Daniel Herzog | Wikiti | [info@danielherzog.es](mailto:info@danielherzog.es)
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ warn e.message
8
+ warn 'Run `bundle install` to install missing gems'
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'rake'
13
+ require 'juwelier'
14
+
15
+ Juwelier::Tasks.new do |gem|
16
+ gem.name = 'deepl-rb'
17
+ gem.homepage = 'http://github.com/wikiti/deepl-rb'
18
+ gem.license = 'MIT'
19
+ gem.summary = 'A simple ruby wrapper for the DeepL API'
20
+ gem.description =
21
+ 'A simple ruby wrapper for the DeepL translation API (v1). ' \
22
+ 'For more information, check this: https://www.deepl.com/docs/api-reference.html'
23
+
24
+ gem.email = 'info@danielherzog.es'
25
+ gem.authors = ['Daniel Herzog']
26
+ end
27
+
28
+ Juwelier::RubygemsDotOrgTasks.new
29
+
30
+ # Tests
31
+ require 'rspec/core/rake_task'
32
+ require 'rubocop/rake_task'
33
+
34
+ RuboCop::RakeTask.new
35
+ RSpec::Core::RakeTask.new(:spec)
36
+
37
+ desc 'Run all tests.'
38
+ task :test do
39
+ Rake::Task['spec'].invoke
40
+ Rake::Task['rubocop'].invoke
41
+ end
42
+
43
+ task default: :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,69 @@
1
+ # Generated by juwelier
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Juwelier::Tasks in rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: deepl-rb 0.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "deepl-rb".freeze
9
+ s.version = "0.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Daniel Herzog".freeze]
14
+ s.date = "2017-12-12"
15
+ s.description = "A simple ruby wrapper for the DeepL translation API (v1). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
16
+ s.email = "info@danielherzog.es".freeze
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.md",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".circleci/config.yml",
23
+ ".rubocop.yml",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.md",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "deepl-rb.gemspec",
31
+ "lib/deepl.rb",
32
+ "lib/deepl/api.rb",
33
+ "lib/deepl/configuration.rb",
34
+ "lib/deepl/exceptions/authorization_failed.rb",
35
+ "lib/deepl/exceptions/bad_request.rb",
36
+ "lib/deepl/exceptions/error.rb",
37
+ "lib/deepl/exceptions/limit_exceeded.rb",
38
+ "lib/deepl/exceptions/request_error.rb",
39
+ "lib/deepl/requests/base.rb",
40
+ "lib/deepl/requests/translate_text.rb",
41
+ "lib/deepl/resources/base.rb",
42
+ "lib/deepl/resources/text.rb",
43
+ "spec/api/api_spec.rb",
44
+ "spec/api/configuration_spec.rb",
45
+ "spec/api/deepl_spec.rb",
46
+ "spec/fixtures/vcr_cassettes/deepl_translate.yml",
47
+ "spec/fixtures/vcr_cassettes/translate_texts.yml",
48
+ "spec/requests/translate_text_spec.rb",
49
+ "spec/resources/text_spec.rb",
50
+ "spec/spec_helper.rb"
51
+ ]
52
+ s.homepage = "http://github.com/wikiti/deepl-rb".freeze
53
+ s.licenses = ["MIT".freeze]
54
+ s.rubygems_version = "2.6.13".freeze
55
+ s.summary = "A simple ruby wrapper for the DeepL API".freeze
56
+
57
+ if s.respond_to? :specification_version then
58
+ s.specification_version = 4
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
62
+ else
63
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
67
+ end
68
+ end
69
+
@@ -0,0 +1,56 @@
1
+ # -- Dependencies
2
+ require 'json'
3
+ require 'net/http'
4
+
5
+ # -- Exceptions
6
+ require 'deepl/exceptions/error'
7
+ require 'deepl/exceptions/request_error'
8
+ require 'deepl/exceptions/authorization_failed'
9
+ require 'deepl/exceptions/bad_request'
10
+ require 'deepl/exceptions/limit_exceeded'
11
+
12
+ # -- Requests
13
+ require 'deepl/requests/base'
14
+ require 'deepl/requests/translate_text'
15
+
16
+ # -- Responses and resources
17
+ require 'deepl/resources/base'
18
+ require 'deepl/resources/text'
19
+
20
+ # -- Other wrappers
21
+ require 'deepl/api'
22
+ require 'deepl/configuration'
23
+
24
+ # -- Gem interface
25
+ module DeepL
26
+ extend self
27
+
28
+ ## -- API shortcuts
29
+
30
+ def api
31
+ @api ||= API.new(configuration)
32
+ end
33
+
34
+ def translate(text, options = {})
35
+ configure if @configuration.nil?
36
+ Requests::TranslateText.new(api, text, fetch(options, :source_lang),
37
+ fetch(options, :target_lang)).request
38
+ end
39
+
40
+ # -- Configuration
41
+
42
+ def configuration
43
+ @configuration ||= Configuration.new
44
+ end
45
+
46
+ def configure
47
+ yield configuration if block_given?
48
+ configuration.validate!
49
+ end
50
+
51
+ private
52
+
53
+ def fetch(hash, key)
54
+ hash[key.to_s] || hash[key.to_sym]
55
+ end
56
+ end