Class: AlmaApi::Client

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

Defined Under Namespace

Classes: Users

Constant Summary collapse

API_ROOT_PATH =
"/almaws"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(options = {})
  options.symbolize_keys.try do |_sanitized_options|
    @apikey = _sanitized_options[:apikey] || _sanitized_options[:api_key] || ENV["ALMA_APIKEY"] || ENV["ALMA_API_KEY"]
    @host = (_sanitized_options[:host] || ENV["ALMA_HOST"]).try(:strip)
  end
end

Instance Attribute Details

#apikeyObject Also known as: api_key

Returns the value of attribute apikey.



9
10
11
# File 'lib/alma_api/client.rb', line 9

def apikey
  @apikey
end

#hostObject

Returns the value of attribute host.



10
11
12
# File 'lib/alma_api/client.rb', line 10

def host
  @host
end

Instance Method Details

#http(method, path, options = {}) ⇒ Object

inter-client api



27
28
29
30
31
32
33
34
# File 'lib/alma_api/client.rb', line 27

def http(method, path, options = {})
  connection = Faraday.new.tap do |_connection|
    _connection.headers["Accept"] = "application/json"
    _connection.params["apikey"] = apikey
  end

  connection.send(method, "#{host}#{API_ROOT_PATH}#{path}", options)
end

#users(user_id = nil) ⇒ Object



22
23
24
# File 'lib/alma_api/client.rb', line 22

def users(user_id = nil)
  Users.new(self, user_id)
end