Class: Puree::Collection

Inherits:
Resource show all
Defined in:
lib/puree/collection.rb

Overview

Collection resource

Instance Method Summary collapse

Methods inherited from Resource

#content, #response, #set_content

Constructor Details

#initialize(resource_type: nil) ⇒ Collection

Returns a new instance of Collection.



7
8
9
10
# File 'lib/puree/collection.rb', line 7

def initialize(resource_type: nil)
  super(resource_type)
  @uuids = []
end

Instance Method Details

#get(endpoint: nil, username: nil, password: nil, qty: nil) ⇒ HTTParty::Response

Get

Parameters:

  • endpoint (String) (defaults to: nil)
  • username (String) (defaults to: nil)
  • password (String) (defaults to: nil)
  • qty (Integer) (defaults to: nil)

Returns:

  • (HTTParty::Response)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/puree/collection.rb', line 19

def get(endpoint:nil, username:nil, password:nil, qty:nil)
  # strip any trailing slash
  @endpoint = endpoint.sub(/(\/)+$/, '')
  @auth = Base64::strict_encode64(username + ':' + password)

  @options = {
      latest_api: true,
      resource_type: @resource_type.to_sym,
      rendering: :system,
      qty: qty
  }
  headers = {
      'Accept' => 'application/xml',
      'Authorization' => 'Basic ' + @auth
  }
  query = {}
  query['rendering'] = @options[:rendering]
  if @options[:qty]
    query['window.size'] = @options[:qty]
  end

  @response = HTTParty.get(url, query: query, headers: headers)
end

#uuidArray<String>

Array of UUIDs

Returns:

  • (Array<String>)


47
48
49
50
# File 'lib/puree/collection.rb', line 47

def uuid
  collect_uuid
  @uuids
end