Class: IsprasAPI
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.
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={}) = { query: params } response = self.class.get "/#{path}", 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={}) = { query: params, body: form } response = self.class.post "/#{path}", check_error response unless response.code == 200 hash = @nori.parse response.body end |