Class: ArchivesSpace::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Request.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/archivesspace/client/request.rb', line 24

def initialize(config, method = "GET", path = "", options = {})
  @config = config
  @method = method.downcase.to_sym
  @path = path.gsub(%r{^/+}, "")
  @options = options
  @options[:headers] =
    options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers(@method)
  @options[:headers]["User-Agent"] = "#{Client::NAME}/#{Client::VERSION}"
  @options[:verify] = config.verify_ssl
  @options[:timeout] = config.timeout
  @options[:query] = {} unless options.key? :query

  self.class.debug_output($stdout) if @config.debug

  base_uri = config.base_repo&.length&.positive? ? File.join(config.base_uri, config.base_repo) : config.base_uri
  self.class.base_uri base_uri
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/archivesspace/client/request.rb', line 6

def config
  @config
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/archivesspace/client/request.rb', line 6

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/archivesspace/client/request.rb', line 6

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/archivesspace/client/request.rb', line 6

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/archivesspace/client/request.rb', line 6

def path
  @path
end

Instance Method Details

#default_headers(method = :get) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/archivesspace/client/request.rb', line 8

def default_headers(method = :get)
  headers = {
    delete: {},
    get: {},
    post: {
      "Content-Type" => "application/json",
      "Content-Length" => "nnnn"
    },
    put: {
      "Content-Type" => "application/json",
      "Content-Length" => "nnnn"
    }
  }
  headers[method]
end

#executeObject



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

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