Class: ArchivesSpace::Client

Inherits:
Object
  • Object
show all
Includes:
Pagination, Task
Defined in:
lib/archivesspace/client/cli.rb,
lib/archivesspace/client/client.rb,
lib/archivesspace/client/version.rb,
lib/archivesspace/client/cli/exec.rb,
lib/archivesspace/client/cli/version.rb

Defined Under Namespace

Modules: CLI

Constant Summary collapse

NAME =
"ArchivesSpaceClient"
TOKEN =
"X-ArchivesSpace-Session"
VERSION =
"0.5.1"

Constants included from Pagination

Pagination::ENDPOINTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Task

#group_user_assignment, #login, #password_reset

Methods included from Pagination

#all

Constructor Details

#initialize(config = Configuration.new) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
# File 'lib/archivesspace/client/client.rb', line 14

def initialize(config = Configuration.new)
  unless config.is_a? ArchivesSpace::Configuration
    raise ConfigurationError, "expected ArchivesSpace::Configuration, got #{config.class}"
  end

  @config = config
  @context = nil
  @token = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/archivesspace/client/client.rb', line 9

def config
  @config
end

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/archivesspace/client/client.rb', line 9

def context
  @context
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/archivesspace/client/client.rb', line 8

def token
  @token
end

Instance Method Details

#backend_versionObject



24
25
26
# File 'lib/archivesspace/client/client.rb', line 24

def backend_version
  get "version"
end

#delete(path) ⇒ Object



40
41
42
# File 'lib/archivesspace/client/client.rb', line 40

def delete(path)
  request "DELETE", path
end

#get(path, options = {}) ⇒ Object



28
29
30
# File 'lib/archivesspace/client/client.rb', line 28

def get(path, options = {})
  request "GET", path, options
end

#post(path, payload, params = {}) ⇒ Object



32
33
34
# File 'lib/archivesspace/client/client.rb', line 32

def post(path, payload, params = {})
  request "POST", path, {body: payload.to_json, query: params}
end

#put(path, payload, params = {}) ⇒ Object



36
37
38
# File 'lib/archivesspace/client/client.rb', line 36

def put(path, payload, params = {})
  request "PUT", path, {body: payload.to_json, query: params}
end

#repository(id) ⇒ Object

Scoping requests



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/archivesspace/client/client.rb', line 45

def repository(id)
  return use_global_repository if id.nil?

  begin
    Integer(id)
  rescue ArgumentError, TypeError
    raise RepositoryIdError, "Invalid Repository id: #{id}"
  end

  new_context = "repositories/#{id}"
  return @context = new_context unless block_given?

  previous = @context
  @context = new_context
  begin
    yield
  ensure
    @context = previous
  end
end

#use_global_repositoryObject



66
67
68
# File 'lib/archivesspace/client/client.rb', line 66

def use_global_repository
  @context = nil
end