Grape middleware to log ReadMe metrics for Grape API endpoints. The spiritual equivalent of ReadMe::Metrics but for Grape APIs.
Read up on ReadMe::Metrics's usage.
Add this line to your application's Gemfile:
gem "grape-readme-metrics"
Then execute:
$ bundle install
Mount the middleware in your API:
class MyApi < Grape::API
use Grape::ReadMe::Metrics::Logging
end
Define settings in an initializer (defaults below):
# config/initializers/grape_readme_metrics.rb
Grape::ReadMe::Metrics.configure do |config|
config.sdk_api_key = "INSERT_YOUR_README_API_KEY_HERE"
config.sdk_development = true || false
config.user_id = Proc.new { current_user.id || "guest" }
config.user_label = "Guest User"
config.user_email = "guest@example.com"
end
Then enable for your Grape endpoints using the log_readme_metrics
DSL:
class MyApi < Grape::API
use Grape::ReadMe::Metrics::Logging
resources :contacts do
log_readme_metrics
get do
Contact.all
end
end
end
That's it!
Refer to ReadMe::Metrics for information on ReadMe metrics.
The gem is available as open source under the terms of the MIT License.