api_analytics 1.0.2 → 1.0.3

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
  SHA256:
3
- metadata.gz: 6c4d318b3d83025f43ba07d133256ce35d250466f876f4c2924a133cac7f2806
4
- data.tar.gz: 793e0d8437796cb2b1ad3db61b1b39b4294b811db599a21c151ec5f088b00a36
3
+ metadata.gz: '098d01b85d0fcc21c62cfd725e9627023215347bf514984ce32439c8ad14b032'
4
+ data.tar.gz: 0e9afbc15ee1ffd011c344fb9fded1afeba64381b1040e5e01b42ef422dc5d5a
5
5
  SHA512:
6
- metadata.gz: ea85b0e60ad7a9e796dd1a406f3eff0a81149073b5f0e019c7b4f2eec26b932c92063490e49b74422400f6e45e5e1cccbed2f7b1ede7d42e649342925d0f31ca
7
- data.tar.gz: 37ab6d51c091c4aa7c3e56d42c2eb0c7dc17529a855ab3d1a18c947731f1f3036042f989fffa7c593d4061fb37cced5d2bbf2395114d695e0ab5cc8268ddce59
6
+ metadata.gz: 452d37e57dbcb9fa71fff792238de09f49bc3f0cb6538417478087b553f8dd18bfadeaaca2757706f15872e01ea693d0bcfa0824c4867b8b557febd9de8cab54
7
+ data.tar.gz: 5dc72c197e4d12fcabcfa4e12f1a7f42e1f7d0496095ccde7e981b2d12d64a0e02cd48e1167355c194ac3ed1526696b7fc221e773efe1cef2c3809ad94ce8648
data/README.md CHANGED
@@ -18,19 +18,11 @@ gem install api_analytics
18
18
 
19
19
  #### Rails
20
20
 
21
- Assign your API key to `ANALYTICS_API_KEY` in `config/secrets.yml`.
22
-
23
- ```yml
24
- development:
25
- ANALYTICS_API_KEY: <api_key>
26
- production:
27
- ANALYTICS_API_KEY: <api_key>
28
- ```
29
-
30
- Require `api_analytics` and add the analytics middleware to your rails application in `config/application.rb`.
21
+ Add the analytics middleware to your rails application in `config/application.rb`.
31
22
 
32
23
  ```ruby
33
- require "api_analytics"
24
+ require 'rails'
25
+ require 'api_analytics'
34
26
 
35
27
  Bundler.require(*Rails.groups)
36
28
 
@@ -39,11 +31,28 @@ module RailsMiddleware
39
31
  config.load_defaults 6.1
40
32
  config.api_only = true
41
33
 
42
- config.middleware.use ::Analytics::Middleware # Add middleware
34
+ config.middleware.use ::Analytics::Middleware, <api_key> # Add middleware
43
35
  end
44
36
  end
45
37
  ```
46
38
 
39
+ #### Sinatra
40
+
41
+ ```ruby
42
+ require 'sinatra'
43
+ require 'api_analytics'
44
+
45
+ use Analytics::Middleware, <api_key>
46
+
47
+ before do
48
+ content_type 'application/json'
49
+ end
50
+
51
+ get '/' do
52
+ {message: 'Hello World!'}.to_json
53
+ end
54
+ ```
55
+
47
56
  ### 3. View your analytics
48
57
 
49
58
  Your API will log requests on all valid routes. Head over to https://my-api-analytics.vercel.app/dashboard and paste in your API key to view your dashboard.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Analytics
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.3"
5
5
  end
data/lib/api_analytics.rb CHANGED
@@ -6,10 +6,9 @@ require 'json'
6
6
 
7
7
  module Analytics
8
8
  class Middleware
9
- def initialize(app)
9
+ def initialize(app, api_key)
10
10
  @app = app
11
- @api_key = Rails.application.secrets.ANALYTICS_API_KEY
12
- raise StandardError.new 'ANALYTICS_API_KEY secret unset.' if @api_key.nil?
11
+ @api_key = api_key
13
12
  end
14
13
 
15
14
  def call(env)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Draper