Class: AtlasRb::Collection

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

Constant Summary collapse

ROUTE =
"/collections/"

Class Method Summary collapse

Methods inherited from Resource

preview

Class Method Details

.children(id) ⇒ Object



23
24
25
# File 'lib/atlas_rb/collection.rb', line 23

def self.children(id)
  JSON.parse(connection({}).get(ROUTE + id + '/children')&.body)
end

.create(id, xml_path = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/atlas_rb/collection.rb', line 11

def self.create(id, xml_path = nil)
  result = JSON.parse(connection({ parent_id: id }).post(ROUTE)&.body)["collection"]
  return result unless xml_path.present?

  update(result["id"], xml_path)
  find(result["id"])
end

.destroy(id) ⇒ Object



19
20
21
# File 'lib/atlas_rb/collection.rb', line 19

def self.destroy(id)
  connection({}).delete(ROUTE + id)
end

.find(id) ⇒ Object



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

def self.find(id)
  JSON.parse(connection({}).get(ROUTE + id)&.body)["collection"]
end

.metadata(id, values) ⇒ Object



34
35
36
# File 'lib/atlas_rb/collection.rb', line 34

def self.(id, values)
  JSON.parse(connection({ metadata: values }).patch(ROUTE + id)&.body)
end

.mods(id, kind = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/atlas_rb/collection.rb', line 38

def self.mods(id, kind = nil)
  # json default, html, xml
  connection({}).get(
    ROUTE + id + '/mods' + (kind.present? ? ".#{kind}" : '')
    )&.body
end

.update(id, xml_path) ⇒ Object



27
28
29
30
31
32
# File 'lib/atlas_rb/collection.rb', line 27

def self.update(id, xml_path)
  payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path),
                                                       "application/xml",
                                                       File.basename(xml_path)) }
  JSON.parse(multipart({}).patch(ROUTE + id, payload)&.body)
end