Class: DspaceClient

Inherits:
Object
  • Object
show all
Defined in:
lib/dspace_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, authenticated_token = nil) ⇒ DspaceClient

Returns a new instance of DspaceClient.



6
7
8
9
10
11
12
13
14
# File 'lib/dspace_client.rb', line 6

def initialize(url, authenticated_token = nil)
  @url = url

  if (authenticated_token.nil?)
    @rest_client = build_rest_client url
  else
    @rest_client = build_rest_client url, rest_dspace_token: authenticated_token
  end
end

Instance Attribute Details

#rest_clientObject (readonly)

Returns the value of attribute rest_client.



4
5
6
# File 'lib/dspace_client.rb', line 4

def rest_client
  @rest_client
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/dspace_client.rb', line 4

def url
  @url
end

Instance Method Details

#login(username, password) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dspace_client.rb', line 20

def (username, password)
  user = JSON.generate({
                           email: username,
                           password: password
                       })

  # send login request to server and receive the token

  authenticated_token = @rest_client['/login'].post user

  # overwrite the rest_client and dspace_repository

  @rest_client = build_rest_client @url, rest_dspace_token: authenticated_token
  @dspace_repository = build_repository @rest_client

  authenticated_token
end

#logoutObject



36
37
38
# File 'lib/dspace_client.rb', line 36

def logout
  response = JSON.parse @rest_client['/logout'].post []
end

#repositoryObject



16
17
18
# File 'lib/dspace_client.rb', line 16

def repository
  @dspace_repository ||= build_repository @rest_client
end

#statusObject



40
41
42
# File 'lib/dspace_client.rb', line 40

def status
  response = JSON.parse @rest_client['/status'].get
end

#testObject



44
45
46
# File 'lib/dspace_client.rb', line 44

def test
  response = JSON.parse(@rest_client['/test'].get)
end