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’‘


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

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.


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

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`


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

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


55
56
57
# File 'lib/evergreen_holdings.rb', line 55

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

#ou_name(id) ⇒ Object


63
64
65
# File 'lib/evergreen_holdings.rb', line 63

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

#status_name(id) ⇒ Object


59
60
61
# File 'lib/evergreen_holdings.rb', line 59

def status_name(id)
  @possible_item_statuses[id]
end