readme-metrics 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +28 -33
  5. data/Makefile +8 -2
  6. data/README.md +1 -1
  7. data/examples/metrics-rails/.gitattributes +7 -0
  8. data/examples/metrics-rails/.gitignore +20 -0
  9. data/examples/metrics-rails/.ruby-version +1 -0
  10. data/examples/metrics-rails/Gemfile +29 -0
  11. data/examples/metrics-rails/Gemfile.lock +184 -0
  12. data/examples/metrics-rails/README.md +38 -0
  13. data/examples/metrics-rails/Rakefile +6 -0
  14. data/examples/metrics-rails/app/controllers/application_controller.rb +2 -0
  15. data/examples/metrics-rails/app/controllers/metrics_controller.rb +34 -0
  16. data/examples/metrics-rails/app/models/application_record.rb +3 -0
  17. data/examples/metrics-rails/bin/bundle +116 -0
  18. data/examples/metrics-rails/bin/rails +4 -0
  19. data/examples/metrics-rails/bin/rake +4 -0
  20. data/examples/metrics-rails/bin/setup +33 -0
  21. data/examples/metrics-rails/config/application.rb +52 -0
  22. data/examples/metrics-rails/config/boot.rb +3 -0
  23. data/examples/metrics-rails/config/credentials.yml.enc +1 -0
  24. data/examples/metrics-rails/config/database.yml +25 -0
  25. data/examples/metrics-rails/config/environment.rb +5 -0
  26. data/examples/metrics-rails/config/environments/development.rb +56 -0
  27. data/examples/metrics-rails/config/environments/production.rb +68 -0
  28. data/examples/metrics-rails/config/environments/test.rb +50 -0
  29. data/examples/metrics-rails/config/initializers/cors.rb +16 -0
  30. data/examples/metrics-rails/config/initializers/filter_parameter_logging.rb +8 -0
  31. data/examples/metrics-rails/config/initializers/inflections.rb +16 -0
  32. data/examples/metrics-rails/config/locales/en.yml +33 -0
  33. data/examples/metrics-rails/config/puma.rb +43 -0
  34. data/examples/metrics-rails/config/routes.rb +5 -0
  35. data/examples/metrics-rails/config.ru +6 -0
  36. data/examples/metrics-rails/db/seeds.rb +7 -0
  37. data/examples/metrics-rails/public/robots.txt +1 -0
  38. data/lib/readme/errors.rb +1 -1
  39. data/lib/readme/har/collection.rb +3 -1
  40. data/lib/readme/har/serializer.rb +2 -2
  41. data/lib/readme/http_request.rb +38 -7
  42. data/lib/readme/http_response.rb +2 -2
  43. data/lib/readme/metrics/version.rb +2 -2
  44. data/lib/readme/metrics.rb +4 -4
  45. data/lib/readme/payload.rb +9 -3
  46. data/lib/readme/webhook.rb +42 -0
  47. data/readme-metrics.gemspec +1 -1
  48. metadata +49 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edf64efc0c1f3a7ba72f9f6d30aaebbd1caf64774258fe7dc69e343751358adb
4
- data.tar.gz: 36dd67292da34691382b5e3d9f7234275c9d14d4b133f8067ed22c2c0c861a02
3
+ metadata.gz: e9d2cf2f3a6e81a4ee2658ac887b8bb7ec3b9fc8cdbef76c627a7ab702f529ec
4
+ data.tar.gz: 83bfccb057682371e7c26a3b37133bf48f44aa77a7fc4eceeec9ab6f4a937210
5
5
  SHA512:
6
- metadata.gz: 20c0d88a3e19f49a742ad52555b22f4cfa1d6fc34eeea60dbeb3410f97050d546ed9caa4d00ba5c518822296d9660a6e24c84c7232165724251cafd68dadab53
7
- data.tar.gz: c29cb1edddfd487996d345be984f402353a1940c4626aad107b4df33537800de0cab8ba41cf294d9a7bfaae5f221cf266012bea8d925ac8794e717b7059c3238
6
+ metadata.gz: 204c6c2d98d6b7300f4ec160ab7c224acba62e4dafae77eae6d135adf84f54443ec7e83ae1d437185e621710553b720885335784a4cd85e60bb6807159b9805c
7
+ data.tar.gz: 0476a102da1dc9659cd965897df2ad2dd40baf07482c97b4519b1680e792639eebd9ed98864287354318702ddd93f85356544be9a69b1cc4ad6f0fbdfa9073af
data/.rubocop.yml CHANGED
@@ -9,6 +9,8 @@ AllCops:
9
9
  # https://docs.rubocop.org/rubocop/cops_layout.html
