Sha256: 6e84393f2fcc354caaf2fcbf84e4e53e54f963bae7219d35aea5c78abe428306

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module AtlasRb
  class Work < Resource
    ROUTE = "/works/"

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

    def self.create(id)
      # params[:collection_id]
      JSON.parse(connection({ collection_id: id }).post(ROUTE)&.body)["work"]
    end

    def self.destroy(id)
      connection({}).delete(ROUTE + id)
    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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
atlas_rb-0.0.52 lib/atlas_rb/work.rb
atlas_rb-0.0.51 lib/atlas_rb/work.rb
atlas_rb-0.0.49 lib/atlas_rb/work.rb
atlas_rb-0.0.48 lib/atlas_rb/work.rb