Class: Cul::Fedora::Connector

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Connector

Returns a new instance of Connector.



16
17
18
# File 'lib/cul/fedora/connector.rb', line 16

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/cul/fedora/connector.rb', line 4

def config
  @config
end

Class Method Details

.parse(environments) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/cul/fedora/connector.rb', line 6

def self.parse(environments)
  connectors = {}
  
  environments.each_pair do |environment, config|
    connectors[environment] = Connector.new(config)
  end 
  
  connectors
end

Instance Method Details

#apim_call(method, *args) ⇒ Object



57
58
59
60
# File 'lib/cul/fedora/connector.rb', line 57

def apim_call(method, *args)
  options = args.extract_options!
  apim_interface.method(method).call(options)
end

#apim_interfaceObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cul/fedora/connector.rb', line 42

def apim_interface()
  wsdl = url_builder(:admin, "fedora/wsdl?api=API-M")
  driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
  
  if config_for(:admin, :ssl_verify)
    raise "SSL verification not currently supported. Please specify ssl_verify: false"
  else
    driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE
  end
  
  driver.options["protocol.http.basic_auth"] << [url_builder(:admin,"fedora/services/management"), config_for(:admin,:user), config_for(:admin,:password)]
  
  driver
end

#config_for(interface, value) ⇒ Object



34
35
36
# File 'lib/cul/fedora/connector.rb', line 34

def config_for(interface, value)
  (@config[interface.to_s] && @config[interface.to_s][value.to_s]) || @config[value.to_s]
end

#protocol_for(interface) ⇒ Object



30
31
32
# File 'lib/cul/fedora/connector.rb', line 30

def protocol_for(interface)
  config_for(interface.to_s,"ssl") == true ? "https" : "http"
end

#rest_interface {|http| ... } ⇒ Object

Yields:

  • (http)


20
21
22
23
24
# File 'lib/cul/fedora/connector.rb', line 20

def rest_interface()
  http = Net::HTTP.start(config_for(:rest, :host),config_for(:rest, :port))
  yield http
  http.finish()
end

#rest_locationObject



26
27
28
# File 'lib/cul/fedora/connector.rb', line 26

def rest_location()
  url_builder(:rest, "")
end

#url_builder(interface, url) ⇒ Object



38
39
40
# File 'lib/cul/fedora/connector.rb', line 38

def url_builder(interface, url)
  "#{protocol_for(interface)}://#{config_for(interface,:host)}:#{config_for(interface,:port)}/#{url}"
end