Class: EvergreenHoldings::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(evergreen_domain) ⇒ Connection

Create a new object with the evergreen_domain specified, e.g. libcat.linnbenton.edu

Usage: ‘conn = EvergreenHoldings::Connection.new ’gapines.org’‘



18
19
20
21
22
23
24
25
26
# File 'lib/evergreen_holdings.rb', line 18

def initialize(evergreen_domain)
  @evergreen_domain = evergreen_domain
  @gateway = URI evergreen_domain + OSRF_PATH
  @acpl_cache = {}
  fetch_idl_order
  raise CouldNotConnectToEvergreenError unless fetch_statuses

  fetch_ou_tree
end

Instance Attribute Details

#org_unitsObject (readonly)

Returns the value of attribute org_units.



13
14
15
# File 'lib/evergreen_holdings.rb', line 13

def org_units
  @org_units
end

Instance Method Details

#get_holdings(tcn, options = {}) ⇒ Object

Fetch holdings data from the Evergreen server Returns a Status object

Usage: ‘stat = conn.get_holdings 23405` If you just want holdings at a specific org_unit: `my_connection.get_holdings 23405, org_unit: 5`



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

def get_holdings(tcn, options = {})
  if options.key?(:org_unit)
    if options[:descendants]
      params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.retrieve&param=auth_token_not_needed_for_this_call&param=#{tcn}"
      @org_units[options[:org_unit]][:descendants]&.each do |ou|
        params << + "&param=#{ou}"
      end
    else
      params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.retrieve&param=auth_token_not_needed_for_this_call&param=#{tcn}&param=#{options[:org_unit]}"
    end
  else
    params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.global.retrieve&param=auth_token_not_needed_for_this_call&param=#{tcn}"
  end
  @gateway.query = params

  res = send_query
  return Status.new res.body, @idl_order, self if res
end

#location_name(id) ⇒ Object

Given an ID, returns a human-readable name



53
54
55
# File 'lib/evergreen_holdings.rb', line 53

def location_name(id)
  @acpl_cache.fetch(id) { |id| fetch_new_acpl(id) || id }
end

#ou_name(id) ⇒ Object



61
62
63
# File 'lib/evergreen_holdings.rb', line 61

def ou_name(id)
      @org_units[id][:name]
end

#status_name(id) ⇒ Object



57
58
59
# File 'lib/evergreen_holdings.rb', line 57

def status_name(id)
  @possible_item_statuses[id]
end