Class: Bx
Overview
Uses bX recommender service to generate links to “similar” articles.
REQUIREMENTS: You must be an bX customer. Required field “token” is specific to your institution. Optional fields:
max_records - max number of records returned; default 10
threshold - minimum score a recommendation must have in order to be included in the results; scores range from 0 to 100; default 50
openurl_base - base for other link resolver; default "/resolve"
source - values "local"|"global"; default "global"
Constant Summary
Constants inherited from Service
Service::LinkOutFilterTask, Service::StandardTask
Instance Attribute Summary
Attributes inherited from Service
#group, #name, #priority, #request, #service_id, #status, #task, #url
Instance Method Summary collapse
- #handle(request) ⇒ Object
-
#initialize(config) ⇒ Bx
constructor
A new instance of Bx.
- #service_types_generated ⇒ Object
Methods inherited from Service
#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_to_view_data, #response_url, #view_data_from_service_type
Constructor Details
#initialize(config) ⇒ Bx
Returns a new instance of Bx.
15 16 17 18 19 20 21 22 23 |
# File 'app/service_adaptors/bx.rb', line 15 def initialize(config) @display_name = "Bx" @base_url = "http://recommender.service.exlibrisgroup.com/service/recommender/openurl" @max_records = "5" @threshold = "50" @source = "global" @openurl_base = "/resolve" super(config) end |
Instance Method Details
#handle(request) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/service_adaptors/bx.rb', line 29 def handle(request) format = "rss" bx_url = "#{@base_url}?res_dat=format%3D#{format}%26source%3D#{@source}%26token%3D#{@token}%26maxRecords%3D#{@max_records}%26threshold%3D#{@threshold}%26baseUrl%3D#{@openurl_base}&#{request.to_context_object.kev}" response = open(bx_url) response_xml_str = response.read response_xml = Nokogiri::XML(response_xml_str) response_xml.search("//item").each do |item| title = item.at("title").inner_text = item.at("author").inner_text display_text = (.nil?)? "#{title}" : "#{}; #{title}" url = item.at("link").inner_text request.add_service_response( :service=>self, :display_text => display_text, :url => url, :service_type_value => :similar) end return request.dispatched(self, true) end |
#service_types_generated ⇒ Object
25 26 27 |
# File 'app/service_adaptors/bx.rb', line 25 def service_types_generated return [ServiceTypeValue[:similar]] end |