Sha256: b902d0041acfb18be5069bbe2836d563b9f6335dddeb588c27b2d358bdb8b02a

Contents?: true

Size: 1002 Bytes

Versions: 5

Compression:

Stored size: 1002 Bytes

Contents

# frozen_string_literal: true

module AtlasRb
  class Collection < Resource
    ROUTE = "/collections/"

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

    def self.create(id)
      # params[:parent_id]
      JSON.parse(connection({ parent_id: id }).post(ROUTE)&.body)["collection"]
    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({ metadata: values }).patch(ROUTE + id)&.body)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
atlas_rb-0.0.41 lib/atlas_rb/collection.rb
atlas_rb-0.0.40 lib/atlas_rb/collection.rb
atlas_rb-0.0.39 lib/atlas_rb/collection.rb
atlas_rb-0.0.38 lib/atlas_rb/collection.rb
atlas_rb-0.0.37 lib/atlas_rb/collection.rb