Class: ArchivesSpace::Request

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

Constant Summary collapse

DEFAULT_HEADERS =
{"Content-Type" => "application/json"}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Request.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/archivesspace/client/request.rb', line 11

def initialize(context, config, method = "GET", path = "", options = {})
  @config = config

  @method = method.downcase.to_sym
  @path = path.gsub(%r{^/+}, "")

  @options = options

  @options[:headers] = DEFAULT_HEADERS.merge(@options.fetch(:headers, {}))
  @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
  self.class.base_uri context ? "#{config.base_uri}/#{context}" : config.base_uri
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#executeObject



30
31
32
# File 'lib/archivesspace/client/request.rb', line 30

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