Class: IrusAnalytics::IrusAnalyticsService
- Inherits:
-
Object
- Object
- IrusAnalytics::IrusAnalyticsService
- Defined in:
- lib/irus_analytics/irus_analytics_service.rb
Instance Attribute Summary collapse
-
#irus_server_address ⇒ Object
Returns the value of attribute irus_server_address.
Instance Method Summary collapse
-
#initialize(irus_server_address) ⇒ IrusAnalyticsService
constructor
A new instance of IrusAnalyticsService.
-
#missing_mandatory_params?(params) ⇒ Boolean
At present, all the params, are mandatory…
- #openurl_link_resolver(context_object) ⇒ Object
- #send_analytics(params = {}) ⇒ Object
Constructor Details
#initialize(irus_server_address) ⇒ IrusAnalyticsService
Returns a new instance of IrusAnalyticsService.
7 8 9 10 |
# File 'lib/irus_analytics/irus_analytics_service.rb', line 7 def initialize(irus_server_address) @irus_server_address = irus_server_address @missing_params = [] end |
Instance Attribute Details
#irus_server_address ⇒ Object
Returns the value of attribute irus_server_address.
5 6 7 |
# File 'lib/irus_analytics/irus_analytics_service.rb', line 5 def irus_server_address @irus_server_address end |
Instance Method Details
#missing_mandatory_params?(params) ⇒ Boolean
At present, all the params, are mandatory…
44 45 46 47 |
# File 'lib/irus_analytics/irus_analytics_service.rb', line 44 def missing_mandatory_params?(params) params.each_pair { |key,value| @missing_fields << key if value.to_s.empty? } return !@missing_params.empty? end |
#openurl_link_resolver(context_object) ⇒ Object
49 50 51 |
# File 'lib/irus_analytics/irus_analytics_service.rb', line 49 def openurl_link_resolver(context_object) OpenURL::Transport.new(@irus_server_address, context_object) end |
#send_analytics(params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/irus_analytics/irus_analytics_service.rb', line 12 def send_analytics(params = {}) if @irus_server_address.to_s.empty? raise ArgumentError, "Cannot send analytics: Missing Irus server address" end default_params = {date_stamp: "", client_ip_address: "", user_agent: "", item_oai_identifier: "", file_url: "", http_referer: "", source_repository: ""} params = default_params.merge(params) if missing_mandatory_params?(params) raise ArgumentError, "Missing the following required params: #{@missing_params}" end tracker_context_object_builder = IrusAnalytics::TrackerContextObjectBuilder.new tracker_context_object_builder.set_event_datestamp(params[:date_stamp]) tracker_context_object_builder.set_client_ip_address(params[:client_ip_address]) tracker_context_object_builder.set_user_agent(params[:user_agent]) tracker_context_object_builder.set_oai_identifier(params[:item_oai_identifier]) tracker_context_object_builder.set_file_url(params[:file_url]) tracker_context_object_builder.set_http_referer(params[:http_referer]) tracker_context_object_builder.set_source_repository(params[:source_repository]) transport = openurl_link_resolver(tracker_context_object_builder.context_object) transport.get if transport.code != "200" raise "Unexpected response from IRUS server" end end |