Module: Epitech::Api

Included in:
Connection
Defined in:
lib/version.rb,
lib/api/version.rb,
lib/epitech-api.rb,
lib/utils.rb

Defined Under Namespace

Modules: CheckApi, Errors, InfoApi, SearchApi Classes: Connection

Constant Summary collapse

VERSION =

Gem version

"1.0.0"
BASE_URL =

JSON API URL

'http://ws.paysdu42.fr/JSON/?'

Instance Method Summary collapse

Instance Method Details

#call_api(opts = {}) ⇒ Object

Used to call the webservice

Parameters:

  • opts (Hash) (defaults to: {})

    Hash used as URL params, formatted by #hash_to_req

Returns:

  • What the Web API is supposed to return



8
9
10
11
12
13
14
# File 'lib/utils.rb', line 8

def call_api(opts={})
  tmp = open(URI(URI.escape(BASE_URL + hash_to_req(opts)))).read
  tmp = tmp.split("\n").drop(1).join("\n") while tmp.start_with?(%Q(SSH connection failed.))
  json = JSON.parse(tmp)
  raise get_error_class(json['error']) if json['error'] != 'none'
  json['result']
end