Sha256: b32e0b5e2b4670339a8637f537ef1dab381bd9edec419434cf483e5dcc1b6cca

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

Contents

# frozen_string_literal: true

module AtlasRb
  class Community < Resource
    ROUTE = "/communities/"

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

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

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

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

    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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
atlas_rb-0.0.34 lib/atlas_rb/community.rb