api_analytics 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e63c1589bb56b02570e9ae05d9f38ca68bb604ef071084f49638b9ff7cc7e90a
4
- data.tar.gz: e468852d2153f6827c8359aceb349884c21e00766b8efbc4895057b89e26318a
3
+ metadata.gz: c0cf3498f46f29e07b93bc01d2182cd8daa147614c349559d9ed9dbc84515db4
4
+ data.tar.gz: 1dff19db20f4b033b48dcc867f27b127618185e10a59239f2d3fc894576a4aea
5
5
  SHA512:
6
- metadata.gz: 25be82084145978d624eb701f84dfe0639ba5c405011b55398f6da5a0e788d4ed87322bd9253002ed9528ac3e757e709a393962327f3864bb7f696a161245c89
7
- data.tar.gz: d65d9b770e3640008a9243dba26d07722bd47acbf786e571c984f2c568f40e2bb2a94d973c667fbe0c02545d091d523663687b26c88e1437bf1fbe3576b6a634
6
+ metadata.gz: 42b54e3a6ecdeecc5315b8b67b91e26e3d65b55069c1db84d2987e50b72cb2cd58cb028201953ee39613ccfdd9dbc71899c7885daaaebf7cc84350b6517e091c
7
+ data.tar.gz: d65e324ac5036b3434bd1b71fd7390458e6aa92388e8ce10b0a30a6eb89d422001d07f405fbf0f9296691c1149015f2f7ed15970fbdaeae2ff7be71769532bdc
data/.gitignore CHANGED
@@ -1,10 +1,10 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
10
  *.gem
