Class: Cul::Fedora::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/cul-fedora/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
18
19
# File 'lib/cul-fedora/server.rb', line 13

def initialize(*args)
  options = args.extract_options!
  @riurl = options[:riurl] || options["riurl"] || raise(ArgumentError, "Must provide riurl argument")
  @riquery = options[:riquery] || options["riquery"] || raise(ArgumentError, "Must provide riquery argument")
  @hc = options[:http_client] || options["http_client"]
  @logger = options[:logger] || options["logger"]
end

Instance Attribute Details

#riqueryObject (readonly)

Returns the value of attribute riquery.



11
12
13
# File 'lib/cul-fedora/server.rb', line 11

def riquery
  @riquery
end

#riurlObject (readonly)

Returns the value of attribute riurl.



11
12
13
# File 'lib/cul-fedora/server.rb', line 11

def riurl
  @riurl
end

Instance Method Details

#item(uri) ⇒ Object



25
26
27
# File 'lib/cul-fedora/server.rb', line 25

def item(uri)
  Item.new(:server => self, :uri => uri, :logger => logger)
end

#loggerObject



21
22
23
# File 'lib/cul-fedora/server.rb', line 21

def logger
  @logger ||= Logger.new(STDOUT)
end

#request(options = {}) ⇒ Object



29
30
31
# File 'lib/cul-fedora/server.rb', line 29

def request(options= {})
  http_client.get_content(*request_path(options))
end

#request_path(options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cul-fedora/server.rb', line 33

def request_path(options = {})
  sdef = options.delete(:sdef).to_s
  pid = options.delete(:pid).to_s
  request = (options.delete(:request) || "").to_s
  method = (options.delete(:method) || "/get").to_s

  sdef = "/" + sdef unless sdef.empty?
  pid = "/" + pid unless pid.empty?
  request = "/" + request.to_s


  uri = @riurl + method + pid + sdef + request
  query = options
  
  return [uri, query]
end