Skip to content

Commit

Permalink
Merge pull request #14 from mlibrary/BLUEDOC-1142-add-investigation-o…
Browse files Browse the repository at this point in the history
…r-request-to-skip-call

BLUEDOC-1142 - Add investigation or request to skip call in IRUS gem
  • Loading branch information
sethaj authored May 4, 2021
2 parents d919e8e + fa03d1c commit 93fb8ab
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ def inject_public_declaration( target_path, after_action )

def skip_send_irus_analytics_method
<<-EOS
def #{SKIP_SEND_IRUS_ANALYTICS_METHOD_NAME}
def #{SKIP_SEND_IRUS_ANALYTICS_METHOD_NAME}(usage_event_type)
# return true to skip tracking, for example to skip curation_concerns.visibility == 'private'
false
case usage_event_type
when '#{IrusAnalytics::INVESTIGATION}'
false
when '#{IrusAnalytics::REQUEST}'
false
end
end
EOS
end
Expand Down
9 changes: 5 additions & 4 deletions lib/irus_analytics/controller/analytics_behaviour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,22 @@ def enqueue
end
end

def skip_send?
def skip_send?(usage_event_type)
bold_debug [ here, called_from,
"self.class.name=#{self.class.name}",
"enable_skip_send_method=#{enable_skip_send_method}",
"usage_event_type=#{usage_event_type}",
"" ] if verbose_debug
return false unless enable_skip_send_method
bold_debug [ here, called_from,
"self.class.name=#{self.class.name}",
"respond_to?(:skip_send_irus_analytics?)=#{respond_to?(:skip_send_irus_analytics?)}",
"" ] if verbose_debug
return false unless respond_to?(:skip_send_irus_analytics?)
rv = skip_send_irus_analytics?
rv = skip_send_irus_analytics?(usage_event_type)
bold_debug [ here, called_from,
"self.class.name=#{self.class.name}",
"skip_send_irus_analytics?=#{rv}",
"skip_send_irus_analytics?(#{usage_event_type})=#{rv}",
"" ] if verbose_debug
rv
end
Expand All @@ -168,7 +169,7 @@ def send_irus_analytics(identifier=nil, usage_event_type=REQUEST)
"enabled=#{enabled}",
"" ] if verbose_debug
return unless enabled
return if skip_send?
return if skip_send?(usage_event_type)
@identifier = identifier
@usage_event_type = usage_event_type
(request && ( filter_request?(request) || missing_server? || enqueue )) || display_warning
Expand Down
2 changes: 1 addition & 1 deletion lib/irus_analytics/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module IrusAnalytics
VERSION = "0.0.9"
VERSION = "0.0.10"
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestClass
include IrusAnalytics::Controller::AnalyticsBehaviour
attr_accessor :request, :item_identifier_for_irus_analytics

def skip_send_irus_analytics?
def skip_send_irus_analytics?(_usage_event_type)
false
end

Expand Down Expand Up @@ -55,7 +55,7 @@ def skip_send_irus_analytics?
allow(@test_class).to receive(:datetime_stamp) .and_return(date_time)
allow(@test_class).to receive(:source_repository) .and_return("hydra.hull.ac.uk")
allow(@test_class).to receive(:irus_server_address) .and_return("irus-server-address.org")
expect(@test_class).to receive(:skip_send_irus_analytics?).at_least(:once).and_return true
expect(@test_class).to receive(:skip_send_irus_analytics?).with('Request').at_least(:once).and_return true
params = { date_stamp: date_time,
client_ip_address: "127.0.0.1",
user_agent: "Test user agent",
Expand All @@ -64,7 +64,7 @@ def skip_send_irus_analytics?
http_referer: "http://localhost:3000",
source_repository: "hydra.hull.ac.uk"
}
allow(Resque).to receive(:enqueue) .and_return(nil)
allow(Resque).to receive(:enqueue).and_return(nil)
expect(@test_class).to_not receive(:filter_request?)
expect(Resque).to_not receive(:enqueue)
@test_class.send_irus_analytics
Expand Down

0 comments on commit 93fb8ab

Please sign in to comment.