yandex_translate_api_gem 0.1.0 → 0.1.2

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: 1f31af32b7e05b0adb3cc8a4f456f36d607713b8ef70809fffe0e8b36bb25bdb
4
- data.tar.gz: 93f263940f7960753483538448ffc58499c6db2a9ab3a4b71e3a72f981b1a101
3
+ metadata.gz: 7e175bf480597e0569fd3e2027fdcb6e19c50988426ebc247eaf04deff9e5a07
4
+ data.tar.gz: fcd1180c403a71a0d5940081666af6bf8af012dc1d20ae60dae8295807d9f00c
5
5
  SHA512:
6
- metadata.gz: 0c92323223bbb5e2eb9521b8b55643e1a9898272c3693739b91ad9860492d96c15804cb0d5ad9ad7e178715f9aae39cd304a7b4c548b3e5ed6c15927655382b1
7
- data.tar.gz: a5db13cfba2c6096ac8fd580578f90280d3e29eb7f496d1e94cb50d7d8782680e15f877a827a6d764aee04da6269ade7319da33c6abc20c25773cf35206291ef
6
+ metadata.gz: 9ba289669f588538822557cc67d7cdecb6eee6b71089a9d2575399e85dbbbc876835d749d8d0f36edca1fac8821ed98c08a286b7520117d52ab5cdc4d61c291b
7
+ data.tar.gz: 69b59448f2b8cb79e042e7cb168f53923dfec0fccbcf1ae34e7343d08cb09d7f4f8ad357fbeb322436d623ce6c87caccfd8fb67ae411afa1bbff6088550977b7
data/.DS_Store ADDED
Binary file
data/.idea/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+
2
+ # Default ignored files
3
+ /workspace.xml
data/.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.6.3-p62" project-jdk-type="RUBY_SDK" />
7
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/yandex_translate_api_gem.iml" filepath="$PROJECT_DIR$/.idea/yandex_translate_api_gem.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$" />
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ </component>
11
+ </module>
data/README.md CHANGED
@@ -4,9 +4,8 @@
4
4
 
5
5
  Add this line to your application's Gemfile:
6
6
 
7
- ```ruby
8
- gem 'yandex_translate_api_gem'
9
- ```
7
+ gem 'yandex_translate_api_gem'
8
+
10
9
 
11
10
  And then execute:
12
11
 
@@ -18,23 +17,28 @@ Or install it yourself as:
18
17
 
19
18
  ## Usage
20
19
 
21
- TODO: Write usage instructions here
20
+ translator = YandexTranslateApiGem::Translate
22
21
 
23
- ## Development
24
22
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
+ Create API Key
26
24
 
27
- 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).
25
+ translator.api_key = 'your key'
28
26
 
29
- ## Contributing
27
+ Get api_key from https://translate.yandex.ru/developers/keys.
30
28
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yandex_translate_api_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/yandex_translate_api_gem/blob/master/CODE_OF_CONDUCT.md).
29
+ Create default lang
32
30
 
31
+ translator.default_lang = 'default lang'
33
32
 
34
- ## License
33
+ To get list of possible translation directions use langs method:
34
+
35
+ translator.langs
35
36
 
36
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
37
 
38
- ## Code of Conduct
38
+ To translate text use translate method:
39
39
 
40
- Everyone interacting in the YandexTranslateApiGem project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/yandex_translate_api_gem/blob/master/CODE_OF_CONDUCT.md).
40
+ translator.translate('Men', lang: 'fi')
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module YandexTranslateApiGem
2
- VERSION = "0.1.0"
3
- end
2
+ VERSION = "0.1.2"
3
+ end
@@ -1,40 +1,37 @@
1
- require "yandex_translate_api_gem/version"
1
+ require 'yandex_translate_api_gem/version'
2
2
  require 'net/http'
3
3
  require 'json'
4
4
  require 'uri'
5
5
 
6
6
  module YandexTranslateApiGem
