Class: Dspace::Client

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

Constant Summary collapse

DSPACE_API =
'https://demo.dspace.org'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/dspace/client.rb', line 7

def initialize(options = {})
  @access_token = options.with_indifferent_access[:access_token]
  @dspace_api = options.with_indifferent_access[:dspace_api]
  @logger = options.with_indifferent_access[:logger]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



33
34
35
# File 'lib/dspace/client.rb', line 33

def method_missing(name, *args, &block)
  resource(name) || super
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/dspace/client.rb', line 5

def access_token
  @access_token
end

Class Method Details

.resourcesObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/dspace/client.rb', line 22

def self.resources
  {
      bitstreams: ::Dspace::Resources::BitstreamResource,
      items: ::Dspace::Resources::ItemResource,
      collections: ::Dspace::Resources::CollectionResource,
      communities: ::Dspace::Resources::CommunityResource,
      status: ::Dspace::Resources::StatusResource,
      authentication: ::Dspace::Resources::AuthenticationResource
  }
end

Instance Method Details

#connectionObject



13
14
15
16
17
18
19
20
# File 'lib/dspace/client.rb', line 13

def connection
  Faraday.new(connection_options) do |req|
    req.request :multipart
    req.request :url_encoded
    req.use(Faraday::Response::Logger, @logger) unless @logger.nil?
    req.adapter :net_http_persistent
  end
end

#is_running?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/dspace/client.rb', line 41

def is_running?
  resource(:status).test
end

#login(email, password) ⇒ Object



45
46
47
# File 'lib/dspace/client.rb', line 45

def (email, password)
  @access_token = resource(:authentication).(email, password)
end

#logoutObject



49
50
51
52
# File 'lib/dspace/client.rb', line 49

def logout
  resource(:authentication).logout
  @access_token = nil
end

#resourcesObject



37
38
39
# File 'lib/dspace/client.rb', line 37

def resources
  @resources ||= {}
end