class Matterhorn::Endpoint::Series
Matterhorn::Endpoint::Series
===¶ ↑
Public Instance Methods
count()
click to toggle source
# File lib/matterhorn/endpoint/series.rb, line 139 def count count = 0 begin split_response http_endpoint_client.get( "series/count" ) count = response_body.to_i rescue => ex exception_handler('count', ex, {}) end count end
create(dublin_core, acl = nil)
click to toggle source
Create a new Series
on Mattherhorn. Return the dublin core of the created Series
. In the property dcterms:identifier is written the Matterhorn
Series
Id.
# File lib/matterhorn/endpoint/series.rb, line 17 def create(dublin_core, acl = nil) dc = nil begin split_response http_endpoint_client.post( "series", { 'series' => dublin_core.to_xml, 'acl' => acl ? acl.to_xml : '' } ) dc = Matterhorn::DublinCore.new(response_body) rescue => ex exception_handler('create', ex, { 400 => "The required form params were missing to create the series!\n" + " dubline_core:\n#{dublin_core.inspect}\n acl:\n#{acl.inspect}", 401 => "Unauthorized. It is required to authenticate first, before create a series!" } ) end dc end
create_property(series_id, name, value)
click to toggle source
Create a new property for a given Series
on Mattherhorn. Return no content.
# File lib/matterhorn/endpoint/series.rb, line 40 def create_property(series_id, name, value) return false if value.nil? || value.to_s.empty? set = false begin split_response http_endpoint_client.post( "series/#{series_id}/property", { 'name' => name, 'value' => value.to_s } ) set = true rescue => ex exception_handler('create_property', ex, { 400 => "The required path or form params were missing in the request.", 401 => "If the current user is not authorized to perform this action .", 404 => "No series with this identifier was found." } ) end set end
delete(series_id)
click to toggle source
————————————————————————————- delete —
# File lib/matterhorn/endpoint/series.rb, line 196 def delete(series_id) deleted = false begin split_response http_endpoint_client.delete( "series/#{series_id}" ) deleted = true rescue => ex exception_handler('delete', ex, { 401 => "Unauthorized. It is required to authenticate first, " + "before delete series #{series_id}.", 404 => "The series #{series_id} could not be found." } ) end deleted end
delete_property(series_id, name)
click to toggle source
# File lib/matterhorn/endpoint/series.rb, line 215 def delete_property(series_id, name) deleted = false begin split_response http_endpoint_client.delete( "series/#{series_id}/property/#{name}" ) deleted = true rescue => ex exception_handler('delete_property', ex, { 401 => "The current user is not authorized to perform this action.", 404 => "The series #{series_id} or property #{name} has not been found." } ) end deleted end
find(options)
click to toggle source
# File lib/matterhorn/endpoint/series.rb, line 118 def find(options) dc_models = [] begin split_response http_endpoint_client.get( "series/series.xml#{build_query_str(options)}" ) Nokogiri::XML(response_body). xpath("/dublincorelist/xmlns:dublincore", Matterhorn::DublinCore::NS).each do |dc_elem| dc_models << Matterhorn::DublinCore.new(dc_elem.to_xml) end rescue => ex exception_handler('find', ex, { 401 => "Unauthorized. It is required to authenticate first, " + "before filter series." } ) end dc_models end
read(series_id)
click to toggle source
————————————————————————————— read —
# File lib/matterhorn/endpoint/series.rb, line 63 def read(series_id) dc_model = nil begin split_response http_endpoint_client.get( "series/#{series_id}.xml" ) dc_model = Matterhorn::DublinCore.new(response_body) rescue => ex exception_handler('read', ex, { 401 => "Unauthorized. It is required to authenticate first, " + "before get the content of series #{series_id}.", 403 => "It is forbidden to get the content of series #{series_id}.", 404 => "The content of series #{series_id} could not be get." } ) end dc_model end
read_acl(series_id)
click to toggle source
# File lib/matterhorn/endpoint/series.rb, line 83 def read_acl(series_id) acl_model = nil begin split_response http_endpoint_client.get( "series/#{series_id}/acl.xml" ) acl_model = Matterhorn::Acl.new(response_body) rescue => ex exception_handler('read_acl', ex, { 404 => "The acl of series #{series_id} could not be found." } ) end acl_model end
read_property(series_id, name)
click to toggle source
# File lib/matterhorn/endpoint/series.rb, line 100 def read_property(series_id, name) prop_value = nil begin split_response http_endpoint_client.get( "series/#{series_id}/property/#{name}.json" ) prop_value = response_body rescue => ex exception_handler('read_property', ex, { 401 => "The current user is not authorized to perform this action.", 404 => "The series #{series_id} or property #{name} has not been found." } ) end prop_value end
update(dublin_core, acl = nil)
click to toggle source
Updates a given Series
on Mattherhorn. In the property dcterms:identifier must be written the Matterhorn
Series
Id of the Series
which should be updated. Return the dublin core of the updated Series
.
# File lib/matterhorn/endpoint/series.rb, line 160 def update(dublin_core, acl = nil) series_id = dublin_core.dcterms_identifier dc_to_update = read(dublin_core.dcterms_identifier) if dc_to_update.nil? raise(Matterhorn::Error.new("Series[#{series_id}] was not found on Matterhorn")) end dc = create(dublin_core, acl) if response_code == 204 dc = read(series_id) end dc end
update_acl(series_id, acl)
click to toggle source
# File lib/matterhorn/endpoint/series.rb, line 174 def update_acl(series_id, acl) acl_updated = false begin split_response http_endpoint_client.post( "series/#{series_id}/accesscontrol", { 'acl' => acl.to_xml } ) acl_updated = true rescue => ex exception_handler('update_acl', ex, { 400 => "Bad request. The required param acl was missing. acl: #{acl.inspect}", 401 => "Unauthorized. It is required to authenticate first, " + "before update the acl of series #{series_id}.", 404 => "The series #{series_id} could not be found." } ) end acl_updated end