class CollectionSpace::Request

CollectionSpace request

Attributes

config[R]
headers[R]
method[R]
options[R]
path[R]

Public Class Methods

new(config, method = "GET", path = "", options = {}) click to toggle source
# File lib/collectionspace/client/request.rb, line 25
def initialize(config, method = "GET", path = "", options = {})
  @config = config
  @method = method.downcase.to_sym
  @path = path.gsub(%r{^/}, "")

  @auth = {
    username: config.username,
    password: config.password
  }

  headers = default_headers(@method).merge(options.fetch(:headers, {}))
  @options = options
  @options[:basic_auth] = @auth
  @options[:headers] = headers
  @options[:verify] = config.verify_ssl
  @options[:query] = options.fetch(:query, {})

  self.class.base_uri config.base_uri
  self.class.debug_output $stdout if config.verbose
  self.class.default_params(
    wf_deleted: config.include_deleted,
    pgSz: config.page_size
  )
end

Public Instance Methods

default_headers(method = :get) click to toggle source
# File lib/collectionspace/client/request.rb, line 9
def default_headers(method = :get)
  headers = {
    delete: {},
    get: {},
    post: {
      "Content-Type" => "application/xml",
      "Content-Length" => "nnnn"
    },
    put: {
      "Content-Type" => "application/xml",
      "Content-Length" => "nnnn"
    }
  }
  headers[method]
end
execute() click to toggle source
# File lib/collectionspace/client/request.rb, line 50
def execute
  self.class.send method, "/#{path}", options
end