Class: IsprasAPI
- Inherits:
-
Object
- Object
- IsprasAPI
- Includes:
- HTTParty
- Defined in:
- lib/ispras-api/ispras_api.rb
Direct Known Subclasses
Constant Summary collapse
- ROOT_URL =
debug_output $stdout
'api.ispras.ru/%s/%s'
Instance Method Summary collapse
- #GET(path = '', params = {}, format = :xml) ⇒ Object
-
#initialize(key, name, ver) ⇒ IsprasAPI
constructor
A new instance of IsprasAPI.
- #POST(path = '', params = {}, body = {}, format = :xml) ⇒ Object
Constructor Details
#initialize(key, name, ver) ⇒ IsprasAPI
Returns a new instance of IsprasAPI.
11 12 13 14 15 16 17 18 19 |
# File 'lib/ispras-api/ispras_api.rb', line 11 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 = {}, format = :xml) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/ispras-api/ispras_api.rb', line 21 def GET(path = '', params = {}, format=:xml) = { headers: headers(format), query: params } response = self.class.get "/#{path}", response.code == 200 ? response.parsed_response : check_error(response) end |
#POST(path = '', params = {}, body = {}, format = :xml) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/ispras-api/ispras_api.rb', line 30 def POST(path = '', params = {}, body = {}, format=:xml) = { headers: headers(format), query: params, body: body } response = self.class.post "/#{path}", response.code == 200 ? response.parsed_response : check_error(response) end |