yandex_cloud 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +1 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +12 -3
- data/README.md +93 -4
- data/lib/yandex_cloud.rb +1 -0
- data/lib/yandex_cloud/translate.rb +24 -0
- data/lib/yandex_cloud/translate/detect.rb +15 -0
- data/lib/yandex_cloud/translate/languages.rb +15 -0
- data/lib/yandex_cloud/translate/translate.rb +15 -0
- data/lib/yandex_cloud/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08e9fc757c30c900829a38de1b39211d48a3cbd087a0c906acb2dd94f2ea5c93'
|
4
|
+
data.tar.gz: 11b41c648e0e050e459c0b6702faa6b65f75f2518d0be09bf1709bd00b576898
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a359eed84de6a8a93a8930896fe5d536fa82ed7439c48ea9b5cb4a0a9f41975ba3ccbd69e73ee7708c2688e895a273b2d17ba8bfa483c60ac069e529d431a461
|
7
|
+
data.tar.gz: 7f2386eebf827e70bd653893738256ab31237c1f73f60b28e98fa32cf75e9027f5ddab412e8d6a587ea717bf5ec6a08e4500e5f2d61586ddc104afcaf72e3422
|
data/.env.example
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,12 +4,21 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
##
|
7
|
+
## [0.3.0] - 2019-02-01
|
8
|
+
### Added
|
9
|
+
- languages() in module YandexCloud::Translate
|
10
|
+
- detect() in module YandexCloud::Translate
|
11
|
+
- translate() in module YandexCloud::Translate
|
12
|
+
|
13
|
+
### Modified
|
14
|
+
- README
|
15
|
+
|
16
|
+
## [0.2.0] - 2019-02-01
|
8
17
|
### Added
|
9
18
|
- CHANGELOG
|
10
19
|
- dotenv support
|
11
|
-
- YandexCloud::Auth with token()
|
12
|
-
- specs for YandexCloud::Auth
|
20
|
+
- YandexCloud::Auth module with token()
|
21
|
+
- specs for token() in module YandexCloud::Auth
|
13
22
|
|
14
23
|
### Modified
|
15
24
|
- README
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ You can use your Oauth token directly in spesific requests or put it to the ENV
|
|
28
28
|
|
29
29
|
## Using
|
30
30
|
|
31
|
-
|
31
|
+
## Get IAM-token for cloud API access
|
32
32
|
|
33
33
|
Request for getting IAM-token for access to cloud API. Valid 12 hours.
|
34
34
|
|
@@ -37,7 +37,7 @@ Request for getting IAM-token for access to cloud API. Valid 12 hours.
|
|
37
37
|
auth_service = YandexCloud::Auth.new
|
38
38
|
auth_service.token
|
39
39
|
|
40
|
-
# or with oauth_token in
|
40
|
+
# or with oauth_token in service declaration
|
41
41
|
auth_service = YandexCloud::Auth.new(oauth_token: oauth_token)
|
42
42
|
auth_service.token
|
43
43
|
```
|
@@ -46,10 +46,99 @@ auth_service.token
|
|
46
46
|
|
47
47
|
```ruby
|
48
48
|
# successful response
|
49
|
-
{
|
49
|
+
{ 'iamToken' => iam_token }
|
50
50
|
|
51
51
|
# response with errors
|
52
|
-
{
|
52
|
+
{ 'code' => 16, 'message' => 'Token is invalid or has expired.', 'details' => [...] }
|
53
|
+
```
|
54
|
+
|
55
|
+
## Translate service
|
56
|
+
|
57
|
+
### Configuration
|
58
|
+
|
59
|
+
For using Translate service you need additionally get FOLDER_ID.
|
60
|
+
|
61
|
+
Instruction for getting FOLDER_ID is [here](https://cloud.yandex.com/docs/translate/concepts/auth)
|
62
|
+
|
63
|
+
You can use your FOLDER_ID directly in spesific requests or put it to the ENV variables.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
# with FOLDER_ID in ENV
|
67
|
+
translator = YandexCloud::Translate.new(iam_token: iam_token)
|
68
|
+
|
69
|
+
# or with FOLDER_ID in service declaration
|
70
|
+
translator = YandexCloud::Translate.new(iam_token: iam_token, folder_id: '12345')
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Options
|
74
|
+
|
75
|
+
iam_token - IAM-token, required
|
76
|
+
folder_id - folder ID of your account at YandexCloud, optional
|
77
|
+
|
78
|
+
### Supported languages
|
79
|
+
|
80
|
+
Request for getting list of supported languages is #languages.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
translator.languages()
|
84
|
+
```
|
85
|
+
|
86
|
+
#### Responses
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# successful response
|
90
|
+
{ 'languages' => [...] }
|
91
|
+
|
92
|
+
# response with errors
|
93
|
+
{ 'error_message' => '' }
|
94
|
+
```
|
95
|
+
|
96
|
+
### Detection
|
97
|
+
|
98
|
+
Request for detecting language of text is #detect.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
translator.detect(text: 'Hello')
|
102
|
+
```
|
103
|
+
|
104
|
+
#### Options
|
105
|
+
|
106
|
+
text - text for detection, required
|
107
|
+
hint - list of possible languages, optional, example - 'en,ru'
|
108
|
+
|
109
|
+
#### Responses
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
# successful response
|
113
|
+
{ 'language' => 'es' }
|
114
|
+
|
115
|
+
# response with errors
|
116
|
+
{ 'error_message' => '' }
|
117
|
+
```
|
118
|
+
|
119
|
+
### Translation
|
120
|
+
|
121
|
+
Request for translating text is #translate.
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
translator.translate(text: 'Hola', target: 'en')
|
125
|
+
```
|
126
|
+
|
127
|
+
#### Options
|
128
|
+
|
129
|
+
text - text for detection, required
|
130
|
+
source - source language, ISO 639-1 format (like 'en'), optional
|
131
|
+
target - target language, ISO 639-1 format (like 'ru'), required
|
132
|
+
format - text format, one of the [plain|html], default - plain, optional
|
133
|
+
|
134
|
+
#### Responses
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
# successful response
|
138
|
+
{ 'translations' => [{ 'text' => 'Hello' }]}
|
139
|
+
|
140
|
+
# response with errors
|
141
|
+
{ 'error_message' => '' }
|
53
142
|
```
|
54
143
|
|
55
144
|
## Contributing
|
data/lib/yandex_cloud.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require_relative 'translate/languages'
|
3
|
+
require_relative 'translate/detect'
|
4
|
+
require_relative 'translate/translate'
|
5
|
+
|
6
|
+
module YandexCloud
|
7
|
+
# Authentification requests
|
8
|
+
class Translate
|
9
|
+
include HTTParty
|
10
|
+
include YandexCloud::Translate::Languages
|
11
|
+
include YandexCloud::Translate::Detect
|
12
|
+
include YandexCloud::Translate::Translate
|
13
|
+
|
14
|
+
base_uri 'https://translate.api.cloud.yandex.net/translate/v1'
|
15
|
+
format :json
|
16
|
+
|
17
|
+
attr_reader :iam_token, :folder_id
|
18
|
+
|
19
|
+
def initialize(args = {})
|
20
|
+
@iam_token = args[:iam_token]
|
21
|
+
@folder_id = args[:folder_id] || ENV['TRANSLATE_FOLDER_ID']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module YandexCloud
|
2
|
+
class Translate
|
3
|
+
# Module for detecting language of the text
|
4
|
+
module Detect
|
5
|
+
# Detect
|
6
|
+
def detect(args = {})
|
7
|
+
# define params for request
|
8
|
+
body = { 'folderId' => folder_id, 'hint' => args[:hint], 'text' => args[:text] }
|
9
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => "Bearer #{iam_token}" }
|
10
|
+
# make request
|
11
|
+
self.class.post('/detect', query: body, headers: headers).parsed_response
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module YandexCloud
|
2
|
+
class Translate
|
3
|
+
# Module for getting list of languages from Translation service
|
4
|
+
module Languages
|
5
|
+
# Get list
|
6
|
+
def languages
|
7
|
+
# define params for request
|
8
|
+
body = { 'folderId' => folder_id }
|
9
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => "Bearer #{iam_token}" }
|
10
|
+
# make request
|
11
|
+
self.class.post('/languages', query: body, headers: headers).parsed_response
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module YandexCloud
|
2
|
+
class Translate
|
3
|
+
# Module for translation for text or phrase
|
4
|
+
module Translate
|
5
|
+
# Translate
|
6
|
+
def translate(args = {})
|
7
|
+
# define params for request
|
8
|
+
body = { 'folderId' => folder_id, 'text' => args[:text], 'source' => args[:source], 'target' => args[:target], 'format' => args[:format] }
|
9
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => "Bearer #{iam_token}" }
|
10
|
+
# make request
|
11
|
+
self.class.post('/translate', query: body, headers: headers).parsed_response
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/yandex_cloud/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Bogdanov
|
@@ -103,6 +103,10 @@ files:
|
|
103
103
|
- lib/yandex_cloud.rb
|
104
104
|
- lib/yandex_cloud/auth.rb
|
105
105
|
- lib/yandex_cloud/auth/iam_token.rb
|
106
|
+
- lib/yandex_cloud/translate.rb
|
107
|
+
- lib/yandex_cloud/translate/detect.rb
|
108
|
+
- lib/yandex_cloud/translate/languages.rb
|
109
|
+
- lib/yandex_cloud/translate/translate.rb
|
106
110
|
- lib/yandex_cloud/version.rb
|
107
111
|
- yandex_cloud.gemspec
|
108
112
|
homepage: https://github.com/kortirso/yandex-cloud
|