10
10
  Layout/LineLength:
11
11
  Max: 150
12
+ Exclude:
13
+ - examples/metrics-rails/bin/*
12
14
 
13
15
  # https://docs.rubocop.org/rubocop/cops_metrics.html
14
16
  Metrics/AbcSize:
@@ -65,3 +67,6 @@ Style/RescueStandardError:
65
67
  # and by only catching `StandardError` we'll miss out on something else and potentially take down
66
68
  # someones integration.
67
69
  Enabled: false
70
+
71
+ Gemspec/RequireMFA:
72
+ Enabled: false
data/Gemfile CHANGED
@@ -12,5 +12,4 @@ gem 'rspec', '~> 3.0'
12
12
  gem 'rubocop', require: false
13
13
  gem 'rubocop-performance', require: false
14
14
  gem 'rubocop-rspec', require: false
15
- gem 'uuid'
16
15
  gem 'webmock'
data/Gemfile.lock CHANGED
@@ -1,42 +1,39 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- readme-metrics (2.0.1)
4
+ readme-metrics (2.2.0)
5
5
  httparty (~> 0.18)
6
- uuid (~> 2.3.8)
6
+ rack (>= 2.2, < 4)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  addressable (2.8.0)
12
12
  public_suffix (>= 2.0.2, < 5.0)
13
- ast (2.4.1)
13
+ ast (2.4.2)
14
14
  crack (0.4.3)
15
15
  safe_yaml (~> 1.0.0)
16
16
  diff-lcs (1.4.4)
17
17
  hashdiff (1.0.1)
18
- httparty (0.20.0)
19
- mime-types (~> 3.0)
18
+ httparty (0.21.0)
19
+ mini_mime (>= 1.0.0)
20
20
  multi_xml (>= 0.5.2)
21
+ json (2.6.2)
21
22
  json-schema (2.8.1)
22
23
  addressable (>= 2.4)
23
- macaddr (1.7.2)
24
- systemu (~> 2.6.5)
25
- mime-types (3.4.1)
26
- mime-types-data (~> 3.2015)
27
- mime-types-data (3.2022.0105)
24
+ mini_mime (1.1.2)
28
25
  multi_xml (0.6.0)
29
- parallel (1.19.2)
30
- parser (2.7.1.4)
26
+ parallel (1.22.1)
27
+ parser (3.1.2.1)
31
28
  ast (~> 2.4.1)
32
29
  public_suffix (4.0.6)
33
30
  rack (2.2.3.1)
34
31
  rack-test (1.1.0)
35
32
  rack (>= 1.0, < 3)
36
- rainbow (3.0.0)
33
+ rainbow (3.1.1)
37
34
  rake (12.3.3)
38
- regexp_parser (1.7.1)
39
- rexml (3.2.4)
35
+ regexp_parser (2.5.0)
36
+ rexml (3.2.5)
40
37
  rspec (3.9.0)
41
38
  rspec-core (~> 3.9.0)
42
39
  rspec-expectations (~> 3.9.0)
@@ -50,27 +47,26 @@ GEM
50
47
  diff-lcs (>= 1.2.0, < 2.0)
51
48
  rspec-support (~> 3.9.0)
52
49
  rspec-support (3.9.3)
53
- rubocop (0.85.1)
50
+ rubocop (1.36.0)
51
+ json (~> 2.3)
54
52
  parallel (~> 1.10)
55
- parser (>= 2.7.0.1)
53
+ parser (>= 3.1.2.1)
56
54
  rainbow (>= 2.2.2, < 4.0)
57
- regexp_parser (>= 1.7)
58
- rexml
59
- rubocop-ast (>= 0.0.3)
55
+ regexp_parser (>= 1.8, < 3.0)
56
+ rexml (>= 3.2.5, < 4.0)
57
+ rubocop-ast (>= 1.20.1, < 2.0)
60
58
  ruby-progressbar (~> 1.7)
61
- unicode-display_width (>= 1.4.0, < 2.0)
62
- rubocop-ast (0.3.0)
63
- parser (>= 2.7.1.4)
64
- rubocop-performance (1.7.1)
65
- rubocop (>= 0.82.0)
66
- rubocop-rspec (1.41.0)
67
- rubocop (>= 0.68.1)
68
- ruby-progressbar (1.10.1)
59
+ unicode-display_width (>= 1.4.0, < 3.0)
60
+ rubocop-ast (1.21.0)
61
+ parser (>= 3.1.1.0)
62
+ rubocop-performance (1.14.3)
63
+ rubocop (>= 1.7.0, < 2.0)
64
+ rubocop-ast (>= 0.4.0)
65
+ rubocop-rspec (2.12.1)
66
+ rubocop (~> 1.31)
67
+ ruby-progressbar (1.11.0)
69
68
  safe_yaml (1.0.5)
70
- systemu (2.6.5)
71
- unicode-display_width (1.7.0)
72
- uuid (2.3.9)
73
- macaddr (~> 1.0)
69
+ unicode-display_width (2.2.0)
74
70
  webmock (3.8.3)
75
71
  addressable (>= 2.3.6)
76
72
  crack (>= 0.3.2)
@@ -88,7 +84,6 @@ DEPENDENCIES
88
84
  rubocop
89
85
  rubocop-performance
90
86
  rubocop-rspec
91
- uuid
92
87
  webmock
93
88
 
94
89
  BUNDLED WITH
data/Makefile CHANGED
@@ -1,3 +1,6 @@
1
+ .PHONY: help test
2
+ API_KEY ?= $(shell bash -c 'read -p "ReadMe API Key: " api_key; echo $$api_key')
3
+
1
4
  install: ## Install all dependencies
2
5
  bundle
3
6
 
@@ -5,10 +8,13 @@ lint: ## Run code standard checks
5
8
  bundle exec rubocop
6
9
 
7
10
  lint-fix: ## Attempt to automatically fix any code standard violations
8
- bundle exec rubocop --auto-correct
11
+ bundle exec rubocop --autocorrect
12
+
13
+ serve-metrics-rails: ## Start the local Express server to test Metrics
14
+ README_API_KEY=$(API_KEY) ./examples/metrics-rails/bin/rails server
9
15
 
10
16
  test: ## Run unit tests
11
17
  rake spec
12
18
 
13
- help: ## Show this help
19
+ help: ## Display this help screen
14
20
  @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  <p align="center">
12
12
  <a href="https://rubygems.org/gems/readme-metrics"><img src="https://img.shields.io/gem/v/readme-metrics.svg?style=for-the-badge" alt="Latest release"></a>
13
- <a href="https://github.com/readmeio/metrics-sdks"><img src="https://img.shields.io/github/workflow/status/readmeio/metrics-sdks/ruby.svg?style=for-the-badge" alt="Build status"></a>
13
+ <a href="https://github.com/readmeio/metrics-sdks"><img src="https://img.shields.io/github/actions/workflow/status/readmeio/metrics-sdks/ruby.yml?branch=main&style=for-the-badge" alt="Build status"></a>
14
14
  </p>
15
15
 
16
16
  With [ReadMe's Metrics API](https://readme.com/metrics) your team can get deep insights into your API's usage. If you're a developer, it takes a few small steps to send your API logs to [ReadMe](http://readme.com). Here's an overview of how the integration works:
@@ -0,0 +1,7 @@
1
+ # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2
+
3
+ # Mark the database schema as having been generated.
4
+ db/schema.rb linguist-generated
5
+
6
+ # Mark any vendored files as having been vendored.
7
+ vendor/* linguist-vendored
@@ -0,0 +1,20 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-*
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*
16
+ /tmp/*
17
+
18
+
19
+ # Ignore master key for decrypting credentials and more.
20
+ /config/master.key
@@ -0,0 +1 @@
1
+ ruby-3.1.2
@@ -0,0 +1,29 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
5
+ gem 'rails', '~> 7.0.3', '>= 7.0.3.1'
6
+
7
+ # Use sqlite3 as the database for Active Record
8
+ gem 'sqlite3', '~> 1.4'
9
+
10
+ # Use the Puma web server [https://github.com/puma/puma]
11
+ gem 'puma', '~> 5.0'
12
+
13
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
14
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
15
+
16
+ # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
17
+ # gem "rack-cors"
18
+
19
+ group :development, :test do
20
+ # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
21
+ gem 'debug', platforms: %i[mri mingw x64_mingw]
22
+ end
23
+
24
+ group :development do
25
+ # Speed up commands on slow machines / big apps [https://github.com/rails/spring]
26
+ # gem "spring"
27
+ end
28
+
29
+ gem 'readme-metrics', path: '../../'
@@ -0,0 +1,184 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ readme-metrics (2.2.0)
5
+ httparty (~> 0.18)
6
+ rack (>= 2.2, < 4)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.0.3.1)
12
+ actionpack (= 7.0.3.1)
13
+ activesupport (= 7.0.3.1)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.3.1)
17
+ actionpack (= 7.0.3.1)
18
+ activejob (= 7.0.3.1)
19
+ activerecord (= 7.0.3.1)
20
+ activestorage (= 7.0.3.1)
21
+ activesupport (= 7.0.3.1)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.3.1)
27
+ actionpack (= 7.0.3.1)
28
+ actionview (= 7.0.3.1)
29
+ activejob (= 7.0.3.1)
30
+ activesupport (= 7.0.3.1)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (7.0.3.1)
37
+ actionview (= 7.0.3.1)
38
+ activesupport (= 7.0.3.1)
39
+ rack (~> 2.0, >= 2.2.0)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (7.0.3.1)
44
+ actionpack (= 7.0.3.1)
45
+ activerecord (= 7.0.3.1)
46
+ activestorage (= 7.0.3.1)
47
+ activesupport (= 7.0.3.1)
48
+ globalid (>= 0.6.0)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (7.0.3.1)
51
+ activesupport (= 7.0.3.1)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (7.0.3.1)
57
+ activesupport (= 7.0.3.1)
58
+ globalid (>= 0.3.6)
59
+ activemodel (7.0.3.1)
60
+ activesupport (= 7.0.3.1)
61
+ activerecord (7.0.3.1)
62
+ activemodel (= 7.0.3.1)
63
+ activesupport (= 7.0.3.1)
64
+ activestorage (7.0.3.1)
65
+ actionpack (= 7.0.3.1)
66
+ activejob (= 7.0.3.1)
67
+ activerecord (= 7.0.3.1)
68
+ activesupport (= 7.0.3.1)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (7.0.3.1)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
76
+ builder (3.2.4)
77
+ concurrent-ruby (1.1.10)
78
+ crass (1.0.6)
79
+ debug (1.6.2)
80
+ irb (>= 1.3.6)
81
+ reline (>= 0.3.1)
82
+ digest (3.1.0)
83
+ erubi (1.11.0)
84
+ globalid (1.0.0)
85
+ activesupport (>= 5.0)
86
+ httparty (0.21.0)
87
+ mini_mime (>= 1.0.0)
88
+ multi_xml (>= 0.5.2)
89
+ i18n (1.12.0)
90
+ concurrent-ruby (~> 1.0)
91
+ io-console (0.5.11)
92
+ irb (1.4.1)
93
+ reline (>= 0.3.0)
94
+ loofah (2.18.0)
95
+ crass (~> 1.0.2)
96
+ nokogiri (>= 1.5.9)
97
+ mail (2.7.1)
98
+ mini_mime (>= 0.1.1)
99
+ marcel (1.0.2)
100
+ method_source (1.0.0)
101
+ mini_mime (1.1.2)
102
+ mini_portile2 (2.8.0)
103
+ minitest (5.16.3)
104
+ multi_xml (0.6.0)
105
+ net-imap (0.2.3)
106
+ digest
107
+ net-protocol
108
+ strscan
109
+ net-pop (0.1.1)
110
+ digest
111
+ net-protocol
112
+ timeout
113
+ net-protocol (0.1.3)
114
+ timeout
115
+ net-smtp (0.3.1)
116
+ digest
117
+ net-protocol
118
+ timeout
119
+ nio4r (2.5.8)
120
+ nokogiri (1.13.9)
121
+ mini_portile2 (~> 2.8.0)
122
+ racc (~> 1.4)
123
+ puma (5.6.5)
124
+ nio4r (~> 2.0)
125
+ racc (1.6.0)
126
+ rack (2.2.4)
127
+ rack-test (2.0.2)
128
+ rack (>= 1.3)
129
+ rails (7.0.3.1)
130
+ actioncable (= 7.0.3.1)
131
+ actionmailbox (= 7.0.3.1)
132
+ actionmailer (= 7.0.3.1)
133
+ actionpack (= 7.0.3.1)
134
+ actiontext (= 7.0.3.1)
135
+ actionview (= 7.0.3.1)
136
+ activejob (= 7.0.3.1)
137
+ activemodel (= 7.0.3.1)
138
+ activerecord (= 7.0.3.1)
139
+ activestorage (= 7.0.3.1)
140
+ activesupport (= 7.0.3.1)
141
+ bundler (>= 1.15.0)
142
+ railties (= 7.0.3.1)
143
+ rails-dom-testing (2.0.3)
144
+ activesupport (>= 4.2.0)
145
+ nokogiri (>= 1.6)
146
+ rails-html-sanitizer (1.4.3)
147
+ loofah (~> 2.3)
148
+ railties (7.0.3.1)
149
+ actionpack (= 7.0.3.1)
150
+ activesupport (= 7.0.3.1)
151
+ method_source
152
+ rake (>= 12.2)
153
+ thor (~> 1.0)
154
+ zeitwerk (~> 2.5)
155
+ rake (13.0.6)
156
+ reline (0.3.2)
157
+ io-console (~> 0.5)
158
+ sqlite3 (1.6.1)
159
+ mini_portile2 (~> 2.8.0)
160
+ sqlite3 (1.6.1-arm64-darwin)
161
+ strscan (3.0.6)
162
+ thor (1.2.1)
163
+ timeout (0.3.0)
164
+ tzinfo (2.0.5)
165
+ concurrent-ruby (~> 1.0)
166
+ websocket-driver (0.7.5)
167
+ websocket-extensions (>= 0.1.0)
168
+ websocket-extensions (0.1.5)
169
+ zeitwerk (2.6.0)
170
+
171
+ PLATFORMS
172
+ arm64-darwin-21
173
+ ruby
174
+
175
+ DEPENDENCIES
176
+ debug
177
+ puma (~> 5.0)
178
+ rails (~> 7.0.3, >= 7.0.3.1)
179
+ readme-metrics!
180
+ sqlite3 (~> 1.4)
181
+ tzinfo-data
182
+
183
+ BUNDLED WITH
184
+ 2.3.11
@@ -0,0 +1,38 @@
1
+ # ReadMe Metrics/Webhooks Rails Demo
2
+
3
+ ```sh
4
+ make install
5
+ ```
6
+
7
+ ## 📊 Metrics
8
+
9
+ ```sh
10
+ make serve-metrics-rails
11
+ ```
12
+
13
+ Access your test server to demo Metrics by making a cURL request:
14
+
15
+ ```sh
16
+ curl http://localhost:8000
17
+ ```
18
+
19
+ ## 📞 Webhooks
20
+
21
+ ```sh
22
+ make serve-metrics-rails
23
+ ```
24
+
25
+ We have to generate a valid HMAC to send through to the webhook, you can do that with the following shell commands:
26
+
27
+ ```sh
28
+ README_API_KEY=<Your ReadMe API Key here>
29
+ TIME=$(date +%s000)
30
+ UNSIGNED=$TIME.{\"email\":\"test@example.com\"}
31
+ HMAC=$(echo -n $UNSIGNED | openssl dgst -sha256 -hmac $README_API_KEY -hex)
32
+ SIGNATURE="t=$TIME,v0=$HMAC"
33
+
34
+ curl http://localhost:8000/webhook \
35
+ -H "readme-signature: $SIGNATURE" \
36
+ -H "content-type: application/json" \
37
+ -d '{"email":"test@example.com"}'
38
+ ```
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::API
2
+ end
@@ -0,0 +1,34 @@
1
+ require 'readme/webhook'
2
+
3
+ class MetricsController < ApplicationController
4
+ def index
5
+ render json: { message: 'hello world' }
6
+ end
7
+
8
+ def post
9
+ head :ok
10
+ end
11
+
12
+ def webhook
13
+ # Your ReadMe secret
14
+ secret = ENV.fetch('README_API_KEY', nil)
15
+ # Verify the request is legitimate and came from ReadMe
16
+ signature = request.headers['readme-signature']
17
+
18
+ begin
19
+ Readme::Webhook.verify(request.raw_post, signature, secret)
20
+ rescue Readme::MissingSignatureError, Readme::ExpiredSignatureError, Readme::InvalidSignatureError => e
21
+ # Handle invalid requests
22
+ render json: { error: e.message }, status: 401
23
+ return
24
+ end
25
+
26
+ # Fetch the user from the database and return their data for use with OpenAPI variables.
27
+ # current_user ||= User.find(session[:user_id]) if session[:user_id]
28
+ render json: {
29
+ # OAS Security variables
30
+ petstore_auth: 'default-key',
31
+ basic_auth: { user: 'user', pass: 'pass' }
32
+ }
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ primary_abstract_class
3
+ end
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'rubygems'
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV.fetch('BUNDLER_VERSION', nil)
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
27
+
28
+ bundler_version = nil
29
+ update_index = nil
30
+ ARGV.each_with_index do |a, i|
31
+ bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
32
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/o
33
+
34
+ bundler_version = Regexp.last_match(1)
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV.fetch('BUNDLE_GEMFILE', nil)
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path('../Gemfile', __dir__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+
59
+ lockfile_contents = File.read(lockfile)
60
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/o
61
+
62
+ Regexp.last_match(1)
63
+ end
64
+
65
+ def bundler_requirement
66
+ @bundler_requirement ||=
67
+ env_var_version || cli_arg_version ||
68
+ bundler_requirement_for(lockfile_version)
69
+ end
70
+
71
+ def bundler_requirement_for(version)
72
+ return "#{Gem::Requirement.default}.a" unless version
73
+
74
+ bundler_gem_version = Gem::Version.new(version)
75
+
76
+ requirement = bundler_gem_version.approximate_recommendation
77
+
78
+ return requirement unless Gem.rubygems_version < Gem::Version.new('2.7.0')
79
+
80
+ requirement += '.a' if bundler_gem_version.prerelease?
81
+
82
+ requirement
83
+ end
84
+
85
+ def load_bundler!
86
+ ENV['BUNDLE_GEMFILE'] ||= gemfile
87
+
88
+ activate_bundler
89
+ end
90
+
91
+ def activate_bundler
92
+ gem_error = activation_error_handling do
93
+ gem 'bundler', bundler_requirement
94
+ end
95
+ return if gem_error.nil?
96
+
97
+ require_error = activation_error_handling do
98
+ require 'bundler/version'
99
+ end
100
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
101
+
102
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
103
+ exit 42
104
+ end
105
+
106
+ def activation_error_handling
107
+ yield
108
+ nil
109
+ rescue StandardError, LoadError => e
110
+ e
111
+ end
112
+ end
113
+
114
+ m.load_bundler!
115
+
116
+ load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = File.expand_path('..', __dir__)
6
+
7
+ def system!(*args)
8
+ system(*args) || abort("\n== Command #{args} failed ==")
9
+ end
10
+
11
+ FileUtils.chdir APP_ROOT do
12
+ # This script is a way to set up or update your development environment automatically.
13
+ # This script is idempotent, so that you can run it at any time and get an expectable outcome.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # puts "\n== Copying sample files =="
21
+ # unless File.exist?("config/database.yml")
22
+ # FileUtils.cp "config/database.yml.sample", "config/database.yml"
23
+ # end
24
+
25
+ puts "\n== Preparing database =="
26
+ system! 'bin/rails db:prepare'
27
+
28
+ puts "\n== Removing old logs and tempfiles =="
29
+ system! 'bin/rails log:clear tmp:clear'
30
+
31
+ puts "\n== Restarting application server =="
32
+ system! 'bin/rails restart'
33
+ end