Module: Rubydora::FedoraUrlHelpers

Included in:
RestApiClient
Defined in:
lib/rubydora/fedora_url_helpers.rb

Constant Summary collapse

API_DOCUMENTATION =

Fedora API documentation available at https://wiki.duraspace.org/display/FCR30/REST+API

'https://wiki.duraspace.org/display/FCR30/REST+API'

Instance Method Summary collapse

Instance Method Details

#datastream_content_url(pid, dsid = nil, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • dsid (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



60
61
62
# File 'lib/rubydora/fedora_url_helpers.rb', line 60

def datastream_content_url pid, dsid = nil, options = nil
  url_for(datastream_url(pid, dsid) +  "/content", options)
end

#datastream_history_url(pid, dsid = nil, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • dsid (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



68
69
70
# File 'lib/rubydora/fedora_url_helpers.rb', line 68

def datastream_history_url pid, dsid = nil, options = nil
  url_for(datastream_url(pid, dsid) +  "/history", options)
end

#datastream_url(pid, dsid = nil, options = nil) ⇒ String

Generate a base datastream REST API endpoint URI

Parameters:

  • pid (String)
  • dsid (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



51
52
53
54
# File 'lib/rubydora/fedora_url_helpers.rb', line 51

def datastream_url pid, dsid = nil, options = nil
  raise "" unless pid
  url_for(object_url(pid) + "/datastreams" + (("/#{CGI::escape(dsid)}" if dsid) || ''), options)
end

#dissemination_url(pid, sdef = nil, method = nil, options = nil) ⇒ String

Generate a base object dissemination REST API endpoint URI

Parameters:

  • pid (String)
  • sdef (String) (defaults to: nil)
  • method (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



41
42
43
44
# File 'lib/rubydora/fedora_url_helpers.rb', line 41

def dissemination_url pid, sdef = nil, method = nil, options = nil
  raise "" unless pid
  url_for(object_url(pid) + "/methods" +  (("/#{CGI::escape(sdef)}" if sdef) || '') +  (("/#{CGI::escape(method)}" if method) || ''), options)
end

#export_object_url(pid, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



82
83
84
# File 'lib/rubydora/fedora_url_helpers.rb', line 82

def export_object_url pid, options = nil
  url_for(object_url(pid) + "/export", options)
end

#find_objects_url(options = nil) ⇒ String

Returns URI.

Parameters:

  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



31
32
33
# File 'lib/rubydora/fedora_url_helpers.rb', line 31

def find_objects_url options = nil
  url_for("objects", options)
end

#new_object_relationship_url(pid, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



110
111
112
# File 'lib/rubydora/fedora_url_helpers.rb', line 110

def new_object_relationship_url pid, options = nil
  url_for(object_relationship_url(pid) + "/new", options)
end

#next_pid_url(options = nil) ⇒ String

Returns URI.

Parameters:

  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



25
26
27
# File 'lib/rubydora/fedora_url_helpers.rb', line 25

def next_pid_url options = nil
  url_for("objects/nextPID", options)
end

#object_relationship_url(pid, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



103
104
105
# File 'lib/rubydora/fedora_url_helpers.rb', line 103

def object_relationship_url pid, options = nil
  url_for(object_url(pid) + "/relationships", options)
end

#object_url(pid, options = nil) ⇒ String

Generate a base object REST API endpoint URI

Parameters:

  • pid (String)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



19
20
21
# File 'lib/rubydora/fedora_url_helpers.rb', line 19

def object_url pid, options = nil
  url_for("objects" + (("/#{CGI::escape(pid.to_s.gsub('info:fedora/', ''))}" if pid) || ''), options)
end

#object_versions_url(pid, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



89
90
91
# File 'lib/rubydora/fedora_url_helpers.rb', line 89

def object_versions_url pid, options = nil
  url_for(object_url(pid) + "/versions", options)
end

#object_xml_url(pid, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



96
97
98
# File 'lib/rubydora/fedora_url_helpers.rb', line 96

def object_xml_url pid, options = nil
  url_for(object_url(pid) + "/objectXML", options)
end

#url_for(base, options = nil) ⇒ String

Generate a REST API compatible URI

Parameters:

  • base (String)

    base URI

  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



10
11
12
13
# File 'lib/rubydora/fedora_url_helpers.rb', line 10

def url_for base, options = nil
  return base unless options.is_a? Hash
  "#{base}" + (("?#{options.map { |key, value|  "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&")  }" if options and not options.empty?) || '')
end

#validate_object_url(pid, options = nil) ⇒ String

Returns URI.

Parameters:

  • pid (String)
  • options (Hash) (defaults to: nil)

    to convert to URL parameters

Returns:

  • (String)

    URI



75
76
77
# File 'lib/rubydora/fedora_url_helpers.rb', line 75

def validate_object_url pid, options = nil
  url_for(object_url(pid) + "/validate", options)
end