Class: Medusa::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/medusa/client.rb

Overview

High-level client for the Medusa Collection Registry.

noinspection RubyClassVariableUsageInspection

Constant Summary collapse

@@configuration =
{
    medusa_base_url: ENV['MEDUSA_BASE_URL'],
    medusa_user:     ENV['MEDUSA_USER'],
    medusa_secret:   ENV['MEDUSA_SECRET']
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configurationObject



20
21
22
# File 'lib/medusa/client.rb', line 20

def self.configuration
  @@configuration
end

.configuration=(config) ⇒ Object



24
25
26
27
# File 'lib/medusa/client.rb', line 24

def self.configuration=(config)
  @@configuration = config
  instance.instance_variable_set('@http_client', nil)
end

Instance Method Details

#class_of_uuid(uuid) ⇒ Class

Parameters:

  • uuid (String)

Returns:

  • (Class)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/medusa/client.rb', line 33

def class_of_uuid(uuid)
  url      = url_for_uuid(uuid) + '.json'
  response = get(url, follow_redirect: false)
  location = response.header['location'].first
  if location&.include?('/repositories/')
    ::Medusa::Repository
  elsif location&.include?('/collections/')
    ::Medusa::Collection
  elsif location&.include?('file_groups/')
    ::Medusa::FileGroup
  elsif location&.include?('/cfs_directories/')
    ::Medusa::Directory
  elsif location&.include?('/cfs_files/')
    ::Medusa::File
  end
end

#get(url, *args) ⇒ Object



50
51
52
53
# File 'lib/medusa/client.rb', line 50

def get(url, *args)
  args = merge_args(args)
  http_client.get(url, args)
end

#get_uuid(url, *args) ⇒ Object



55
56
57
# File 'lib/medusa/client.rb', line 55

def get_uuid(url, *args)
  get(url_for_uuid(url) + '.json', args)
end

#head(url, *args) ⇒ Object



59
60
61
62
# File 'lib/medusa/client.rb', line 59

def head(url, *args)
  args = merge_args(args)
  http_client.head(url, args)
end

#url_for_uuid(uuid) ⇒ String?

Returns URI of the corresponding Medusa resource.

Parameters:

  • uuid (String)

Returns:

  • (String, nil)

    URI of the corresponding Medusa resource.



68
69
70
# File 'lib/medusa/client.rb', line 68

def url_for_uuid(uuid)
  [self.class.configuration[:medusa_base_url].chomp('/'), 'uuids', uuid].join('/')
end