ahoy_matey 1.5.4 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78e1ff8eb75ded92834b341ed0319b37d784f5bd
4
- data.tar.gz: ac76baab29e95a2f7fe69d9505b2dc08ab31cfe5
3
+ metadata.gz: fb739af8b0e101e97b738d5839b438da101fc41f
4
+ data.tar.gz: 5c202d2758f9fe5b33a6aa142e8a2c7520ff1f92
5
5
  SHA512:
6
- metadata.gz: 87fecfd6cf70712efc9e7bde3e64587b86ab3f85f41b3fe68165e85a5fe37f67bff8f9d590bcf46a1b0ca6fe2312aa3253131790a2bde92acb766fbccdf39b9a
7
- data.tar.gz: fc2abee96f713a6b072290b53b64b2dfa164f0764404b1c8d0fff708e0e1d18f586790ff65eaf1f5b6834958144fbd4b5b3f25050f7722ac28d0ef3124fb4ebf
6
+ metadata.gz: 7d65012b0f13dc8c79bc0efed4ef4c0f5618fa5356eab36881cd44ebcf74029b9ab8820a6b160cf4d4713e8a910bb17e6f57391e0add52804855dd8963c7a58c
7
+ data.tar.gz: a16fb236d50969a9a3ba95ca28f2f1f6e4ffa4c6715eedb854bec2cb7f57257a4812d4b46c94ae0fdfd44146b9e60f336faf3944976e3d0dbf221ade9c6d3088
@@ -1,3 +1,8 @@
1
+ ## 1.5.5
2
+
3
+ - Added support for Rails API
4
+ - Added NATS and NSQ stores
5
+
1
6
  ## 1.5.4
2
7
 
3
8
  - Fixed issue with duplicate events
data/README.md CHANGED
@@ -29,10 +29,7 @@ Ahoy supports a number of data stores out of the box. You can start with one of
29
29
 
