Class: EvergreenHoldings::Connection
- Inherits:
-
Object
- Object
- EvergreenHoldings::Connection
- Defined in:
- lib/evergreen_holdings.rb
Instance Method Summary collapse
-
#get_holdings(tcn, options = {}) ⇒ Object
Fetch holdings data from the Evergreen server Returns a Status object.
-
#initialize(evergreen_domain) ⇒ Connection
constructor
Create a new object with the evergreen_domain specified, e.g.
- #location_name(id) ⇒ Object
- #status_name(id) ⇒ Object
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’‘
13 14 15 16 17 18 |
# File 'lib/evergreen_holdings.rb', line 13 def initialize evergreen_domain @gateway = URI evergreen_domain+OSRF_PATH unless fetch_statuses raise CouldNotConnectToEvergreenError end 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`
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/evergreen_holdings.rb', line 25 def get_holdings tcn, = {} if .key?(:org_unit) params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.retrieve¶m=auth_token_not_needed_for_this_call¶m=#{tcn}¶m=#{options[:org_unit]}" else params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.global.retrieve¶m=auth_token_not_needed_for_this_call¶m=#{tcn}" end @gateway.query = params res = Net::HTTP.get_response(@gateway) return Status.new res.body, self if res.is_a?(Net::HTTPSuccess) end |
#location_name(id) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/evergreen_holdings.rb', line 37 def location_name id params = "format=json&input_format=json&service=open-ils.circ&method=open-ils.circ.copy_location.retrieve¶m=#{id}" @gateway.query = params res = Net::HTTP.get_response(@gateway) if res.is_a? Net::HTTPSuccess data = JSON.parse(res.body)['payload'][0] unless data.key? 'stacktrace' return data['__p'][4] end end return id end |
#status_name(id) ⇒ Object
50 51 52 |
# File 'lib/evergreen_holdings.rb', line 50 def status_name id return @possible_item_statuses[id] end |