Module: Glassfrog::REST::Get

Defined in:
lib/glassfrog/rest/get.rb

Overview

Encapsulates all GET requests.

Class Method Summary collapse

Class Method Details

.get(client, path, options) ⇒ Array<Hash>

Sends a GET request.

Parameters:

  • client (Glassfrog::Client)

    Client that will send the request.

  • path (String)

    Path to send request to.

  • options (Hash)

    Options being sent in the request.

Returns:

  • (Array<Hash>)

    Array containing Hashes of objects fetched.



16
17
18
19
# File 'lib/glassfrog/rest/get.rb', line 16

def self.get(client, path, options)
  path = options[:id] ? path + '/' + options.delete(:id).to_s : path
  Glassfrog::REST::Request.new(client, :get, path, options).perform
end

.irregular_get(client, type, path, options) ⇒ Array<Hash>

Handles GET requests for objects that do not have a native get with ID method on GlassFrog.

Parameters:

  • client (Glassfrog::Client)

    Client that will send the request.

  • type (Symbol)

    The symbol of the object type being fetched to be used as a key in the response hash.

  • path (String)

    Path to send request to.

  • options (Hash)

    Options being sent in the request.

Returns:

  • (Array<Hash>)

    Array containing Hashes of objects fetched.



29
30
31
32
33
34
35
36
37
# File 'lib/glassfrog/rest/get.rb', line 29

def self.irregular_get(client, type, path, options)
  if options.is_a?(Hash) && options[:id]
    response = get(client, path, {})
    if response[type] then response[type].select! { |object| object[:id] == options[:id] } end
  else
    response = get(client, path, options)
  end
  response
end