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, #created, #metadata, #modified, #response, #set_content

Constructor Details

#initialize(api: nil, endpoint: nil, username: nil, password: nil) ⇒ Collection



11
12
13
14
15
16
17
18
19
20
# File 'lib/puree/collection.rb', line 11

def initialize(api: nil,
               endpoint: nil,
               username: nil,
               password: nil)
  super(api: api,
        endpoint: endpoint,
        username: username,
        password: password)
  @uuids = []
end

Instance Method Details

#get(limit: 20, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil) ⇒ HTTParty::Response Also known as: find

Get



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/puree/collection.rb', line 31

def get(
        limit:            20,
        offset:           0,
        created_start:    nil,
        created_end:      nil,
        modified_start:   nil,
        modified_end:     nil)

  missing = missing_credentials
  if !missing.empty?
    missing.each do |m|
      puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}"
    end
    exit
  end
  # 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,
      limit:            limit,
      offset:           offset,
      created_start:    created_start,
      created_end:      created_end,
      modified_start:   modified_start,
      modified_end:     modified_end
  }
  headers = {
      'Accept' => 'application/xml',
      'Authorization' => 'Basic ' + @auth
  }
  query = {}

  query['rendering'] = @options[:rendering]

  if @options[:limit]
    query['window.size'] = @options[:limit]
  end

  if @options[:offset]
    query['window.offset'] = @options[:offset]
  end

  if @options[:created_start]
    query['createdDate.fromDate'] = @options[:created_start]
  end

  if @options[:created_end]
    query['createdDate.toDate'] = @options[:created_end]
  end

  if @options[:modified_start]
    query['modifiedDate.fromDate'] = @options[:modified_start]
  end

  if @options[:modified_end]
    query['modifiedDate.toDate'] = @options[:modified_end]
  end

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

#uuidArray<String>

Array of UUIDs



100
101
102
103
# File 'lib/puree/collection.rb', line 100

def uuid
  collect_uuid
  @uuids
end