class CollectionSpace::Client

CollectionSpace client

Constants

VERSION

Attributes

config[R]

Public Class Methods

new(config = Configuration.new) click to toggle source
# 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

Public Instance Methods

delete(path) click to toggle source
# File lib/collectionspace/client/client.rb, line 42
def delete(path)
  request "DELETE", path
end
get(path, options = {}) click to toggle source
# File lib/collectionspace/client/client.rb, line 17
def get(path, options = {})
  request "GET", path, options
end
post(path, payload, options = {}) click to toggle source
# 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 = {}) click to toggle source
# 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 = {}) click to toggle source
# File lib/collectionspace/client/client.rb, line 37
def put(path, payload, options = {})
  check_payload(payload)
  request "PUT", path, {body: payload}.merge(options)
end

Private Instance Methods

check_payload(payload) click to toggle source
# File lib/collectionspace/client/client.rb, line 48
def check_payload(payload)
  errors = Nokogiri::XML(payload).errors
  raise CollectionSpace::PayloadError, errors if errors.any?
end
request(method, path, options = {}) click to toggle source
# File lib/collectionspace/client/client.rb, line 53
def request(method, path, options = {})
  sleep config.throttle
  Response.new(Request.new(config, method, path, options).execute)
end