Class: AtlasRb::Community

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

Constant Summary collapse

ROUTE =
"/communities/"

Class Method Summary collapse

Methods included from FaradayHelper

#connection, #multipart

Class Method Details

.children(id) ⇒ Object



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

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

.create(id = nil) ⇒ Object



11
12
13
# File 'lib/atlas_rb/community.rb', line 11

def self.create(id = nil)
  JSON.parse(connection({ parent_id: id }).post(ROUTE)&.body)
end

.destroy(id) ⇒ Object



15
16
17
# File 'lib/atlas_rb/community.rb', line 15

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

.find(id) ⇒ Object



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

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

.update(id, xml_path) ⇒ Object



23
24
25
26
27
28
# File 'lib/atlas_rb/community.rb', line 23

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