yandex_predictor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4928147358a4c582e881133977b2361d7c9e8903
4
+ data.tar.gz: 7d71925af3bce4c44c4d1325cc89ba1d97b27d70
5
+ SHA512:
6
+ metadata.gz: 3daa30c31bb33b57e0c05987cbb275fddda1b5a6475b3ba2ec3865f016238a910d18a1aaa9d5b536185c3b21b736218868eed163420224e66915d3d5cb6a25d7
7
+ data.tar.gz: cf9aaa2544bc197878fb5ef3d39ffbab476ee51eb7dacf7115bafa0668e875388d00ab94673161195ed1db373be2522449064d865d1e06b4af9759358a9d8ad3
@@ -0,0 +1,38 @@
1
+ module Yandex
2
+ class Client
3
+ include HTTParty
4
+ base_uri 'https://predictor.yandex.net/api/v1/predict.json/'
5
+
6
+ attr_reader :access_token
7
+
8
+ format :json
9
+
10
+ def initialize(access_token)
11
+ @access_token = access_token || ENV['PREDICTOR_ACCESS_TOKEN']
12
+ end
13
+
14
+ def langs
15
+ @langs ||= visit('/getLangs').parsed_response
16
+ end
17
+ alias get_langs langs
18
+
19
+ def complete(q, lang)
20
+ options = { q: q, lang: lang }
21
+ visit('/complete', options).parsed_response
22
+ end
23
+
24
+ def visit(address, options = {})
25
+ response = self.class.post address, body: options.merge(key: access_token)
26
+ check_errors(response)
27
+ response
28
+ end
29
+
30
+ private
31
+
32
+ def check_errors(response)
33
+ if response.code && (response.code.to_i != 200)
34
+ raise ApiError, response['message']
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Yandex
2
+ class Predictor
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'yandex/predictor/version'
2
+ require 'httparty'
3
+ require "yandex/client"
4
+
5
+ module YandexPredictor
6
+ class ApiError < StandardError; end
7
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yandex_predictor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladislav Dyachenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Client for Yandex Predictor Service API.
84
+ email:
85
+ - vla-dy@yandex.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/yandex/client.rb
91
+ - lib/yandex/predictor/version.rb
92
+ - lib/yandex_predictor.rb
93
+ homepage: https://github.com/wowinter13/yandex_predictor
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Yandex Predictor API
117
+ test_files: []