Class: IsprasAPI

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ispras-api/ispras_api.rb

Direct Known Subclasses

TexterraAPI, TwitterAPI

Constant Summary collapse

ROOT_URL =

debug_output $stdout

'api.ispras.ru/%s/%s'

Instance Method Summary collapse

Constructor Details

#initialize(key, name, ver) ⇒ IsprasAPI

Returns a new instance of IsprasAPI.



10
11
12
13
14
15
16
17
18
# File 'lib/ispras-api/ispras_api.rb', line 10

def initialize(key, name, ver)
  if key && key.size == 40
    self.class.base_uri format(ROOT_URL, name, ver)
    self.class.default_params apikey: key
    self.class.read_timeout 60
  else
    fail ApiError, 'Please provide proper apikey'
  end
end

Instance Method Details

#GET(path = '', params = {}) ⇒ Object



20
21
22
23
24
# File 'lib/ispras-api/ispras_api.rb', line 20

def GET(path = '', params = {})
  options = { query: params }
  response = self.class.get "/#{path}", options
  response.code == 200 ? response.parsed_response : check_error(response)
end

#POST(path = '', params = {}, form = {}) ⇒ Object



26
27
28
29
30
# File 'lib/ispras-api/ispras_api.rb', line 26

def POST(path = '', params = {}, form = {})
  options = { query: params, body: form }
  response = self.class.post "/#{path}", options
  response.code == 200 ? response.parsed_response : check_error(response)
end