Class: ArchivesSpace::Client::CLI::Exec

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/archivesspace/client/cli/exec.rb

Overview

ArchivesSpace::Client::CLI::Exec executes an API request

Instance Method Summary collapse

Instance Method Details

#call(type:, path:, rid: nil, payload: "{}", params: "{}") ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/archivesspace/client/cli/exec.rb', line 22

def call(type:, path:, rid: nil, payload: "{}", params: "{}", **)
  client = ArchivesSpace::Client::CLI.client
  client.repository(rid) if rid
  type = type.to_sym
  payload = JSON.parse(payload, symbolize_names: true)
  params = JSON.parse(params, symbolize_names: true)

  response = case type
  when :get
    client.get(path, params)
  when :post
    client.post(path, payload, params)
  when :put
    client.put(path, payload, params)
  when :delete
    client.delete(path)
  end
  puts JSON.generate(response.parsed)
end