qodex-rails 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +9 -0
- data/lib/qodex/rails/version.rb +1 -1
- data/lib/qodex-rails/configuration.rb +10 -0
- data/lib/qodex-rails/middleware.rb +55 -12
- data/lib/qodex-rails/version.rb +1 -1
- data/lib/qodex-rails.rb +15 -0
- data/qodex-rails-0.1.0.gem +0 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cc9a5ccd335641d6c77c77ec917e86f4546b9ad6b17111b5a3ea52bc79faa3c
|
4
|
+
data.tar.gz: b5bc6ee69f2d251c98cc72c22957d01f0f58437909b47f031e91d1b31dd44de6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17ebca6fdc4e5349277352f388181e6e5a75164c3acaa43a52db8c3f39ae257e1b3a1f48459eaf0e89aa507b050c49b7a1f563e157a63f8375355dee65f4afee
|
7
|
+
data.tar.gz: 9e2e6bd01d2d2eb2be4073aac3403154edf8a8ca68db91ab06bf5c84405aa589c927885572f4dfbe18d846e1081e6ba3c688766c48bc8dbf1bdd1dbec592fc72
|
data/README.md
CHANGED
@@ -14,6 +14,15 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
14
14
|
|
15
15
|
$ gem install qodex-rails
|
16
16
|
|
17
|
+
## Configuration
|
18
|
+
# config/initializers/qodex_rails.rb
|
19
|
+
|
20
|
+
QodexRails.configure do |config|
|
21
|
+
config.collection_name = 'Your_Collection_Name' # Name of the collection where logs will be stored
|
22
|
+
config.api_key = 'Your_API_Key' # API key for authentication
|
23
|
+
end
|
24
|
+
|
25
|
+
|
17
26
|
## Usage
|
18
27
|
|
19
28
|
TODO: Write usage instructions here
|
data/lib/qodex/rails/version.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
1
4
|
module QodexRails
|
2
5
|
module Middleware
|
3
6
|
class RequestLogger
|
@@ -8,24 +11,64 @@ module QodexRails
|
|
8
11
|
|
9
12
|
def call(env)
|
10
13
|
start_time = Time.now
|
14
|
+
|
15
|
+
# Capture the request details
|
16
|
+
request = Rack::Request.new(env)
|
17
|
+
request_body = request.body.read
|
18
|
+
request.body.rewind
|
19
|
+
|
11
20
|
status, headers, response = @app.call(env)
|
21
|
+
|
12
22
|
end_time = Time.now
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
# Capture the response details
|
25
|
+
response_body = extract_body(response)
|
26
|
+
|
27
|
+
# Construct the logs
|
28
|
+
logs = {
|
29
|
+
collection_name: QodexRails.configuration.collection_name,
|
30
|
+
api_key: QodexRails.configuration.api_key,
|
31
|
+
apis: [{
|
32
|
+
body: response_body,
|
33
|
+
body_type: response.content_type,
|
34
|
+
request_type: request.request_method,
|
35
|
+
timestamp: Time.now.to_i,
|
36
|
+
url: request.url,
|
37
|
+
status: status,
|
38
|
+
headers: extract_headers(headers),
|
39
|
+
params: request.filtered_parameters # Using Rails' parameter filtering
|
40
|
+
}]
|
41
|
+
}
|
42
|
+
|
43
|
+
# Send the logs to the external API
|
44
|
+
send_to_api(logs)
|
26
45
|
|
27
46
|
[status, headers, response]
|
28
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def extract_body(response)
|
52
|
+
body = ""
|
53
|
+
response.each { |part| body << part }
|
54
|
+
body
|
55
|
+
end
|
56
|
+
|
57
|
+
def extract_headers(headers)
|
58
|
+
headers.map { |name, value| { name: name, value: value } }
|
59
|
+
end
|
60
|
+
|
61
|
+
def send_to_api(logs)
|
62
|
+
uri = URI("#{ENV['API_URL']}/api/v1/collections/create_with_folder/#{ENV['API_KEY']}")
|
63
|
+
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
64
|
+
request.body = JSON.generate(logs)
|
65
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
66
|
+
http.request(request)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Optionally log the response from the external API
|
70
|
+
Rails.logger.info "API Response: #{response.body}" if response
|
71
|
+
end
|
29
72
|
end
|
30
73
|
end
|
31
74
|
end
|
data/lib/qodex-rails/version.rb
CHANGED
data/lib/qodex-rails.rb
CHANGED
@@ -1,9 +1,24 @@
|
|
1
1
|
require "qodex-rails/version"
|
2
2
|
require "qodex-rails/middleware"
|
3
|
+
require "qodex-rails/configuration" # Require the new configuration file
|
3
4
|
|
4
5
|
module QodexRails
|
5
6
|
class Error < StandardError; end
|
6
7
|
|
8
|
+
class << self
|
9
|
+
attr_writer :configuration
|
10
|
+
|
11
|
+
# Get or initialize the configuration
|
12
|
+
def configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# Allow block-style configuration
|
17
|
+
def configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
7
22
|
class Railtie < Rails::Railtie
|
8
23
|
initializer "qodex-rails.insert_middleware" do |app|
|
9
24
|
app.config.middleware.use Middleware::RequestLogger
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qodex-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sid
|
@@ -25,10 +25,12 @@ files:
|
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- lib/qodex-rails.rb
|
28
|
+
- lib/qodex-rails/configuration.rb
|
28
29
|
- lib/qodex-rails/middleware.rb
|
29
30
|
- lib/qodex-rails/version.rb
|
30
31
|
- lib/qodex/rails.rb
|
31
32
|
- lib/qodex/rails/version.rb
|
33
|
+
- qodex-rails-0.1.0.gem
|
32
34
|
- sig/qodex/rails.rbs
|
33
35
|
homepage: https://qodex.ai
|
34
36
|
licenses:
|