yandex-dictionary 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e080ecede7634b48277b6fac44385a29a6d9485f
4
+ data.tar.gz: c954ec274fdfda1dd05f3644312acf8af0f16007
5
+ SHA512:
6
+ metadata.gz: b269932144afce0e34f3890411455d12d5d666be1cdb90bafcfa917765b631972b7dd7b20f4de8e66914c776519e0ee144c2d8cd041513d19e303c0c87050fc5
7
+ data.tar.gz: 2e53981bc5b39b4b08db43de38b7f54fbf64c12c1589606e5f6e644858a8b23e12061a669ee4c4ddca74345e3c669f0fd4fb30c61f88e7e71a7e1d59bbb52726
@@ -0,0 +1,42 @@
1
+ require_relative 'yandex_dictionary/version'
2
+ require 'httparty'
3
+
4
+ module Yandex::Dictionary
5
+ include HTTParty
6
+ base_uri 'https://dictionary.yandex.net/api/v1/dicservice.json/'
7
+
8
+ attr_accessor :api_key
9
+
10
+ class TranslationError < StandardError; end
11
+ class ApiError < StandardError; end
12
+
13
+ # List of translation directions.
14
+ def get_langs
15
+ visit '/getLangs', key: api_key
16
+ end
17
+
18
+ # Search word or phrase. Return dictionary entry.
19
+ def lookup(text, *lang)
20
+ options = { key: api_key, text: text, lang: lang.join('-') }
21
+ visit('/lookup', options)
22
+ end
23
+
24
+ def visit(address, options = {})
25
+ responce = get(address, query: options)
26
+ check_errors(responce) unless responce.code == 200
27
+ responce
28
+ end
29
+
30
+ def check_errors(responce)
31
+ raise *(case responce.code
32
+ when 401 then [ApiError, 'Invalid api key']
33
+ when 402 then [ApiError, 'Api key blocked']
34
+ when 403 then [ApiError, 'Daily request limit exceeded']
35
+ when 404 then [ApiError, 'Daily char limit exceeded']
36
+ when 413 then [TranslationError, 'Text too long']
37
+ when 501 then [TranslationError, 'Can\'t translate text in that direction']
38
+ end)
39
+ end
40
+
41
+ extend Yandex::Dictionary
42
+ end
@@ -0,0 +1,6 @@
1
+ module Yandex
2
+ module Dictionary
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
6
+
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yandex-dictionary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Smagin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Library for Yandex Dictionary API
28
+ email: smaginsergey1310@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/yandex_dictionary.rb
34
+ - lib/yandex_dictionary/version.rb
35
+ homepage: https://github.com/s-mage/yandex-dictionary
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.0.3
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Yandex Dictionary API
59
+ test_files: []
60
+ has_rdoc: