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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9ca2cca961e4920795564acf705f031f0b23c3a25a7124bb8cc118d306231b0
4
- data.tar.gz: 555abfa17f980445b50892c91e46d597871ed7983226f0de50be7ed2239680bc
3
+ metadata.gz: 702a0fd18a6b78cb75707c6911e96da39ddcda9900561fcedd76c6a327e676ab
4
+ data.tar.gz: 4045603cc4851997b43a83ed5aed51d925024d30671c4d51a97a09ccd2694a5d
5
5
  SHA512:
6
- metadata.gz: 40679811bba1dbb543487a7440d21b4ab6d2f441fdc7026c9b5df9a6bd8adf580f4c9e03a77b52a4b6cd7984048fdb0bed76133abb4487331af9bd289f5b3e64
7
- data.tar.gz: 307247155b94adf53ef90277b1ba2411c514c108f8a33012bff0087fbd93a735ec1909ce7c462e02b0d14262900e9a94c73b6d108cf633489cb26644a256dde2
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
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/yandex_tranlator_IS. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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/[USERNAME]/yandex_tranlator_IS/blob/master/CODE_OF_CONDUCT.md).
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).
@@ -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
- attr_accessor :api_key
8
+ class << self
9
+ def start
10
+ @api_key
11
+ end
7
12
 
8
- def self.start
9
- @api_key
10
- end
13
+ def apikey(api_key)
14
+ @api_key = api_key
15
+ end
11
16
 
12
- def self.apikey(api_key)
13
- @api_key=api_key
14
- end
17
+ def default_lang(lang)
18
+ @default_lang = lang
19
+ end
15
20
 
16
- def self.translate(packet={})
17
- text = packet[:text]||' '
18
- lang = packet[:lang]||'ru'
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
- def languages
26
- uri = URI('https://translate.yandex.net/api/v1.5/tr.json/getLangs?' \
27
- "key=#{@api_key}&ui=en")
28
- result = Net::HTTP.get(uri)
29
- JSON.parse(result)['langs']
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
@@ -1,3 +1,3 @@
1
1
  module YandexTranlatorIS
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-01 00:00:00.000000000 Z
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: