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.



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

def initialize(config, method = "GET", path = "", options = {})
  @config  = config
  @method  = method.downcase.to_sym
  @path    = path

  @options = options
  @options[:headers]    = options[:headers] ? default_headers(@method).merge(options[:headers]) : default_headers
  @options[:verify]     = config.verify_ssl
  @options[:query]      = {} unless options.has_key? :query

  base_uri = (config.base_repo.nil? or config.base_repo.empty?) ? config.base_uri : "#{config.base_uri}/#{config.base_repo}"
  self.class.base_uri base_uri
  # self.class.default_params abc: 123
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#default_headers(method = :get) ⇒ Object



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

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



38
39
40
# File 'lib/archivesspace/client/request.rb', line 38

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