Class: Yandex::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/yandex/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/yandex/client.rb', line 10

def initialize(access_token)
  @access_token = access_token || ENV['PREDICTOR_ACCESS_TOKEN']
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



6
7
8
# File 'lib/yandex/client.rb', line 6

def access_token
  @access_token
end

Instance Method Details

#complete(q, lang) ⇒ Object



19
20
21
22
# File 'lib/yandex/client.rb', line 19

def complete(q, lang)
  options = { q: q, lang: lang }
  visit('/complete', options).parsed_response
end

#langsObject Also known as: get_langs



14
15
16
# File 'lib/yandex/client.rb', line 14

def langs
  @langs ||= visit('/getLangs').parsed_response
end

#visit(address, options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/yandex/client.rb', line 24

def visit(address, options = {})
  response = self.class.post address, body: options.merge(key: access_token)
  check_errors(response)
  response
end