close_encounters 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -3
- data/README.md +9 -0
- data/Rakefile +13 -2
- data/app/assets/config/close_encounters_manifest.js +1 -0
- data/app/assets/javascripts/encounters.js +22 -0
- data/app/assets/stylesheets/close_encounters/application.css +15 -0
- data/app/models/close_encounters/participant_event.rb +5 -2
- data/app/models/close_encounters/participant_service.rb +7 -2
- data/app/views/layouts/close_encounters/application.html.erb +15 -0
- data/config/importmap.rb +1 -0
- data/lib/close_encounters/engine.rb +24 -0
- data/lib/close_encounters/version.rb +1 -1
- data/lib/close_encounters.rb +3 -3
- data/lib/tasks/close_encounters.rake +12 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d25208cd9077c5ee5664ca4751be09d336af8655ea251f36724075da31fc5b88
|
4
|
+
data.tar.gz: 2589b53abede0624c4fb55a48bb7cd5e954940d6f984cd0c5971906cbfe79a24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de2552af2d64096df4613627a64b92d07178217366b9af8c5730562c8059142308b5dfeced444c889ac66a789b152bfebecd19c1c6038e06fa879a9baacae904
|
7
|
+
data.tar.gz: 588ba90d0f89e0c1a8bafbadadb7a5da6398b728fa0a3db1e044a982f3ea2fe19743f718028241a6dbac012966c4b0effd541936a0b1346ec849311a57f05ab5
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,26 @@
|
|
1
1
|
# Change log
|
2
|
+
|
2
3
|
All notable changes to this project will be documented in this file.
|
3
4
|
|
4
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
6
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
7
|
|
7
|
-
##
|
8
|
-
|
9
|
-
|
8
|
+
## [0.1.1] - 2024-07-11
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Support for Importmaps
|
13
|
+
- `reissue` gem for managing releases
|
14
|
+
|
15
|
+
### Fixed
|
16
|
+
|
17
|
+
- Alter newest scope to properly return a relation limited to 1 record
|
18
|
+
- Update ensure_service to not overwrite existing connection_info
|
19
|
+
- Allow specs to run properly locally
|
20
|
+
- Incorrect manifest paths for sprockets
|
21
|
+
|
22
|
+
## [0.1.0] - 2024-05-08
|
23
|
+
|
24
|
+
### Added
|
25
|
+
|
26
|
+
- Initial implimentation
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# CloseEncounters
|
2
|
+
|
3
|
+
… of the Third Party.
|
4
|
+
|
2
5
|
Add serices and events that can track responses from third-party services.
|
3
6
|
|
4
7
|
## Usage
|
@@ -24,6 +27,12 @@ CloseEncounters.status("SomeThirdPartyService") # => 200
|
|
24
27
|
CloseEncounters.status("SomeThirdPartyService") # => 500
|
25
28
|
```
|
26
29
|
|
30
|
+
### TODO
|
31
|
+
|
32
|
+
- [ ] Add JS to the gem to track events on the front-end.
|
33
|
+
- [ ] Add a UI to create and manage services.
|
34
|
+
- [ ] Add a UI to view events.
|
35
|
+
|
27
36
|
## Installation
|
28
37
|
Add this line to your application's Gemfile:
|
29
38
|
|
data/Rakefile
CHANGED
@@ -9,9 +9,20 @@ require "bundler/gem_tasks"
|
|
9
9
|
|
10
10
|
require "rake/testtask"
|
11
11
|
|
12
|
-
Rake::TestTask.new do |t|
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
13
|
t.libs << "test"
|
14
14
|
t.pattern = "test/**/*_test.rb"
|
15
15
|
end
|
16
16
|
|
17
|
-
task default: ["db:
|
17
|
+
task default: ["db:drop", "db:create", "db:schema:load", "db:test:prepare", :test]
|
18
|
+
|
19
|
+
require "reissue/gem"
|
20
|
+
|
21
|
+
Reissue::Task.create :reissue do |task|
|
22
|
+
task.version_file = "lib/close_encounters/version.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
require "standard/rake"
|
26
|
+
|
27
|
+
require "close_encounters/engine"
|
28
|
+
load "lib/tasks/close_encounters.rake"
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link_tree ../javascripts
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Controller } from 'stimulus';
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
static targets = ['output'];
|
5
|
+
|
6
|
+
connect() {
|
7
|
+
this.poll();
|
8
|
+
}
|
9
|
+
|
10
|
+
poll() {
|
11
|
+
setInterval(() => {
|
12
|
+
fetch('/close_encounters')
|
13
|
+
.then(response => response.json())
|
14
|
+
.then(data => {
|
15
|
+
this.outputTarget.textContent = data;
|
16
|
+
})
|
17
|
+
.catch(error => {
|
18
|
+
console.error('Error:', error);
|
19
|
+
});
|
20
|
+
}, 30000); // Poll every 30 seconds
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module CloseEncounters
|
2
2
|
class ParticipantEvent < ApplicationRecord
|
3
|
-
belongs_to :participant_service,
|
3
|
+
belongs_to :participant_service,
|
4
|
+
inverse_of: :events,
|
5
|
+
class_name: "CloseEncounters::ParticipantService",
|
6
|
+
foreign_key: "close_encounters_participant_service_id"
|
4
7
|
|
5
|
-
scope :newest, -> { order(created_at: :desc).
|
8
|
+
scope :newest, -> { order(created_at: :desc).limit(1) }
|
6
9
|
end
|
7
10
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module CloseEncounters
|
2
2
|
class ParticipantService < ApplicationRecord
|
3
|
-
has_many :events,
|
3
|
+
has_many :events,
|
4
|
+
inverse_of: :participant_service,
|
5
|
+
class_name: "CloseEncounters::ParticipantEvent"
|
4
6
|
|
5
7
|
validates :name, presence: true
|
6
8
|
|
@@ -8,6 +10,9 @@ module CloseEncounters
|
|
8
10
|
serialize :connection_info, coder: JSON
|
9
11
|
end
|
10
12
|
|
11
|
-
|
13
|
+
# ONLY encrypt if you have the necessary keys
|
14
|
+
if Rails.application.credentials.close_encounters_encryption_key.present?
|
15
|
+
encrypts :connection_info
|
16
|
+
end
|
12
17
|
end
|
13
18
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Close encounters</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
|
8
|
+
<%= stylesheet_link_tag "close_encounters/application", media: "all" %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%= yield %>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
data/config/importmap.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pin_all_from File.expand_path("../app/assets/javascripts", __dir__)
|
@@ -1,5 +1,29 @@
|
|
1
1
|
module CloseEncounters
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
isolate_namespace CloseEncounters
|
4
|
+
|
5
|
+
config.generators do |g|
|
6
|
+
g.test_framework :minitest, spec: true
|
7
|
+
end
|
8
|
+
|
9
|
+
if defined?(Importmap)
|
10
|
+
initializer "close_encounters.importmap", before: "importmap" do |app|
|
11
|
+
app.config.importmap.paths << root.join("config/importmap.rb")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined?(Sprockets)
|
16
|
+
initializer "close_encounters.assets" do |app|
|
17
|
+
app.config.assets.precompile += %w[close_encounters_manifest.js]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
initializer :append_migrations do |app|
|
22
|
+
unless app.root.to_s.match root.to_s
|
23
|
+
config.paths["db/migrate"].expanded.each do |expanded_path|
|
24
|
+
app.config.paths["db/migrate"] << expanded_path
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
4
28
|
end
|
5
29
|
end
|
data/lib/close_encounters.rb
CHANGED
@@ -14,7 +14,7 @@ module CloseEncounters
|
|
14
14
|
# @param response [String] the response object
|
15
15
|
def contact(name, status:, response:)
|
16
16
|
service = ParticipantService.find_by!(name:)
|
17
|
-
unless service.events.newest.status == status
|
17
|
+
unless service.events.newest.pick(:status) == status
|
18
18
|
service.events.create!(status: status, response:)
|
19
19
|
end
|
20
20
|
end
|
@@ -24,7 +24,7 @@ module CloseEncounters
|
|
24
24
|
# @param name [String] the name of the service
|
25
25
|
# @return [Integer] the HTTP status of the most recent contact
|
26
26
|
def status(name)
|
27
|
-
ParticipantService.find_by!(name: name).events.newest.status
|
27
|
+
ParticipantService.find_by!(name: name).events.newest.pick(:status)
|
28
28
|
end
|
29
29
|
|
30
30
|
# Ensure that a participant service exists
|
@@ -33,7 +33,7 @@ module CloseEncounters
|
|
33
33
|
# @param connection_info [Hash] the connection information for the service
|
34
34
|
def ensure_service(name, connection_info: {})
|
35
35
|
ParticipantService.find_or_create_by!(name: name) do |service|
|
36
|
-
service.connection_info = connection_info
|
36
|
+
service.connection_info = connection_info unless service.connection_info.present?
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :close_encounters do
|
2
|
+
namespace :db do
|
3
|
+
desc "Run migrations for CloseEncounters"
|
4
|
+
task migrate: :environment do
|
5
|
+
ActiveRecord::Migration.migrate(File.expand_path("../../db/migrate", __dir__))
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
Rake::Task["db:migrate"].enhance do
|
11
|
+
Rake::Task["close_encounters:db:migrate"].invoke
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: close_encounters
|
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
|
- Jim Gay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -106,15 +106,21 @@ files:
|
|
106
106
|
- MIT-LICENSE
|
107
107
|
- README.md
|
108
108
|
- Rakefile
|
109
|
+
- app/assets/config/close_encounters_manifest.js
|
110
|
+
- app/assets/javascripts/encounters.js
|
111
|
+
- app/assets/stylesheets/close_encounters/application.css
|
109
112
|
- app/models/close_encounters/application_record.rb
|
110
113
|
- app/models/close_encounters/participant_event.rb
|
111
114
|
- app/models/close_encounters/participant_service.rb
|
115
|
+
- app/views/layouts/close_encounters/application.html.erb
|
116
|
+
- config/importmap.rb
|
112
117
|
- db/migrate/20240430173723_create_close_encounters_participant_services.rb
|
113
118
|
- db/migrate/20240430173725_create_close_encounters_participant_events.rb
|
114
119
|
- db/migrate/20240508190642_add_close_ecounters_indexes.rb
|
115
120
|
- lib/close_encounters.rb
|
116
121
|
- lib/close_encounters/engine.rb
|
117
122
|
- lib/close_encounters/version.rb
|
123
|
+
- lib/tasks/close_encounters.rake
|
118
124
|
homepage: https://github.com/SOFware/close_encounters
|
119
125
|
licenses:
|
120
126
|
- MIT
|