Class: CollectionSpace::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/collectionspace/client/request.rb

Overview

CollectionSpace request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, method = 'GET', path = '', options = {}) ⇒ Request

Returns a new instance of Request.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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.default_params(
    wf_deleted: config.include_deleted,
    pgSz: config.page_size
  )
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#default_headers(method = :get) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

#executeObject



49
50
51
# File 'lib/collectionspace/client/request.rb', line 49

def execute
  self.class.send method, "/#{path}", options
end