party_bus 0.1.16 → 0.2.0
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/Gemfile.lock +1 -1
- data/lib/generators/party_bus/party_bus_generator.rb +6 -3
- data/lib/party_bus/client.rb +14 -12
- data/lib/party_bus/configuration.rb +4 -6
- data/lib/party_bus/events/create.rb +11 -12
- data/lib/party_bus/models/concerns/publishable.rb +12 -15
- data/lib/party_bus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a35c124322fb4164c6ad19fc6617a4bfdfa6f176c41653e6570aabd0bf38854d
|
4
|
+
data.tar.gz: 9f76b8c375ca124460a38f4ca33eb21630034bd615e45ae2d7a66d51338c2e71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '097f076dc927a87e0938f2f6d53b302bc86aff677211b39a849623989adadf4edae244ef1bcb3eb275e6a70288544d27c930fc1fd80cb1f0b3e42e488bc234c0'
|
7
|
+
data.tar.gz: 85e86b6f85a1bfa12a33ce22d1d92a3921e72d25e046a960ecd00018fe66d30a2eedea4c83fb97fceda4ec610fef12a3dc353a777cb284fbc3ca1cd5bfa96bb8
|
data/Gemfile.lock
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'rails/generators'
|
2
|
+
|
2
3
|
class PartyBusGenerator < Rails::Generators::Base
|
3
4
|
source_root File.expand_path('../templates', __FILE__)
|
4
5
|
|
5
|
-
argument :
|
6
|
+
argument :connection_id, required: true, :desc => "required"
|
7
|
+
argument :secret, required: true, :desc => "required"
|
6
8
|
|
7
|
-
desc "Configures the
|
9
|
+
desc "Configures the party-bus notifier with your application secret"
|
8
10
|
|
9
11
|
def create_initializer_file
|
10
12
|
initializer "party_bus.rb" do
|
11
13
|
<<-EOF
|
12
14
|
PartyBus.configure do |config|
|
13
|
-
config.
|
15
|
+
config.connection_id = #{connection_id.inspect}
|
16
|
+
config.secret = #{secret.inspect}
|
14
17
|
end
|
15
18
|
EOF
|
16
19
|
end
|
data/lib/party_bus/client.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
module PartyBus
|
2
2
|
class Client
|
3
3
|
def self.post(
|
4
|
-
|
4
|
+
body:,
|
5
5
|
path:,
|
6
|
-
|
6
|
+
timestamp: Time.now
|
7
7
|
)
|
8
8
|
return { success: true } unless PartyBus.configuration.enabled
|
9
9
|
|
10
10
|
response = HTTParty.post(
|
11
11
|
"#{PartyBus.configuration.api_url}#{path}",
|
12
12
|
body: body.to_json,
|
13
|
-
default_timeout:
|
14
|
-
headers: headers,
|
15
|
-
query: { entity_id: entity_id }
|
13
|
+
default_timeout: 30,
|
14
|
+
headers: headers(timestamp, body)
|
16
15
|
)
|
17
16
|
|
18
17
|
parse_response(response)
|
@@ -32,16 +31,19 @@ module PartyBus
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
def self.headers
|
34
|
+
def self.headers(timestamp, body)
|
36
35
|
{
|
37
36
|
'Accept': 'application/json',
|
38
|
-
'
|
39
|
-
'
|
37
|
+
'Content-Type': 'application/json',
|
38
|
+
'Party-Signature': {
|
39
|
+
t: timestamp.to_i,
|
40
|
+
v1: OpenSSL::HMAC.hexdigest(
|
41
|
+
"SHA256",
|
42
|
+
PartyBus.configuration.secret,
|
43
|
+
"#{timestamp.to_i}.#{body.to_json}"
|
44
|
+
)
|
45
|
+
}.map { |key| key.join('=') }.join(',')
|
40
46
|
}
|
41
47
|
end
|
42
|
-
|
43
|
-
def self.authorization
|
44
|
-
"Bearer #{PartyBus.configuration.api_key}"
|
45
|
-
end
|
46
48
|
end
|
47
49
|
end
|
@@ -1,18 +1,16 @@
|
|
1
1
|
module PartyBus
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :api_key
|
4
3
|
attr_accessor :api_url
|
4
|
+
attr_accessor :connection_id
|
5
5
|
attr_accessor :enabled
|
6
|
-
attr_accessor :
|
7
|
-
attr_accessor :source_id
|
6
|
+
attr_accessor :secret
|
8
7
|
attr_accessor :stripped_attributes
|
9
8
|
|
10
9
|
def initialize
|
11
|
-
self.api_key = nil
|
12
10
|
self.api_url = "https://party-bus.gigalixirapp.com"
|
11
|
+
self.connection_id = nil
|
13
12
|
self.enabled = ENV['RUBY_ENV'] != 'test' && ENV['RAILS_ENV'] != 'test'
|
14
|
-
self.
|
15
|
-
self.source_id = nil
|
13
|
+
self.secret = nil
|
16
14
|
self.stripped_attributes = []
|
17
15
|
end
|
18
16
|
end
|
@@ -2,35 +2,34 @@ module PartyBus
|
|
2
2
|
module Events
|
3
3
|
class Create
|
4
4
|
def self.perform_using(
|
5
|
-
|
5
|
+
connection_id:,
|
6
6
|
payload:,
|
7
|
-
resource_type:,
|
8
7
|
resource_action:,
|
9
|
-
|
8
|
+
resource_type:,
|
9
|
+
timestamp: Time.now
|
10
10
|
)
|
11
|
-
new(
|
11
|
+
new(connection_id, payload, resource_type, resource_action, timestamp).perform
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(
|
15
|
-
@
|
14
|
+
def initialize(connection_id, payload, resource_type, resource_action, timestamp)
|
15
|
+
@connection_id = connection_id
|
16
16
|
@resource_type = resource_type
|
17
17
|
@resource_action = resource_action
|
18
18
|
@payload = payload
|
19
|
-
@
|
19
|
+
@timestamp = timestamp
|
20
20
|
end
|
21
21
|
|
22
22
|
def perform
|
23
23
|
@response ||= PartyBus::Client.post(
|
24
|
-
entity_id: @entity_id,
|
25
|
-
path: '/api/v1/events',
|
26
24
|
body: {
|
27
25
|
event: {
|
28
26
|
payload: @payload,
|
29
|
-
resource_type: @resource_type,
|
30
27
|
resource_action: @resource_action,
|
31
|
-
|
28
|
+
resource_type: @resource_type
|
32
29
|
}
|
33
|
-
}
|
30
|
+
},
|
31
|
+
path: "/api/v1/connections/#{@connection_id}/events",
|
32
|
+
timestamp: @timestamp
|
34
33
|
)
|
35
34
|
end
|
36
35
|
end
|
@@ -46,6 +46,15 @@ module Publishable
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def pb_serialize(action = nil)
|
49
|
+
{
|
50
|
+
connection_id: pb_connection_id,
|
51
|
+
payload: pb_payload,
|
52
|
+
resource_type: pb_resource_name,
|
53
|
+
resource_action: action,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def pb_payload
|
49
58
|
payload = if self.respond_to?(:attributes)
|
50
59
|
self.attributes
|
51
60
|
else
|
@@ -53,27 +62,15 @@ module Publishable
|
|
53
62
|
end
|
54
63
|
.deep_symbolize_keys
|
55
64
|
.except(*pb_stripped_attributes)
|
65
|
+
end
|
56
66
|
|
57
|
-
|
58
|
-
|
59
|
-
payload: payload,
|
60
|
-
resource_type: pb_resource_name,
|
61
|
-
resource_action: action,
|
62
|
-
source_id: pb_source_id,
|
63
|
-
}
|
67
|
+
def pb_connection_id
|
68
|
+
PartyBus.configuration.connection_id
|
64
69
|
end
|
65
70
|
|
66
71
|
# These attributes are stripped by default
|
67
72
|
def pb_stripped_attributes
|
68
73
|
PartyBus.configuration.stripped_attributes
|
69
74
|
end
|
70
|
-
|
71
|
-
def pb_entity_id
|
72
|
-
PartyBus.configuration.entity_id
|
73
|
-
end
|
74
|
-
|
75
|
-
def pb_source_id
|
76
|
-
PartyBus.configuration.source_id
|
77
|
-
end
|
78
75
|
end
|
79
76
|
end
|
data/lib/party_bus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: party_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- corey jergensen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: after_do
|