data/.rubocop.yml CHANGED
@@ -1,13 +1,13 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
3
-
4
- Style/StringLiterals:
5
- Enabled: true
6
- EnforcedStyle: double_quotes
7
-
8
- Style/StringLiteralsInInterpolation:
9
- Enabled: true
10
- EnforcedStyle: double_quotes
11
-
12
- Layout/LineLength:
13
- Max: 120
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md CHANGED
@@ -1,5 +1,5 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2022-12-05
4
-
5
- - Initial release
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-12-05
4
+
5
+ - Initial release
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,84 +1,84 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tomjdraper1@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tomjdraper1@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile CHANGED
@@ -1,10 +1,9 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in api_analytics.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rubocop", "~> 1.7"
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in api_analytics.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rubocop", "~> 1.7"
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2022 Tom Draper
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Tom Draper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,58 +1,58 @@
1
- # API Analytics
2
-
3
- A lightweight API analytics solution, complete with a dashboard.
4
-
5
- ## Getting Started
6
-
7
- ### 1. Generate a new API key
8
-
9
- Head to https://my-api-analytics.vercel.app/generate to generate your unique API key with a single click. This key is used to monitor your specific API, so keep it secret! It's also required in order to view your APIs analytics dashboard.
10
-
11
- ### 2. Add middleware to your API
12
-
13
- Add our lightweight middleware to your API. Almost all processing is handled by our servers so there should be virtually no impact on your APIs performance.
14
-
15
- ```bash
16
- gem install api_analytics
17
- ```
18
-
19
- #### Rails
20
-
21
- Add the analytics middleware to your rails application in `config/application.rb`.
22
-
23
- ```ruby
24
- require 'rails'
25
- require 'api_analytics'
26
-
27
- Bundler.require(*Rails.groups)
28
-
29
- module RailsMiddleware
30
- class Application < Rails::Application
31
- config.load_defaults 6.1
32
- config.api_only = true
33
-
34
- config.middleware.use ::Analytics::Rails, <api_key> # Add middleware
35
- end
36
- end
37
- ```
38
-
39
- #### Sinatra
40
-
41
- ```ruby
42
- require 'sinatra'
43
- require 'api_analytics'
44
-
45
- use Analytics::Sinatra, <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
-
56
- ### 3. View your analytics
57
-
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
+ # API Analytics
2
+
3
+ A lightweight API analytics solution, complete with a dashboard.
4
+
5
+ ## Getting Started
6
+
7
+ ### 1. Generate a new API key
8
+
9
+ Head to https://my-api-analytics.vercel.app/generate to generate your unique API key with a single click. This key is used to monitor your specific API, so keep it secret! It's also required in order to view your APIs analytics dashboard.
10
+
11
+ ### 2. Add middleware to your API
12
+
13
+ Add our lightweight middleware to your API. Almost all processing is handled by our servers so there should be virtually no impact on your APIs performance.
14
+
15
+ ```bash
16
+ gem install api_analytics
17
+ ```
18
+
19
+ #### Rails
20
+
21
+ Add the analytics middleware to your rails application in `config/application.rb`.
22
+
23
+ ```ruby
24
+ require 'rails'
25
+ require 'api_analytics'
26
+
27
+ Bundler.require(*Rails.groups)
28
+
29
+ module RailsMiddleware
30
+ class Application < Rails::Application
31
+ config.load_defaults 6.1
32
+ config.api_only = true
33
+
34
+ config.middleware.use ::Analytics::Rails, <api_key> # Add middleware
35
+ end
36
+ end
37
+ ```
38
+
39
+ #### Sinatra
40
+
41
+ ```ruby
42
+ require 'sinatra'
43
+ require 'api_analytics'
44
+
45
+ use Analytics::Sinatra, <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
+
56
+ ### 3. View your analytics
57
+
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.
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rubocop/rake_task"
5
-
6
- RuboCop::RakeTask.new
7
-
8
- task default: :rubocop
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -1,34 +1,28 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/api_analytics/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "api_analytics"
7
- spec.version = Analytics::VERSION
8
- spec.authors = ["Tom Draper"]
9
- spec.email = ["tomjdraper1@gmail.com"]
10
-
11
- spec.summary = "Monitoring and analytics for API applications."
12
- spec.description = "Monitoring and analytics for API applications."
13
- spec.homepage = "https://github.com/tom-draper/api-analytics"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.4.0"
16
-
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = "https://github.com/tom-draper/api-analytics"
19
-
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
- end
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
-
29
- # Uncomment to register a new dependency of your gem
30
- # spec.add_dependency "example-gem", "~> 1.0"
31
-
32
- # For more information and examples about making a new gem, checkout our
33
- # guide at: https://bundler.io/guides/creating_gem.html
34
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/api_analytics/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "api_analytics"
7
+ spec.version = Analytics::VERSION
8
+ spec.authors = ["Tom Draper"]
9
+ spec.email = ["tomjdraper1@gmail.com"]
10
+
11
+ spec.summary = "Monitoring and analytics for API applications."
12
+ spec.description = "Monitoring and analytics for API applications."
13
+ spec.homepage = "https://github.com/tom-draper/api-analytics"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/tom-draper/api-analytics"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
data/bin/console CHANGED
@@ -1,15 +1,15 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "api_analytics"
6
-
7
- # You can add fixtures and/or initialization code here to make experimenting
8
- # with your gem easier. You can also use a different console, if you like.
9
-
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- require "irb"
15
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "api_analytics"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module Analytics
4
- VERSION = "1.0.4"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Analytics
4
+ VERSION = "1.0.5"
5
+ end
data/lib/api_analytics.rb CHANGED
@@ -1,62 +1,63 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
- require 'net/http'
5
- require 'json'
6
-
7
- module Analytics
8
- class Middleware
9
- def initialize(app, api_key)
10
- @app = app
11
- @api_key = api_key
12
- end
13
-
14
- def call(env)
15
- start = Time.now
16
- status, headers, response = @app.call(env)
17
-
18
- data = {
19
- api_key: @api_key,
20
- hostname: env['HTTP_HOST'],
21
- path: env['REQUEST_PATH'],
22
- user_agent: env['HTTP_USER_AGENT'],
23
- method: env['REQUEST_METHOD'],
24
- status: status,
25
- framework: @framework,
26
- response_time: (Time.now - start).to_f.round,
27
- }
28
-
29
- Thread.new {
30
- log_request(data)
31
- }
32
-
33
- [status, headers, response]
34
- end
35
-
36
- private
37
-
38
- def log_request(data)
39
- uri = URI('https://api-analytics-server.vercel.app/api/log-request')
40
- res = Net::HTTP.post(uri, data.to_json)
41
- end
42
- end
43
-
44
- private_constant :Middleware
45
-
46
- class Rails < Middleware
47
- def initialize(app, api_key)
48
- super(app, api_key)
49
- @framework = "Rails"
50
- end
51
- end
52
-
53
- class Sinatra < Middleware
54
- def initialize(app, api_key)
55
- super(app, api_key)
56
- @framework = "Sinatra"
57
- end
58
- end
59
- end
60
-
61
-
62
-
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+
7
+ module Analytics
8
+ class Middleware
9
+ def initialize(app, api_key)
10
+ @app = app
11
+ @api_key = api_key
12
+ end
13
+
14
+ def call(env)
15
+ start = Time.now
16
+ status, headers, response = @app.call(env)
17
+
18
+ data = {
19
+ api_key: @api_key,
20
+ hostname: env['HTTP_HOST'],
21
+ ip_address: env['REMOTE_ADDR'],
22
+ path: env['REQUEST_PATH'],
23
+ user_agent: env['HTTP_USER_AGENT'],
24
+ method: env['REQUEST_METHOD'],
25
+ status: status,
26
+ framework: @framework,
27
+ response_time: (Time.now - start).to_f.round,
28
+ }
29
+
30
+ Thread.new {
31
+ log_request(data)
32
+ }
33
+
34
+ [status, headers, response]
35
+ end
36
+
37
+ private
38
+
39
+ def log_request(data)
40
+ uri = URI('https://api-analytics-server.vercel.app/api/log-request')
41
+ res = Net::HTTP.post(uri, data.to_json)
42
+ end
43
+ end
44
+
45
+ private_constant :Middleware
46
+
47
+ class Rails < Middleware
48
+ def initialize(app, api_key)
49
+ super(app, api_key)
50
+ @framework = "Rails"
51
+ end
52
+ end
53
+
54
+ class Sinatra < Middleware
55
+ def initialize(app, api_key)
56
+ super(app, api_key)
57
+ @framework = "Sinatra"
58
+ end
59
+ end
60
+ end
61
+
62
+
63
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Draper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Monitoring and analytics for API applications.
14
14
  email: