Class: Fedora::Connection

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

Overview

Class to handle connections to remote web services. This class is used by ActiveResource::Base to interface with REST services.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, format = , surrogate = nil) ⇒ Connection

The site parameter is required and will set the site attribute to the URI for the remote resource service.

Raises:

  • (ArgumentError)


74
75
76
77
78
79
# File 'lib/fedora/connection.rb', line 74

def initialize(site, format = ActiveResource::Formats[:xml], surrogate=nil)
  raise ArgumentError, 'Missing site URI' unless site
  self.site = site
  self.format = format
  @surrogate=surrogate
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



64
65
66
# File 'lib/fedora/connection.rb', line 64

def format
  @format
end

#siteObject

Returns the value of attribute site.



63
64
65
# File 'lib/fedora/connection.rb', line 63

def site
  @site
end

#surrogateObject (readonly)

Returns the value of attribute surrogate.



63
64
65
# File 'lib/fedora/connection.rb', line 63

def surrogate
  @surrogate
end

Class Method Details

.requestsObject



67
68
69
# File 'lib/fedora/connection.rb', line 67

def requests
  @@requests ||= []
end

Instance Method Details

#delete(path, headers = {}) ⇒ Object

Execute a DELETE request (see HTTP protocol documentation if unfamiliar). Used to delete resources.



94
95
96
# File 'lib/fedora/connection.rb', line 94

def delete(path, headers = {})
  request(:delete, path, build_request_headers(headers))
end

#get(path, headers = {}) ⇒ Object

Execute a GET request. Used to get (find) resources.



88
89
90
# File 'lib/fedora/connection.rb', line 88

def get(path, headers = {})
  format.decode(request(:get, path, build_request_headers(headers)).body)
end

#post(path, body = '', headers = {}) ⇒ Object



103
104
105
# File 'lib/fedora/connection.rb', line 103

def post(path, body='', headers={})
  do_method(:post, path, body, headers)
end

#put(path, body = '', headers = {}) ⇒ Object



106
107
108
# File 'lib/fedora/connection.rb', line 106

def put( path, body='', headers={})
  do_method(:put, path, body, headers)
end

#raw_get(path, headers = {}) ⇒ Object



100
101
102
# File 'lib/fedora/connection.rb', line 100

def raw_get(path, headers = {})
  request(:get, path, build_request_headers(headers))
end