Class: ApiClient::Dispatcher::Parallel

Inherits:
Object
  • Object
show all
Defined in:
lib/api-client/dispatcher/parallel.rb

Overview

ApiClient::Dispatcher provides methods to make requests using typhoeus

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requisition) ⇒ Parallel

Initialize a new object and save the request in a instance variable.

Parameters:

  • requisition (Typhoeus::Request)

    the requisition object.


6
7
8
# File 'lib/api-client/dispatcher/parallel.rb', line 6

def initialize(requisition)
  @requisition = requisition
end

Class Method Details

.delete(url, header = {}) ⇒ Typhoeus::Request

Make a delete request and returns it.

Parameters:

  • url (String)

    of the api request.

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

    attributes of the request.

Returns:

  • (Typhoeus::Request)

    the response object.


69
70
71
# File 'lib/api-client/dispatcher/parallel.rb', line 69

def self.delete(url, header = {})
  new(::Typhoeus.Request.new(url, :method => :delete, :headers => ApiClient.config.header.merge(header)))
end

.get(url, header = {}) ⇒ Typhoeus::Request

Make a get request and returns it.

Parameters:

  • url (String)

    of the api request.

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

    attributes of the request.

Returns:

  • (Typhoeus::Request)

    the response object.


30
31
32
# File 'lib/api-client/dispatcher/parallel.rb', line 30

def self.get(url, header = {})
  new(::Typhoeus::Request.new(url, :headers => ApiClient.config.header.merge(header)))
end

.patch(url, args, header = {}) ⇒ Typhoeus::Request

Make a patch request and returns it.

Parameters:

  • url (String)

    of the api request.

  • args (Hash)

    attributes of object.

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

    attributes of the request.

Returns:

  • (Typhoeus::Request)

    the response object.


60
61
62
# File 'lib/api-client/dispatcher/parallel.rb', line 60

def self.patch(url, args, header = {})
  new(::Typhoeus.Request.new(url, :method => :patch, :body => args, :headers => ApiClient.config.header.merge(header)))
end

.post(url, args, header = {}) ⇒ Typhoeus::Request

Make a post request and returns it.

Parameters:

  • url (String)

    of the api request.

  • args (Hash)

    attributes of object.

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

    attributes of the request.

Returns:

  • (Typhoeus::Request)

    the response object.


40
41
42
# File 'lib/api-client/dispatcher/parallel.rb', line 40

def self.post(url, args, header = {})
  new(::Typhoeus.Request.new(url, :method => :post, :body => args, :headers => ApiClient.config.header.merge(header)))
end

.put(url, args, header = {}) ⇒ Typhoeus::Request

Make a put request and returns it.

Parameters:

  • url (String)

    of the api request.

  • args (Hash)

    attributes of object.

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

    attributes of the request.

Returns:

  • (Typhoeus::Request)

    the response object.


50
51
52
# File 'lib/api-client/dispatcher/parallel.rb', line 50

def self.put(url, args, header = {})
  new(::Typhoeus.Request.new(url, :method => :put, :body => args, :headers => ApiClient.config.header.merge(header)))
end

Instance Method Details

#on_complete_update(variable) ⇒ Object

When the requisition finish, this method update the given object with the response.

Parameters:


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/api-client/dispatcher/parallel.rb', line 13

def on_complete_update(variable)
  @requisition.on_complete do |response|
    attributes = ApiClient::Parser.response(response, response.effective_url)
    if variable.instance_of?(ApiClient::Collection)
      variable.update(attributes)
    else
      variable.attributes = attributes
    end
  end
  ApiClient.config.hydra.queue @requisition
end