qodex-rails 0.1.0 → 0.1.2
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 +64 -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
- data/qodex-rails-0.1.1.gem +0 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d080fca50aa62a0fd87df635167b95cc00c08daf13c66ece7967b623bd40d4f
|
4
|
+
data.tar.gz: bc4bbe33dad3f8cabb516452d7f15953db58fb60419dc66cfe3ece4b6e2298c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ddfeddfa0c02ee396284a0d606a70120266b9483734d69b06fb9f771152b02e29697b9799cb2586f8c48f43491ebe3f4f41b5def8a0bcc04dbeacdc09716d02
|
7
|
+
data.tar.gz: '09ef8c37d89a0ec3fb07759e79320dff24d415ff0659502502b5c515ce6fb468e0d140787cf307a8659f5d797c9f025f5c48b700da11e03e0bec44b2f5eaee64'
|
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
|
@@ -7,25 +10,74 @@ module QodexRails
|
|
7
10
|
end
|
8
11
|
|
9
12
|
def call(env)
|
13
|
+
# Exit early if collection_name or api_key are not configured
|
14
|
+
unless QodexRails.configuration.collection_name && QodexRails.configuration.api_key
|
15
|
+
Rails.logger.warn "QodexRails: collection_name or api_key not configured. Skipping middleware."
|
16
|
+
return @app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Print the initializer keys to the output
|
20
|
+
Rails.logger.info "QodexRails Initializer Keys: Collection Name: #{QodexRails.configuration.collection_name}, API Key: #{QodexRails.configuration.api_key}"
|
21
|
+
|
10
22
|
start_time = Time.now
|
23
|
+
|
24
|
+
# Capture the request details
|
25
|
+
request = Rack::Request.new(env)
|
26
|
+
request_body = request.body.read
|
27
|
+
request.body.rewind
|
28
|
+
|
11
29
|
status, headers, response = @app.call(env)
|
30
|
+
|
12
31
|
end_time = Time.now
|
13
32
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
33
|
+
# Capture the response details
|
34
|
+
response_body = extract_body(response)
|
35
|
+
|
36
|
+
# Construct the logs
|
37
|
+
logs = {
|
38
|
+
collection_name: QodexRails.configuration.collection_name,
|
39
|
+
api_key: QodexRails.configuration.api_key,
|
40
|
+
apis: [{
|
41
|
+
body: response_body,
|
42
|
+
body_type: response.content_type,
|
43
|
+
request_type: request.request_method,
|
44
|
+
timestamp: Time.now.to_i,
|
45
|
+
url: request.url,
|
46
|
+
status: status,
|
47
|
+
headers: extract_headers(headers),
|
48
|
+
params: request.filtered_parameters # Using Rails' parameter filtering
|
49
|
+
}]
|
50
|
+
}
|
51
|
+
|
52
|
+
# Send the logs to the external API
|
53
|
+
send_to_api(logs)
|
26
54
|
|
27
55
|
[status, headers, response]
|
28
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def extract_body(response)
|
61
|
+
body = ""
|
62
|
+
response.each { |part| body << part }
|
63
|
+
body
|
64
|
+
end
|
65
|
+
|
66
|
+
def extract_headers(headers)
|
67
|
+
headers.map { |name, value| { name: name, value: value } }
|
68
|
+
end
|
69
|
+
|
70
|
+
def send_to_api(logs)
|
71
|
+
uri = URI("https://api.app.qodex.ai/api/v1/collections/create_with_folder/#{QodexRails.configuration.api_key}")
|
72
|
+
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
73
|
+
request.body = JSON.generate(logs)
|
74
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
75
|
+
http.request(request)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Optionally log the response from the external API
|
79
|
+
Rails.logger.info "URI: #{uri}, API Response: #{response.body}" if response
|
80
|
+
end
|
29
81
|
end
|
30
82
|
end
|
31
83
|
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
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sid
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Intercept your rails application to power Qodex.ai AI copilot.
|
14
14
|
email:
|
@@ -25,10 +25,13 @@ 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
|
34
|
+
- qodex-rails-0.1.1.gem
|
32
35
|
- sig/qodex/rails.rbs
|
33
36
|
homepage: https://qodex.ai
|
34
37
|
licenses:
|