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 = {}) ⇒ Object
-
#initialize(key, name, ver) ⇒ IsprasAPI
constructor
A new instance of IsprasAPI.
- #POST(path = '', params = {}, form = {}) ⇒ Object
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 = {}) = { query: params } response = self.class.get "/#{path}", 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 = {}) = { query: params, body: form } response = self.class.post "/#{path}", response.code == 200 ? response.parsed_response : check_error(response) end |