Class: RubyFedora::Connection
- Inherits:
-
Object
- Object
- RubyFedora::Connection
- 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
-
#format ⇒ Object
Returns the value of attribute format.
-
#site ⇒ Object
Returns the value of attribute site.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete(path, headers = {}) ⇒ Object
Execute a DELETE request (see HTTP protocol documentation if unfamiliar).
-
#get(path, headers = {}) ⇒ Object
Execute a GET request.
-
#initialize(site, format = ) ⇒ Connection
constructor
The
siteparameter is required and will set thesiteattribute to the URI for the remote resource service. -
#post(path, body = '', headers = {}) ⇒ Object
Execute a POST request.
-
#put(path, body = '', headers = {}) ⇒ Object
Execute a PUT request (see HTTP protocol documentation if unfamiliar).
- #raw_get(path, headers = {}) ⇒ Object
Constructor Details
#initialize(site, format = ) ⇒ Connection
The site parameter is required and will set the site attribute to the URI for the remote resource service.
123 124 125 126 127 |
# File 'lib/fedora/connection.rb', line 123 def initialize(site, format = ActiveResource::Formats[:xml]) raise ArgumentError, 'Missing site URI' unless site self.site = site self.format = format end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
113 114 115 |
# File 'lib/fedora/connection.rb', line 113 def format @format end |
#site ⇒ Object
Returns the value of attribute site.
112 113 114 |
# File 'lib/fedora/connection.rb', line 112 def site @site end |
Class Method Details
.requests ⇒ Object
116 117 118 |
# File 'lib/fedora/connection.rb', line 116 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.
142 143 144 |
# File 'lib/fedora/connection.rb', line 142 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.
136 137 138 |
# File 'lib/fedora/connection.rb', line 136 def get(path, headers = {}) format.decode(request(:get, path, build_request_headers(headers)).body) end |
#post(path, body = '', headers = {}) ⇒ Object
Execute a POST request. Used to create new resources.
158 159 160 161 162 163 164 |
# File 'lib/fedora/connection.rb', line 158 def post(path, body = '', headers = {}) if body.is_a?(File) multipart_request(Net::HTTP::Post.new(path, build_request_headers(headers)), body) else request(:post, path, body.to_s, build_request_headers(headers)) end end |
#put(path, body = '', headers = {}) ⇒ Object
Execute a PUT request (see HTTP protocol documentation if unfamiliar). Used to update resources.
148 149 150 151 152 153 154 |
# File 'lib/fedora/connection.rb', line 148 def put(path, body = '', headers = {}) if body.is_a?(File) multipart_request(Net::HTTP::Put.new(path, build_request_headers(headers)), body) else request(:put, path, body.to_s, build_request_headers(headers)) end end |
#raw_get(path, headers = {}) ⇒ Object
166 167 168 |
# File 'lib/fedora/connection.rb', line 166 def raw_get(path, headers = {}) request(:get, path, build_request_headers(headers)) end |