fun_translations 0.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/CODE_OF_CONDUCT.md +46 -0
- data/.github/CONTRIBUTING.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +5 -0
- data/LICENSE.md +22 -0
- data/README.md +123 -0
- data/Rakefile +21 -0
- data/fun_translations.gemspec +39 -0
- data/lib/fun_translations/client.rb +29 -0
- data/lib/fun_translations/connection.rb +34 -0
- data/lib/fun_translations/error.rb +48 -0
- data/lib/fun_translations/request.rb +36 -0
- data/lib/fun_translations/translation.rb +22 -0
- data/lib/fun_translations/version.rb +5 -0
- data/lib/fun_translations.rb +24 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d84c29856a6bce39d4f029d7e6100d2ce6f69d389edd32e3105d71502cb12d39
|
4
|
+
data.tar.gz: e04aa571850204cdca9b5d63f840c1283dc8daaca256115974c57f84df7cbf0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a8575556f666b18ecc39b80dc2498baed5231a61214aff59ab142cd9aa97ab28d0e09f24064cdc5b467b851de1a003777a006d6558d0a07375cc17d73af1c955
|
7
|
+
data.tar.gz: 21452dd559035b8a9fdd5c0961048b27ca9aa9bb1ea37b570196bbfcd607a59495ad0fbedb219c850040f3842f6d7bbe29ceb599640bf19fc2ef2743f8a873d7
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
## Our Standards
|
8
|
+
|
9
|
+
Examples of behavior that contributes to creating a positive environment include:
|
10
|
+
|
11
|
+
* Using welcoming and inclusive language
|
12
|
+
* Being respectful of differing viewpoints and experiences
|
13
|
+
* Gracefully accepting constructive criticism
|
14
|
+
* Focusing on what is best for the community
|
15
|
+
* Showing empathy towards other community members
|
16
|
+
|
17
|
+
Examples of unacceptable behavior by participants include:
|
18
|
+
|
19
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
+
* Public or private harassment
|
22
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
+
|
25
|
+
## Our Responsibilities
|
26
|
+
|
27
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
+
|
29
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
+
|
31
|
+
## Scope
|
32
|
+
|
33
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
+
|
35
|
+
## Enforcement
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at golosizpru@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
+
|
39
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
+
|
41
|
+
## Attribution
|
42
|
+
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
+
|
45
|
+
[homepage]: http://contributor-covenant.org
|
46
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
1. [Fork the repository.][fork]
|
4
|
+
2. [Create a topic branch.][branch]
|
5
|
+
3. Implement your feature or bug fix.
|
6
|
+
4. Don't forget to add specs and make sure they pass by running `rspec .`.
|
7
|
+
5. Make sure your code complies with the style guide by running `rubocop`. `rubocop -a` can automatically fix most issues for you. Run `rubocop -A` to make it more aggressive.
|
8
|
+
6. If necessary, add documentation for your feature or bug fix.
|
9
|
+
7. Commit and push your changes.
|
10
|
+
8. [Submit a pull request.][pr]
|
11
|
+
|
12
|
+
[fork]: http://help.github.com/fork-a-repo/
|
13
|
+
[branch]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-branches
|
14
|
+
[pr]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
|
@@ -0,0 +1,11 @@
|
|
1
|
+
### Summary
|
2
|
+
|
3
|
+
Provide a general description of the code changes in your pull
|
4
|
+
request. Were there any bugs you had fixed? If so, mention them. If
|
5
|
+
these bugs have open GitHub issues, be sure to tag them here as well,
|
6
|
+
to keep the conversation linked together.
|
7
|
+
|
8
|
+
### Other Information
|
9
|
+
|
10
|
+
If there's anything else that's important and relevant to your pull
|
11
|
+
request, mention that information here.
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Ilya Bodrov-Krukowski
|
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 NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# FunTranslations API Ruby interface
|
2
|
+
|
3
|
+
![Gem](https://img.shields.io/gem/v/fun_translations)
|
4
|
+
![CI](https://github.com/bodrovis/fun_translations/actions/workflows/ci.yml/badge.svg)
|
5
|
+
[![Test Coverage](https://codecov.io/gh/bodrovis/fun_translations/graph/badge.svg)](https://codecov.io/gh/bodrovis/fun_translations)
|
6
|
+
![Downloads total](https://img.shields.io/gem/dt/fun_translations)
|
7
|
+
|
8
|
+
This is a Ruby client that enables you to easily perform translations using [FunTranslations API](https://api.funtranslations.com/).
|
9
|
+
|
10
|
+
*If would like to learn how this gem was built, please check out [this and subsequent lessons](https://www.youtube.com/watch?v=FEfHExlN6-8) on my YT channel (currently only available in Russian).*
|
11
|
+
|
12
|
+
## Prerequisites
|
13
|
+
|
14
|
+
[Ruby 2.7+](https://www.ruby-lang.org/en/) and [RubyGems subsystem](https://rubygems.org/) is required.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Install this gem by running:
|
19
|
+
|
20
|
+
```
|
21
|
+
$ gem install fun_translations
|
22
|
+
```
|
23
|
+
|
24
|
+
Or add it to your `Gemfile`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'fun_translations'
|
28
|
+
```
|
29
|
+
|
30
|
+
And run:
|
31
|
+
|
32
|
+
```
|
33
|
+
bundle install
|
34
|
+
```
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
Include the client in your script:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require 'fun_translations'
|
42
|
+
```
|
43
|
+
|
44
|
+
Next, instantiate the client:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
client = FunTranslations.client
|
48
|
+
```
|
49
|
+
|
50
|
+
And perform translations:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
translation_yoda = client.translate :yoda, "Hello, my padawan"
|
54
|
+
translation_klingon = client.translate :klingon, "We are klingons."
|
55
|
+
translation_morse = client.translate 'morse/audio', "Morse code is dit and dash."
|
56
|
+
```
|
57
|
+
|
58
|
+
### Additional request parameters
|
59
|
+
|
60
|
+
In most cases you will only need to pass the text to translate. However, certain translators (for example, `'morse/audio'`) might require additional params. You can specify these params as a third hash argument:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
translation_morse = client.translate 'morse/audio', "Morse code is dit and dash.", speed: 5, tone: 700
|
64
|
+
```
|
65
|
+
|
66
|
+
### Translation object
|
67
|
+
|
68
|
+
The `translate` method returns an instance of the `FunTranslations::Translation` class. It responds to the following methods:
|
69
|
+
|
70
|
+
* `translated_text` — the actual translation result. Please note that in very rare cases this method will return `nil`, specifically, when you are using `'morse/audio'` translator that returns encoded audio only.
|
71
|
+
* `original_text` — your initial (base) text.
|
72
|
+
* `translation` — translator that you've chosen.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
translation_yoda.translated_text # => 'A planet, master obi wan lost'
|
76
|
+
translation_yoda.original_text # => 'Master Obi Wan lost a planet'
|
77
|
+
translation_yoda.translation # => 'yoda'
|
78
|
+
```
|
79
|
+
|
80
|
+
There are additional methods available only for "audio" translators:
|
81
|
+
|
82
|
+
* `audio` — returns base64-encoded audio stream.
|
83
|
+
* `speed` — audio speed.
|
84
|
+
* `tone` — audio tone.
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
translation_morse = client.translate 'morse/audio', "Morse code is dit and dash.", speed: 5, tone: 700
|
88
|
+
|
89
|
+
translation_yoda.audio # => 'data:audio/wave;base64,UklGRjiBCQBXQVZFZm1...'
|
90
|
+
translation_yoda.speed # => '5 WPM'
|
91
|
+
translation_yoda.tone # => '700 Hz'
|
92
|
+
|
93
|
+
# Please note that the `translation` method returns a hash in this case:
|
94
|
+
|
95
|
+
translation_yoda.translation['source'] # => 'english'
|
96
|
+
translation_yoda.translation['destination'] # => 'morse audio'
|
97
|
+
```
|
98
|
+
|
99
|
+
### API token
|
100
|
+
|
101
|
+
FunTranslations API has a free pricing plan which does not require registering and obtaining an API key. In other words, you can start using the gem right away. However, please be aware that the free plan allows only 5 requests per hour and 60 requests per day. Therefore, you might want to purchase a paid plan and obtain an API key. Then, simply pass this key when instantiating the client:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
client = FunTranslations.client('123abc')
|
105
|
+
```
|
106
|
+
|
107
|
+
Then perform translations as usual.
|
108
|
+
|
109
|
+
## Running tests
|
110
|
+
|
111
|
+
Tests are written in RSpec (all HTTP requests are stubbed):
|
112
|
+
|
113
|
+
```
|
114
|
+
rspec .
|
115
|
+
```
|
116
|
+
|
117
|
+
Observe test results and coverage.
|
118
|
+
|
119
|
+
## Copyright and license
|
120
|
+
|
121
|
+
Licensed under the [MIT license](./LICENSE.md).
|
122
|
+
|
123
|
+
Copyright (c) 2022 [Ilya Krukowski](http://bodrovis.tech)
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler/setup'
|
7
|
+
Bundler::GemHelper.install_tasks
|
8
|
+
rescue LoadError
|
9
|
+
puts 'although not required, bundler is recommened for running the tests'
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :spec
|
13
|
+
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
require 'rubocop/rake_task'
|
18
|
+
RuboCop::RakeTask.new do |task|
|
19
|
+
task.requires << 'rubocop-performance'
|
20
|
+
task.requires << 'rubocop-rspec'
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/fun_translations/version', __dir__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'fun_translations'
|
7
|
+
spec.version = FunTranslations::VERSION
|
8
|
+
spec.authors = ['Ilya Krukowski']
|
9
|
+
spec.email = ['golosizpru@gmail.com']
|
10
|
+
spec.summary = 'Ruby interface for FunTranslations API.'
|
11
|
+
spec.description = 'This is a Ruby client that enables you to easily perform translations using ' \
|
12
|
+
'FunTranslations API.'
|
13
|
+
spec.homepage = 'https://github.com/bodrovis/fun_translations'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.platform = Gem::Platform::RUBY
|
16
|
+
spec.required_ruby_version = '>= 2.7.0'
|
17
|
+
|
18
|
+
spec.files = Dir['README.md', 'LICENSE.md',
|
19
|
+
'CHANGELOG.md', 'lib/**/*.rb',
|
20
|
+
'fun_translations.gemspec', '.github/*.md',
|
21
|
+
'Gemfile', 'Rakefile']
|
22
|
+
spec.extra_rdoc_files = ['README.md']
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'faraday', '~> 2.6'
|
26
|
+
spec.add_dependency 'zeitwerk', '~> 2.4'
|
27
|
+
spec.add_development_dependency 'codecov', '~> 0.1'
|
28
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.6'
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 1.6'
|
31
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
32
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
34
|
+
spec.add_development_dependency 'webmock', '~> 3.14'
|
35
|
+
|
36
|
+
spec.metadata = {
|
37
|
+
'rubygems_mfa_required' => 'true'
|
38
|
+
}
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FunTranslations
|
4
|
+
# FunTranslations API client
|
5
|
+
class Client
|
6
|
+
include FunTranslations::Request
|
7
|
+
|
8
|
+
attr_accessor :token
|
9
|
+
|
10
|
+
def initialize(token = nil)
|
11
|
+
@token = token
|
12
|
+
end
|
13
|
+
|
14
|
+
# Performs translation
|
15
|
+
# @return [FunTranslations::Translation]
|
16
|
+
# @param endpoint [String, Symbol]
|
17
|
+
# @param text [String]
|
18
|
+
# @param params [Hash]
|
19
|
+
def translate(endpoint, text, params = {})
|
20
|
+
FunTranslations::Translation.new(
|
21
|
+
post(
|
22
|
+
"/translate/#{endpoint}.json",
|
23
|
+
self,
|
24
|
+
{text: text}.merge(params)
|
25
|
+
)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FunTranslations
|
4
|
+
# This module prepares a connection object
|
5
|
+
module Connection
|
6
|
+
BASE_URL = 'https://api.funtranslations.com'
|
7
|
+
|
8
|
+
# Prepares a new connection object
|
9
|
+
# @param client [FunTranslations::Client]
|
10
|
+
def connection(client)
|
11
|
+
Faraday.new(options(client)) do |faraday|
|
12
|
+
faraday.adapter Faraday.default_adapter
|
13
|
+
faraday.request :url_encoded
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def options(client)
|
20
|
+
headers = {
|
21
|
+
accept: 'application/json',
|
22
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
23
|
+
user_agent: "fun_translations gem/#{FunTranslations::VERSION}"
|
24
|
+
}
|
25
|
+
|
26
|
+
headers['X-Funtranslations-Api-Secret'] = client.token unless client.token.nil?
|
27
|
+
|
28
|
+
{
|
29
|
+
headers: headers,
|
30
|
+
url: BASE_URL
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FunTranslations
|
4
|
+
# Custom errors
|
5
|
+
class Error < StandardError
|
6
|
+
ClientError = Class.new(self)
|
7
|
+
ServerError = Class.new(self)
|
8
|
+
|
9
|
+
BadRequest = Class.new(ClientError)
|
10
|
+
Unauthorized = Class.new(ClientError)
|
11
|
+
NotAcceptable = Class.new(ClientError)
|
12
|
+
NotFound = Class.new(ClientError)
|
13
|
+
Conflict = Class.new(ClientError)
|
14
|
+
TooManyRequests = Class.new(ClientError)
|
15
|
+
Forbidden = Class.new(ClientError)
|
16
|
+
Locked = Class.new(ClientError)
|
17
|
+
MethodNotAllowed = Class.new(ClientError)
|
18
|
+
|
19
|
+
NotImplemented = Class.new(ServerError)
|
20
|
+
BadGateway = Class.new(ServerError)
|
21
|
+
ServiceUnavailable = Class.new(ServerError)
|
22
|
+
GatewayTimeout = Class.new(ServerError)
|
23
|
+
|
24
|
+
ERRORS = {
|
25
|
+
400 => FunTranslations::Error::BadRequest,
|
26
|
+
401 => FunTranslations::Error::Unauthorized,
|
27
|
+
403 => FunTranslations::Error::Forbidden,
|
28
|
+
404 => FunTranslations::Error::NotFound,
|
29
|
+
405 => FunTranslations::Error::MethodNotAllowed,
|
30
|
+
406 => FunTranslations::Error::NotAcceptable,
|
31
|
+
409 => FunTranslations::Error::Conflict,
|
32
|
+
423 => FunTranslations::Error::Locked,
|
33
|
+
429 => FunTranslations::Error::TooManyRequests,
|
34
|
+
500 => FunTranslations::Error::ServerError,
|
35
|
+
502 => FunTranslations::Error::BadGateway,
|
36
|
+
503 => FunTranslations::Error::ServiceUnavailable,
|
37
|
+
504 => FunTranslations::Error::GatewayTimeout
|
38
|
+
}.freeze
|
39
|
+
|
40
|
+
class << self
|
41
|
+
# Create a new error from an HTTP response
|
42
|
+
def from_response(body)
|
43
|
+
msg = body['detail'] || body['message']
|
44
|
+
new msg.to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FunTranslations
|
4
|
+
# This module contains methods to perform HTTP requests
|
5
|
+
module Request
|
6
|
+
include FunTranslations::Connection
|
7
|
+
|
8
|
+
# Performs an HTTP post request
|
9
|
+
# @param path [String]
|
10
|
+
# @param client [FunTranslations::Client]
|
11
|
+
# @param params [Hash]
|
12
|
+
def post(path, client, params = {})
|
13
|
+
respond_with(
|
14
|
+
connection(client).post(path, params)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# Parses response body using JSON
|
21
|
+
# or raises an error if the status code is not 2xx
|
22
|
+
def respond_with(response)
|
23
|
+
body = response.body.empty? ? response.body : JSON.parse(response.body)
|
24
|
+
|
25
|
+
respond_with_error(response.status, body['error']) if body.key?('error') || !response.success?
|
26
|
+
|
27
|
+
body['contents']
|
28
|
+
end
|
29
|
+
|
30
|
+
def respond_with_error(code, body)
|
31
|
+
raise(FunTranslations::Error, body) unless FunTranslations::Error::ERRORS.key? code
|
32
|
+
|
33
|
+
raise FunTranslations::Error::ERRORS[code].from_response(body)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FunTranslations
|
4
|
+
# This class represents a response returned by FunTranslation API
|
5
|
+
class Translation
|
6
|
+
attr_reader :translated_text, :original_text, :translation, :audio, :speed, :tone
|
7
|
+
|
8
|
+
# Initializes a new Translation object
|
9
|
+
def initialize(raw_translation)
|
10
|
+
if raw_translation['translated'].respond_to?(:key?) && raw_translation['translated'].key?('audio')
|
11
|
+
@audio = raw_translation['translated']['audio']
|
12
|
+
else
|
13
|
+
@translated_text = raw_translation['translated']
|
14
|
+
end
|
15
|
+
|
16
|
+
@original_text = raw_translation['text']
|
17
|
+
@translation = raw_translation['translation']
|
18
|
+
@speed = raw_translation['speed']
|
19
|
+
@tone = raw_translation['tone']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'zeitwerk'
|
4
|
+
require 'faraday'
|
5
|
+
|
6
|
+
loader = Zeitwerk::Loader.for_gem
|
7
|
+
loader.setup
|
8
|
+
|
9
|
+
# This is a Ruby client that enables you to easily perform translations using FunTranslations API:
|
10
|
+
#
|
11
|
+
# client = FunTranslations.client
|
12
|
+
# translation_yoda = client.translate :yoda, "Hello, my padawan"
|
13
|
+
# translation_yoda.translated_text
|
14
|
+
module FunTranslations
|
15
|
+
class << self
|
16
|
+
# Initializes a new Client object
|
17
|
+
#
|
18
|
+
# @return [FunTranslations::Client]
|
19
|
+
# @param token [String]
|
20
|
+
def client(token = nil)
|
21
|
+
FunTranslations::Client.new token
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fun_translations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.rc1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya Krukowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zeitwerk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-performance
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.5'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.5'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.16'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.16'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: webmock
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.14'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.14'
|
153
|
+
description: This is a Ruby client that enables you to easily perform translations
|
154
|
+
using FunTranslations API.
|
155
|
+
email:
|
156
|
+
- golosizpru@gmail.com
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files:
|
160
|
+
- README.md
|
161
|
+
files:
|
162
|
+
- ".github/CODE_OF_CONDUCT.md"
|
163
|
+
- ".github/CONTRIBUTING.md"
|
164
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
165
|
+
- CHANGELOG.md
|
166
|
+
- Gemfile
|
167
|
+
- LICENSE.md
|
168
|
+
- README.md
|
169
|
+
- Rakefile
|
170
|
+
- fun_translations.gemspec
|
171
|
+
- lib/fun_translations.rb
|
172
|
+
- lib/fun_translations/client.rb
|
173
|
+
- lib/fun_translations/connection.rb
|
174
|
+
- lib/fun_translations/error.rb
|
175
|
+
- lib/fun_translations/request.rb
|
176
|
+
- lib/fun_translations/translation.rb
|
177
|
+
- lib/fun_translations/version.rb
|
178
|
+
homepage: https://github.com/bodrovis/fun_translations
|
179
|
+
licenses:
|
180
|
+
- MIT
|
181
|
+
metadata:
|
182
|
+
rubygems_mfa_required: 'true'
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: 2.7.0
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">"
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: 1.3.1
|
197
|
+
requirements: []
|
198
|
+
rubygems_version: 3.3.24
|
199
|
+
signing_key:
|
200
|
+
specification_version: 4
|
201
|
+
summary: Ruby interface for FunTranslations API.
|
202
|
+
test_files: []
|