Class: AtlasRb::Community
- Defined in:
- lib/atlas_rb/community.rb
Constant Summary collapse
- ROUTE =
"/communities/"
Class Method Summary collapse
- .children(id) ⇒ Object
- .create(id = nil, xml_path = nil) ⇒ Object
- .destroy(id) ⇒ Object
- .find(id) ⇒ Object
- .metadata(id, values) ⇒ Object
- .mods(id, kind = nil) ⇒ Object
- .update(id, xml_path) ⇒ Object
Methods inherited from Resource
Class Method Details
.children(id) ⇒ Object
23 24 25 |
# File 'lib/atlas_rb/community.rb', line 23 def self.children(id) JSON.parse(connection({}).get(ROUTE + id + '/children')&.body) end |
.create(id = nil, xml_path = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/atlas_rb/community.rb', line 11 def self.create(id = nil, xml_path = nil) result = JSON.parse(connection({ parent_id: id }).post(ROUTE)&.body)["community"] 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/community.rb', line 19 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 |
.metadata(id, values) ⇒ Object
34 35 36 |
# File 'lib/atlas_rb/community.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/community.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/community.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 |