Class: DspaceClient
- Inherits:
-
Object
- Object
- DspaceClient
- Defined in:
- lib/dspace_client.rb
Instance Attribute Summary collapse
-
#rest_client ⇒ Object
readonly
Returns the value of attribute rest_client.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url, authenticated_token = nil) ⇒ DspaceClient
constructor
A new instance of DspaceClient.
- #login(username, password) ⇒ Object
- #logout ⇒ Object
- #repository ⇒ Object
- #status ⇒ Object
- #test ⇒ Object
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_client ⇒ Object (readonly)
Returns the value of attribute rest_client.
4 5 6 |
# File 'lib/dspace_client.rb', line 4 def rest_client @rest_client end |
#url ⇒ Object (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 login(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 |
#logout ⇒ Object
36 37 38 |
# File 'lib/dspace_client.rb', line 36 def logout response = JSON.parse @rest_client['/logout'].post [] end |
#repository ⇒ Object
16 17 18 |
# File 'lib/dspace_client.rb', line 16 def repository @dspace_repository ||= build_repository @rest_client end |
#status ⇒ Object
40 41 42 |
# File 'lib/dspace_client.rb', line 40 def status response = JSON.parse @rest_client['/status'].get end |
#test ⇒ Object
44 45 46 |
# File 'lib/dspace_client.rb', line 44 def test response = JSON.parse(@rest_client['/test'].get) end |