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



79
80
81
# File 'lib/rubydora/fedora_url_helpers.rb', line 79

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



87
88
89
# File 'lib/rubydora/fedora_url_helpers.rb', line 87

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

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

Generate a base datastream REST API endpoint URI

Parameters:

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

    to convert to URL parameters

Returns:

  • (String)

    URI

Raises:

  • (ArgumentError)


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

def datastream_url pid, dsid, options = nil
  raise ArgumentError, "You must provide a pid and a dsid" unless pid and dsid
  url_for(object_url(pid) + "/datastreams/#{CGI::escape(dsid)}", options)
end

#datastreams_url(pid, options = nil) ⇒ String

Generate a base datastream REST API endpoint URI

Parameters:

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

    to convert to URL parameters

Returns:

  • (String)

    URI

Raises:

  • (ArgumentError)


70
71
72
73
# File 'lib/rubydora/fedora_url_helpers.rb', line 70

def datastreams_url pid, options = nil
  raise ArgumentError, "You must provide a pid" unless pid
  url_for(object_url(pid) + "/datastreams", options)
end

#describe_repository_url(options = nil) ⇒ Object



15
16
17
# File 'lib/rubydora/fedora_url_helpers.rb', line 15

def describe_repository_url options = nil
  url_for("describe", 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

Raises:

  • (ArgumentError)


49
50
51
52
# File 'lib/rubydora/fedora_url_helpers.rb', line 49

def dissemination_url pid, sdef = nil, method = nil, options = nil
  raise ArgumentError, "You must provide a pid" 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



101
102
103
# File 'lib/rubydora/fedora_url_helpers.rb', line 101

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



39
40
41
# File 'lib/rubydora/fedora_url_helpers.rb', line 39

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



129
130
131
# File 'lib/rubydora/fedora_url_helpers.rb', line 129

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

#new_object_url(options = nil) ⇒ Object



27
28
29
# File 'lib/rubydora/fedora_url_helpers.rb', line 27

def new_object_url options = nil
  object_url "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



33
34
35
# File 'lib/rubydora/fedora_url_helpers.rb', line 33

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



122
123
124
# File 'lib/rubydora/fedora_url_helpers.rb', line 122

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



23
24
25
# File 'lib/rubydora/fedora_url_helpers.rb', line 23

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



108
109
110
# File 'lib/rubydora/fedora_url_helpers.rb', line 108

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



115
116
117
# File 'lib/rubydora/fedora_url_helpers.rb', line 115

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



94
95
96
# File 'lib/rubydora/fedora_url_helpers.rb', line 94

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