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



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

def initialize evergreen_domain
    @evergreen_domain = evergreen_domain
    @gateway = URI evergreen_domain+OSRF_PATH
    fetch_idl_order
    unless fetch_statuses
        raise CouldNotConnectToEvergreenError
    end
    fetch_ou_tree
end

Instance Attribute Details

#org_unitsObject (readonly)

Returns the value of attribute org_units.



11
12
13
# File 'lib/evergreen_holdings.rb', line 11

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`



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

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}"
            if @org_units[options[:org_unit]][:descendants]
                @org_units[options[:org_unit]][:descendants].each do |ou|
                    params <<  + "&param=#{ou}"
                end
            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
56
57
58
59
60
61
62
63
64
# File 'lib/evergreen_holdings.rb', line 53

def location_name id
    params = "format=json&input_format=json&service=open-ils.circ&method=open-ils.circ.copy_location.retrieve&param=#{id}"
    @gateway.query = params
    res = send_query
    if res
        data = JSON.parse(res.body)['payload'][0]
        unless data.key? 'stacktrace'
            return data['__p'][@idl_order[:acpl]['name']]
        end
    end
    return id
end

#ou_name(id) ⇒ Object



70
71
72
# File 'lib/evergreen_holdings.rb', line 70

def ou_name id
    return @org_units[id][:name]
end

#status_name(id) ⇒ Object



66
67
68
# File 'lib/evergreen_holdings.rb', line 66

def status_name id
    return @possible_item_statuses[id]
end