7
- class Error < StandardError; end
8
-
9
7
  class Translate
10
- attr_accessor :api_key
11
-
12
- def self.get_api_key(key)
13
- @api_key = key
14
- end
8
+ class << self
9
+ def api_key=(key)
10
+ @api_key = key
11
+ end
15
12
 
16
- def self.def_lang(lang)
17
- @def_lang = lang
18
- end
13
+ def default_lang=(lang)
14
+ @default_lang = lang
15
+ end
19
16
 
20
- def self.translate(opt = {})
21
- text = opt[:text] || 'Hello'
22
- lang = opt[:lang] || 'ru'
23
- uri = URI("https://translate.yandex.net/api/v1.5/tr.json/translate?key=#{@api_key}&text=#{URI.encode(text)}&lang=#{lang}")
24
- result = Net::HTTP.get(uri)
25
- JSON.parse(result)['text']
26
- end
17
+ def translate(text, opt = {})
18
+ lang = opt[:lang] || @default_lang || 'ru'
19
+ uri = URI("https://translate.yandex.net/api/v1.5/tr.json/translate?key=#{@api_key}&text=#{URI.encode(text)}&lang=#{lang}")
20
+ result = Net::HTTP.get(uri)
21
+ JSON.parse(result)['text']
22
+ end
27
23
 
28
- def self.get_langs
29
- uri = URI("https://translate.yandex.net/api/v1.5/tr.json/getLangs?ui=en&key=#{@api_key}")
30
- result = Net::HTTP.get(uri)
31
- JSON.parse(result)['langs']
24
+ def langs
25
+ uri = URI("https://translate.yandex.net/api/v1.5/tr.json/getLangs?ui=en&key=#{@api_key}")
26
+ result = Net::HTTP.get(uri)
27
+ JSON.parse(result)['langs']
28
+ end
32
29
  end
33
30
  end
34
-
35
- # translate = YandexTranslateApiGem::Translate
36
- # translate.get_api_key("trnsl.1.1.20191025T110335Z.4b11526739cc9f02.61937478c797b0f19512e761bc467d4ef9a89d54")
37
- # translate.get_langs
38
- # translate.translate(text: 'Men', lang: 'fi')
39
-
40
31
  end
32
+
33
+ # translate = YandexTranslateApiGem::Translate
34
+ # translate.api_key = "trnsl.1.1.20191025T110335Z.4b11526739cc9f02.61937478c797b0f19512e761bc467d4ef9a89d54"
35
+ # translate.default_lang = "default_lang"
36
+ # translate.langs
37
+ # translate.translate('Men', lang: 'fi')
Binary file
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.summary = %q{Yandex Translate API}
10
10
  spec.description = %q{Library for Yandex Translate API}
11
- spec.homepage = ""
11
+ spec.homepage = "https://github.com/NatashaMalakhova/yandex_translate_api_gem"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex_translate_api_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Malakhova Natasha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2019-11-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Library for Yandex Translate API
14
14
  email:
@@ -17,7 +17,13 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".DS_Store"
20
21
  - ".gitignore"
22
+ - ".idea/.gitignore"
23
+ - ".idea/misc.xml"
24
+ - ".idea/modules.xml"
25
+ - ".idea/vcs.xml"
26
+ - ".idea/yandex_translate_api_gem.iml"
21
27
  - ".travis.yml"
22
28
  - CODE_OF_CONDUCT.md
23
29
  - Gemfile
@@ -28,8 +34,9 @@ files:
28
34
  - bin/setup
29
35
  - lib/yandex_translate_api_gem.rb
30
36
  - lib/yandex_translate_api_gem/version.rb
37
+ - yandex_translate_api_gem-0.1.0.gem
31
38
  - yandex_translate_api_gem.gemspec
32
- homepage: ''
39
+ homepage: https://github.com/NatashaMalakhova/yandex_translate_api_gem
33
40
  licenses:
34
41
  - MIT
35
42
  metadata: {}