Class: IsprasAPI

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/ispapi/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.



11
12
13
14
15
16
17
18
19
# File 'lib/ispapi/ispras_api.rb', line 11

def initialize(key, name, ver)
  if key && key.size == 40
    self.class.base_uri ROOT_URL % [name, ver]
    self.class.default_params apikey: key
    @nori = Nori.new(parser: :rexml, convert_tags_to: lambda { |tag| tag.snakecase.to_sym })
  else
    raise ApiError, 'Please provide proper apikey'
  end
end

Instance Method Details

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



21
22
23
24
25
26
# File 'lib/ispapi/ispras_api.rb', line 21

def GET(path='', params={})
  options = { query: params }
  response = self.class.get "/#{path}", options
  check_error response unless response.code == 200
  hash = @nori.parse response.body
end

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



28
29
30
31
32
33
# File 'lib/ispapi/ispras_api.rb', line 28

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