Class: IqTriplestorage::BaseAdaptor

Inherits:
Object
  • Object
show all
Defined in:
lib/iq_triplestorage.rb

Direct Known Subclasses

SesameAdaptor, VirtuosoAdaptor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, options = {}) ⇒ BaseAdaptor

Returns a new instance of BaseAdaptor.



7
8
9
10
11
# File 'lib/iq_triplestorage.rb', line 7

def initialize(host, options={})
  @host = URI.parse(host).normalize
  @username = options[:username]
  @password = options[:password]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/iq_triplestorage.rb', line 5

def host
  @host
end

Instance Method Details

#http_request(method, path, body = nil, headers = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/iq_triplestorage.rb', line 13

def http_request(method, path, body=nil, headers={})
  uri = URI.join("#{@host}/", path)

  req = Net::HTTP.const_get(method.to_s.downcase.capitalize).new(uri.to_s)
  req.basic_auth(@username, @password) if (@username && @password)
  headers.each { |key, value| req[key] = value }
  req.body = body if body

  return Net::HTTP.new(uri.host, uri.port).request(req)
end