Class: PolyAnalyst6API::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/polyanalyst6api/request.rb

Overview

This class allows to construct requests, execute them and process theri responses

Instance Method Summary collapse

Constructor Details

#initialize(base_url, sid, url, method, params) ⇒ Request

Returns an instance of Request.

Parameters:

  • base_url (String)

    Base part of url (host, port, API version)

  • sid (String)

    A session SID

  • url (String)

    Request specific url part of an url

  • method (String)

    Http method of a request

  • params (String)

    Parameters


12
13
14
15
16
17
18
# File 'lib/polyanalyst6api/request.rb', line 12

def initialize(base_url, sid, url, method, params)
  @base_url = base_url
  @sid = sid
  @url = url
  @method = method
  @params = params
end

Instance Method Details

#perform! {|response| ... } ⇒ Hash, custom

Executes the request (and allows response manual processing)

Yields:

  • (response)

    Manual reponse processing

Yield Parameters:

  • response (RestClient::Response)

    A response to process

Yield Returns:

  • (custom)

    The result of a block

Returns:

  • (Hash)

    The parsed response body (default)

  • (custom)

    The result of passed block (if passed)

Raises:

  • (StandardError)

    An exception with corresponding error message


27
28
29
30
31
32
33
34
35
# File 'lib/polyanalyst6api/request.rb', line 27

def perform!
  begin
    resp = RestClient::Request.execute full_params
  rescue RestClient::InternalServerError => e
    raise JSON.parse(e.response.body)[1]
  end
  return yield(resp) if block_given? # Allowing manual response processing
  JSON.parse(resp.body)
end