Added api_only option
Andrew Kane
committed Aug 23, 2016
commit f7cb00bb3c937d6d3219a20aab80b94347a9d5cb
Showing 3
changed files with
9 additions
and 6 deletions
ahoy.rb b/lib/ahoy.rb
+3
-0
| @@ | @@ -84,6 +84,9 @@ module Ahoy |
| mattr_accessor :job_queue | |
| self.job_queue = :ahoy | |
| + | mattr_accessor :api_only |
| + | self.api_only = false |
| + | |
| def self.ensure_uuid(id) | |
| valid = UUIDTools::UUID.parse(id) rescue nil | |
| if valid | |
ahoy/controller.rb b/lib/ahoy/controller.rb
+4
-4
| @@ | @@ -6,12 +6,12 @@ module Ahoy |
| base.helper_method :current_visit | |
| base.helper_method :ahoy | |
| if base.respond_to?(:before_action) | |
| - | base.before_action :set_ahoy_cookies |
| - | base.before_action :track_ahoy_visit |
| + | base.before_action :set_ahoy_cookies, unless: -> { Ahoy.api_only } |
| + | base.before_action :track_ahoy_visit, unless: -> { Ahoy.api_only } |
| base.before_action :set_ahoy_request_store | |
| else | |
| - | base.before_filter :set_ahoy_cookies |
| - | base.before_filter :track_ahoy_visit |
| + | base.before_filter :set_ahoy_cookies, unless: -> { Ahoy.api_only } |
| + | base.before_filter :track_ahoy_visit, unless: -> { Ahoy.api_only } |
| base.before_filter :set_ahoy_request_store | |
| end | |
| end | |
ahoy/tracker.rb b/lib/ahoy/tracker.rb
+2
-2
| @@ | @@ -101,11 +101,11 @@ module Ahoy |
| protected | |
| def visit_token_helper | |
| - | @visit_token_helper ||= existing_visit_id || (@options[:api] && request.params["visit_token"]) || generate_id |
| + | @visit_token_helper ||= existing_visit_id || (@options[:api] && request.params["visit_token"]) || (Ahoy.api_only ? nil : generate_id) |
| end | |
| def visitor_token_helper | |
| - | @visitor_token_helper ||= existing_visitor_id || (@options[:api] && request.params["visitor_token"]) || generate_id |
| + | @visitor_token_helper ||= existing_visitor_id || (@options[:api] && request.params["visitor_token"]) || (Ahoy.api_only ? nil : generate_id) |
| end | |
| def set_cookie(name, value, duration = nil, use_domain = true) | |