Class: Puree::Extractor::Collection

Inherits:
Object
  • Object
show all
Includes:
API::Authentication
Defined in:
lib/puree/extractor/collection.rb

Overview

A collection extractor can retrieve any number of resources of the same type.

Instance Method Summary collapse

Constructor Details

#initialize(config:, resource:) ⇒ Collection

Returns a new instance of Collection.

Parameters:

  • resource (Symbol)
  • config (Hash)

    a customizable set of options

Options Hash (config:):

  • :url (String)

    The URL of the Pure host.

  • :username (String)

    The username of the Pure host account.

  • :password (String)

    The password of the Pure host account.



12
13
14
15
16
# File 'lib/puree/extractor/collection.rb', line 12

def initialize(config:, resource:)
  @resource_type = resource
  @api_map = Puree::API::Map.new.get
  configure_api config
end

Instance Method Details

#countFixnum

Count of records available for a resource type.

Returns:

  • (Fixnum)


62
63
64
# File 'lib/puree/extractor/collection.rb', line 62

def count
  get_count
end

#get(limit: 0, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil) ⇒ Array<Puree::Model::Resource subclass> Also known as: find

Gets an array of objects of resource type specified in constructor.

Parameters:

  • limit (Fixnum) (defaults to: 0)
  • offset (Fixnum) (defaults to: 0)
  • created_start (String) (defaults to: nil)
  • created_end (String) (defaults to: nil)
  • modified_start (String) (defaults to: nil)
  • modified_end (String) (defaults to: nil)

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/puree/extractor/collection.rb', line 27

def get(
        limit:            0,
        offset:           0,
        created_start:    nil,
        created_end:      nil,
        modified_start:   nil,
        modified_end:     nil
)
  @response = @request.get rendering:        :system,
                           limit:            limit,
                           offset:           offset,
                           resource_type:    @resource_type,
                           created_start:    created_start,
                           created_end:      created_end,
                           modified_start:   modified_start,
                           modified_end:     modified_end
  set_content @response.body
end

#random_resourcePuree::Model::Resource subclass?

Gets a random resource of type specified in constructor.

Returns:



49
50
51
52
53
54
55
56
# File 'lib/puree/extractor/collection.rb', line 49

def random_resource
  @response = @request.get rendering:        :system,
                           limit:            1,
                           offset:           rand(0..count-1),
                           resource_type:    @resource_type
  content = set_content @response.body
  content[0] if content
end