Class: CollectionSpace::Client

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/collectionspace/client/client.rb,
lib/collectionspace/client/version.rb

Overview

CollectionSpace client

Constant Summary collapse

VERSION =
"0.15.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#add_batch, #add_batch_job, #add_report, #all, #authority_doctypes, #count, #domain, #find, #find_relation, #get_list_types, #keyword_search, #reindex_full_text, #reset_media_blob, #run_job, #search, #service

Constructor Details

#initialize(config = Configuration.new) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
# File 'lib/collectionspace/client/client.rb', line 9

def initialize(config = Configuration.new)
  unless config.is_a? CollectionSpace::Configuration
    raise CollectionSpace::ArgumentError, "Invalid configuration object"
  end

  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/collectionspace/client/client.rb', line 7

def config
  @config
end

Instance Method Details

#delete(path) ⇒ Object



42
43
44
# File 'lib/collectionspace/client/client.rb', line 42

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

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



17
18
19
# File 'lib/collectionspace/client/client.rb', line 17

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

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



21
22
23
24
# File 'lib/collectionspace/client/client.rb', line 21

def post(path, payload, options = {})
  check_payload(payload)
  request "POST", path, {body: payload}.merge(options)
end

#post_file(file, options = {}) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
34
35
# File 'lib/collectionspace/client/client.rb', line 26

def post_file(file, options = {})
  file = File.expand_path(file)
  raise ArgumentError, "cannot find file #{file}" unless File.exist? file

  request "POST", "blobs", {
    body: {
      file: File.open(file)
    }
  }.merge(options)
end

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



37
38
39
40
# File 'lib/collectionspace/client/client.rb', line 37

def put(path, payload, options = {})
  check_payload(payload)
  request "PUT", path, {body: payload}.merge(options)
end