Class: SfxBackchannelRecord

Inherits:
Service
  • Object
show all
Defined in:
app/service_adaptors/sfx_backchannel_record.rb

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

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #preempted_by, required_config_params, #response_url, #service_types_generated, #translate

Constructor Details

#initialize(config) ⇒ SfxBackchannelRecord

Returns a new instance of SfxBackchannelRecord.



19
20
21
22
23
# File 'app/service_adaptors/sfx_backchannel_record.rb', line 19

def initialize(config)
  @display_name = "SFX Statistics"
  super(config)
  @timeout ||= 5
end

Instance Method Details

#handle(request) ⇒ Object

This is meant to be called as task:link_out_filter, it doesn’t have an implementation for handle, it implements link_out_filter() instead.



27
28
29
# File 'app/service_adaptors/sfx_backchannel_record.rb', line 27

def handle(request)
   raise "Not implemented."
end

Hook method called by Umlaut. We always return nil because we aren’t interested in modifying the url, just using the callback to record the click with SFX.



34
35
36
37
38
39
40
41
42
43
# File 'app/service_adaptors/sfx_backchannel_record.rb', line 34

def link_out_filter(orig_url, service_response, other_args = {})
  # Only work on responses that came from SFX.
  unless (service_response.service.class.to_s == "Sfx")
     return nil
  end
  make_backchannel_request( service_response )
  
  
  return nil
end

#make_backchannel_request(service_response) ⇒ Object

Does everything in a background thread to avoid slowing down the user.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/service_adaptors/sfx_backchannel_record.rb', line 46

def make_backchannel_request(service_response)

  Thread.new do
    begin
      direct_sfx_url = Sfx.pass_through_url(service_response.data_values)
      # now we call that url through a back channel just to record it
      # with SFX.
      
      parsed_uri = URI.parse(direct_sfx_url )
      sfx_response = Net::HTTP.get_response( parsed_uri  )
      
      #raise if not 200 OK response
      unless ( sfx_response.kind_of?(Net::HTTPSuccess) ||
               sfx_response.kind_of?(Net::HTTPRedirection) )
             # raise
             sfx_response.value
      end                
    rescue Exception => e
      Rails.logger.error("Could not record sfx backchannel click for service_response id #{service_response.id} ; sfx backchannel url attempted: #{direct_sfx_url} ; problem: #{e}")
      Rails.logger.error( e.backtrace.join("\n"))
    end
  end
end