yandex_tranlator_IS 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +30 -15
- data/lib/yandex_tranlator_IS.rb +28 -21
- data/lib/yandex_tranlator_IS/version.rb +1 -1
- data/yandex_tranlator_IS-0.1.0.gem +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 702a0fd18a6b78cb75707c6911e96da39ddcda9900561fcedd76c6a327e676ab
|
|
4
|
+
data.tar.gz: 4045603cc4851997b43a83ed5aed51d925024d30671c4d51a97a09ccd2694a5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 325b87ef1136736da3a50733da3a14b684b6e64775e2f13d000192d6490ca7aab410e48bafbf7077a6bb1335526ec05e03fb0370de929064906d7ed7558f16a4
|
|
7
|
+
data.tar.gz: 00aa6b5b9475358c605b4e74a52f4f0cd579fe10e07964b9fcdfdce758b9f93fd65a40590fb821f10248649f4feb10f62f6ffe5d68bd2dd76a2b975d9863c3cc
|
data/README.md
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
# YandexTranlatorIS
|
|
2
|
-
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yandex_tranlator_IS`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
-
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
|
6
|
-
|
|
7
1
|
## Installation
|
|
8
2
|
|
|
9
3
|
Add this line to your application's Gemfile:
|
|
@@ -22,17 +16,38 @@ Or install it yourself as:
|
|
|
22
16
|
|
|
23
17
|
## Usage
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
1. You need to get API key - https://translate.yandex.com/developers/keys
|
|
20
|
+
2. ```ruby
|
|
21
|
+
translator = YandexTranlatorIS::YandexTr
|
|
22
|
+
```
|
|
23
|
+
3. Create API key
|
|
24
|
+
```ruby
|
|
25
|
+
translator.apikey 'your key'
|
|
26
|
+
```
|
|
27
|
+
4. Install defoult language
|
|
28
|
+
```ruby
|
|
29
|
+
translator.default_lang 'default language'
|
|
30
|
+
```
|
|
31
|
+
5. Translate
|
|
32
|
+
```ruby
|
|
33
|
+
translator.translate 'your text', lang:'language'
|
|
34
|
+
```
|
|
35
|
+
6. Get current API key
|
|
36
|
+
```ruby
|
|
37
|
+
translator.start
|
|
38
|
+
```
|
|
39
|
+
7. See the list of available languages
|
|
40
|
+
```ruby
|
|
41
|
+
translator.languages
|
|
42
|
+
```
|
|
43
|
+
8. See current default language
|
|
44
|
+
```ruby
|
|
45
|
+
translator.default.languages
|
|
46
|
+
```
|
|
32
47
|
|
|
33
48
|
## Contributing
|
|
34
49
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/IlyaSedov/yandex_tranlator_IS.
|
|
36
51
|
|
|
37
52
|
## License
|
|
38
53
|
|
|
@@ -40,4 +55,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
40
55
|
|
|
41
56
|
## Code of Conduct
|
|
42
57
|
|
|
43
|
-
Everyone interacting in the YandexTranlatorIS project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
|
58
|
+
Everyone interacting in the YandexTranlatorIS project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/IlyaSedov/yandex_tranlator_IS/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/yandex_tranlator_IS.rb
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
require "yandex_tranlator_IS/version"
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'uri'
|
|
2
5
|
|
|
3
6
|
module YandexTranlatorIS
|
|
4
|
-
class Error < StandardError; end
|
|
5
7
|
class YandexTr
|
|
6
|
-
|
|
8
|
+
class << self
|
|
9
|
+
def start
|
|
10
|
+
@api_key
|
|
11
|
+
end
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
def apikey(api_key)
|
|
14
|
+
@api_key = api_key
|
|
15
|
+
end
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
def default_lang(lang)
|
|
18
|
+
@default_lang = lang
|
|
19
|
+
end
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# url=@api_url<<"key=#{@api_key}&text=#{text}&lang=#{lang}"
|
|
20
|
-
uri=URI("https://translate.yandex.net/api/v1.5/tr.json/translate?key=#{@api_key}&text=#{URI.encode(text)}&lang=#{lang}")
|
|
21
|
-
result = Net::HTTP.get(uri)
|
|
22
|
-
JSON.parse(result)['text']
|
|
23
|
-
end
|
|
21
|
+
def default_languages
|
|
22
|
+
@default_lang
|
|
23
|
+
end
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
def translate(text, packet = {})
|
|
26
|
+
lang = packet[:lang] || @default_lang || 'ru'
|
|
27
|
+
uri = URI.parse("https://translate.yandex.net/api/v1.5/tr.json/translate?key=#{@api_key}&text=#{URI.encode(text)}&lang=#{lang}")
|
|
28
|
+
result = Net::HTTP.get(uri)
|
|
29
|
+
JSON.parse(result)['text']
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def languages
|
|
33
|
+
uri = URI.parse("https://translate.yandex.net/api/v1.5/tr.json/getLangs?key=#{@api_key}&ui=en")
|
|
34
|
+
result = Net::HTTP.get(uri)
|
|
35
|
+
JSON.parse(result)['langs']
|
|
30
36
|
end
|
|
37
|
+
end
|
|
31
38
|
end
|
|
32
39
|
end
|
|
Binary file
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yandex_tranlator_IS
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- IlyaSedov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-11-
|
|
11
|
+
date: 2019-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -55,6 +55,7 @@ files:
|
|
|
55
55
|
- bin/setup
|
|
56
56
|
- lib/yandex_tranlator_IS.rb
|
|
57
57
|
- lib/yandex_tranlator_IS/version.rb
|
|
58
|
+
- yandex_tranlator_IS-0.1.0.gem
|
|
58
59
|
- yandex_tranlator_IS.gemspec
|
|
59
60
|
homepage: https://github.com/IlyaSedov
|
|
60
61
|
licenses:
|