30
30
  - [PostgreSQL, MySQL, or SQLite](#postgresql-mysql-or-sqlite)
31
31
  - [MongoDB](#mongodb)
32
- - [Kafka](#kafka)
33
- - [Fluentd](#fluentd)
34
- - [RabbitMQ](#rabbitmq)
35
- - [Amazon Kinesis Firehose](#amazon-kinesis-firehose)
32
+ - [Kafka](#kafka), [Fluentd](#fluentd), [RabbitMQ](#rabbitmq), [NATS](#nats), [NSQ](#nsq), or [Amazon Kinesis Firehose](#amazon-kinesis-firehose)
36
33
  - [Logs](#logs)
37
34
  - [Custom](#custom)
38
35
 
@@ -47,6 +44,8 @@ rake db:migrate
47
44
 
48
45
  ### MongoDB
49
46
 
47
+ Run:
48
+
50
49
  ```sh
51
50
  rails generate ahoy:stores:mongoid
52
51
  ```
@@ -99,6 +98,38 @@ rails generate ahoy:stores:bunny
99
98
 
100
99
  Use `ENV["RABBITMQ_URL"]` to configure.
101
100
 
101
+ ### NATS
102
+
103
+ Add [nats-pure](https://github.com/nats-io/pure-ruby-nats) to your Gemfile.
104
+
105
+ ```ruby
106
+ gem 'nats-pure'
107
+ ```
108
+
109
+ And run:
110
+
111
+ ```sh
112
+ rails generate ahoy:stores:nats
113
+ ```
114
+
115
+ Use `ENV["NATS_URL"]` to configure.
116
+
117
+ ### NSQ
118
+
119
+ Add [nsq-ruby](https://github.com/wistia/nsq-ruby) to your Gemfile.
120
+
121
+ ```ruby
122
+ gem 'nsq-ruby'
123
+ ```
124
+
125
+ And run:
126
+
127
+ ```sh
128
+ rails generate ahoy:stores:nsq
129
+ ```
130
+
131
+ Use `ENV["NSQ_URL"]` to configure.
132
+
102
133
  ### Amazon Kinesis Firehose
103
134
 
104
135
  Add [aws-sdk](https://github.com/aws/aws-sdk-ruby) to your Gemfile.
@@ -261,7 +292,7 @@ Exceptions are rescued so analytics do not break your app. Ahoy uses [Safely](ht
261
292
  To customize this, use:
262
293
 
263
294
  ```ruby
264
- Safely.report_exception_method = proc { |e| Rollbar.error(e) }
295
+ Safely.report_exception_method = -> (e) { Rollbar.error(e) }
265
296
  ```
266
297
 
267
298
  ### Use Different Models
@@ -27,6 +27,8 @@ require "ahoy/stores/log_store"
27
27
  require "ahoy/stores/fluentd_store"
28
28
  require "ahoy/stores/mongoid_store"
29
29
  require "ahoy/stores/kafka_store"
30
+ require "ahoy/stores/nats_store"
31
+ require "ahoy/stores/nsq_store"
30
32
  require "ahoy/stores/kinesis_firehose_store"
31
33
  require "ahoy/stores/bunny_store"
32
34
  require "ahoy/engine" if defined?(Rails)
@@ -116,6 +118,7 @@ end
116
118
  if defined?(Rails)
117
119
  ActiveSupport.on_load(:action_controller) do
118
120
  ActionController::Base.send :include, Ahoy::Controller
121
+ ActionController::API.send :include, Ahoy::Controller if defined?(ActionController::API)
119
122
  end
120
123
 
121
124
  ActiveSupport.on_load(:active_record) do
@@ -3,8 +3,10 @@ require "request_store"
3
3
  module Ahoy
4
4
  module Controller
5
5
  def self.included(base)
6
- base.helper_method :current_visit
7
- base.helper_method :ahoy
6
+ if base.respond_to?(:helper_method)
7
+ base.helper_method :current_visit
8
+ base.helper_method :ahoy
9
+ end
8
10
  if base.respond_to?(:before_action)
9
11
  base.before_action :set_ahoy_cookies, unless: -> { Ahoy.api_only }
10
12
  base.before_action :track_ahoy_visit, unless: -> { Ahoy.api_only }
@@ -18,7 +18,8 @@ module Ahoy
18
18
  visit.save!
19
19
  geocode(visit)
20
20
  rescue *unique_exception_classes
21
- # do nothing
21
+ # reset to nil so subsequent calls to track_event will load visit from DB
22
+ @visit = nil
22
23
  end
23
24
  end
24
25
 
@@ -19,7 +19,8 @@ module Ahoy
19
19
  visit.save!
20
20
  geocode(visit)
21
21
  rescue *unique_exception_classes
22
- # do nothing
22
+ # reset to nil so subsequent calls to track_event will load visit from DB
23
+ @visit = nil
23
24
  end
24
25
  end
25
26
 
@@ -43,7 +44,7 @@ module Ahoy
43
44
  event =
44
45
  event_model.new do |e|
45
46
  e.visit_id = visit.try(:id)
46
- e.user = user
47
+ e.user = user if e.respond_to?(:user=)
47
48
  e.name = name
48
49
  e.properties = properties
49
50
  e.time = options[:time]
@@ -0,0 +1,34 @@
1
+ module Ahoy
2
+ module Stores
3
+ class NatsStore < LogStore
4
+ def log_visit(data)
5
+ publish(visits_subject, data)
6
+ end
7
+
8
+ def log_event(data)
9
+ publish(events_subject, data)
10
+ end
11
+
12
+ def publish(subject, data)
13
+ client.publish(subject, data.to_json)
14
+ end
15
+
16
+ def client
17
+ @client ||= begin
18
+ require "nats/io/client"
19
+ client = NATS::IO::Client.new
20
+ client.connect(servers: (ENV["NATS_URL"] || "nats://127.0.0.1:4222").split(","))
21
+ client
22
+ end
23
+ end
24
+
25
+ def visits_subject
26
+ "ahoy_visits"
27
+ end
28
+
29
+ def events_subject
30
+ "ahoy_events"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ module Ahoy
2
+ module Stores
3
+ class NsqStore < LogStore
4
+ def log_visit(data)
5
+ post(visits_topic, data)
6
+ end
7
+
8
+ def log_event(data)
9
+ post(events_topic, data)
10
+ end
11
+
12
+ def client
13
+ @client ||= begin
14
+ require "nsq"
15
+ client = Nsq::Producer.new(
16
+ nsqd: ENV["NSQ_URL"] || "127.0.0.1:4150"
17
+ )
18
+ at_exit { client.terminate }
19
+ client
20
+ end
21
+ end
22
+
23
+ def post(topic, data)
24
+ client.write_to_topic(topic, data.to_json)
25
+ end
26
+
27
+ def visits_topic
28
+ "ahoy_visits"
29
+ end
30
+
31
+ def events_topic
32
+ "ahoy_events"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Ahoy
2
- VERSION = "1.5.4"
2
+ VERSION = "1.5.5"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require "rails/generators"
2
+
3
+ module Ahoy
4
+ module Stores
5
+ module Generators
6
+ class NatsGenerator < Rails::Generators::Base
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def create_initializer
10
+ template "nats_initializer.rb", "config/initializers/ahoy.rb"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "rails/generators"
2
+
3
+ module Ahoy
4
+ module Stores
5
+ module Generators
6
+ class NsqGenerator < Rails::Generators::Base
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def create_initializer
10
+ template "nsq_initializer.rb", "config/initializers/ahoy.rb"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class Ahoy::Store < Ahoy::Stores::NatsStore
2
+ def visits_subject
3
+ "ahoy_visits"
4
+ end
5
+
6
+ def events_subject
7
+ "ahoy_events"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Ahoy::Store < Ahoy::Stores::NsqStore
2
+ def visits_topic
3
+ "ahoy_visits"
4
+ end
5
+
6
+ def events_topic
7
+ "ahoy_events"
8
+ end
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahoy_matey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.4
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -273,6 +273,8 @@ files:
273
273
  - lib/ahoy/stores/kinesis_firehose_store.rb
274
274
  - lib/ahoy/stores/log_store.rb
275
275
  - lib/ahoy/stores/mongoid_store.rb
276
+ - lib/ahoy/stores/nats_store.rb
277
+ - lib/ahoy/stores/nsq_store.rb
276
278
  - lib/ahoy/subscribers/active_record.rb
277
279
  - lib/ahoy/throttle.rb
278
280
  - lib/ahoy/tracker.rb
@@ -292,6 +294,8 @@ files:
292
294
  - lib/generators/ahoy/stores/mongoid_events_generator.rb
293
295
  - lib/generators/ahoy/stores/mongoid_generator.rb
294
296
  - lib/generators/ahoy/stores/mongoid_visits_generator.rb
297
+ - lib/generators/ahoy/stores/nats_generator.rb
298
+ - lib/generators/ahoy/stores/nsq_generator.rb
295
299
  - lib/generators/ahoy/stores/templates/active_record_event_model.rb
296
300
  - lib/generators/ahoy/stores/templates/active_record_events_migration.rb
297
301
  - lib/generators/ahoy/stores/templates/active_record_initializer.rb
@@ -306,6 +310,8 @@ files:
306
310
  - lib/generators/ahoy/stores/templates/mongoid_event_model.rb
307
311
  - lib/generators/ahoy/stores/templates/mongoid_initializer.rb
308
312
  - lib/generators/ahoy/stores/templates/mongoid_visit_model.rb
313
+ - lib/generators/ahoy/stores/templates/nats_initializer.rb
314
+ - lib/generators/ahoy/stores/templates/nsq_initializer.rb
309
315
  - test/properties/mysql_json_test.rb
310
316
  - test/properties/mysql_text_test.rb
311
317
  - test/properties/postgresql_hstore_test.rb