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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e39456566803fe054a0c711c098ccef2dc9ee642821512f6184c4e62d5b4dc4
4
- data.tar.gz: e001a920651ceab1b284078e46ea96fa563acd64c7a4468ac0abb2b45e0030b7
3
+ metadata.gz: a35c124322fb4164c6ad19fc6617a4bfdfa6f176c41653e6570aabd0bf38854d
4
+ data.tar.gz: 9f76b8c375ca124460a38f4ca33eb21630034bd615e45ae2d7a66d51338c2e71
5
5
  SHA512:
6
- metadata.gz: d3882bc0e9e5598f5e4a5b1539e3c9f3c19a4708d0d2fb8de2f3619525b72f2caba615a1a1fb5ab6760802502b6917842f76c916f9984a1f35d553146266e548
7
- data.tar.gz: 874879ad560ee6bf383b345452e3c6ef449cbe6c1c04ed1907db4b14ec9b1b391cc10724395f4c18f5af16b90c5776ce3f02eb3e9fe1e7e2ae72cb81f1f5f04c
6
+ metadata.gz: '097f076dc927a87e0938f2f6d53b302bc86aff677211b39a849623989adadf4edae244ef1bcb3eb275e6a70288544d27c930fc1fd80cb1f0b3e42e488bc234c0'
7
+ data.tar.gz: 85e86b6f85a1bfa12a33ce22d1d92a3921e72d25e046a960ecd00018fe66d30a2eedea4c83fb97fceda4ec610fef12a3dc353a777cb284fbc3ca1cd5bfa96bb8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- party_bus (0.1.14)
4
+ party_bus (0.2.0)
5
5
  activerecord (>= 6.0, <= 8.0)
6
6
  after_do (~> 0.4.0)
7
7
  httparty (~> 0.20.0)
@@ -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 :api_key, required: true, :desc => "required"
6
+ argument :connection_id, required: true, :desc => "required"
7
+ argument :secret, required: true, :desc => "required"
6
8
 
7
- desc "Configures the bugsnag notifier with your API key"
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.api_key = #{api_key.inspect}
15
+ config.connection_id = #{connection_id.inspect}
16
+ config.secret = #{secret.inspect}
14
17
  end
15
18
  EOF
16
19
  end
@@ -1,18 +1,17 @@
1
1
  module PartyBus
2
2
  class Client
3
3
  def self.post(
4
- entity_id: PartyBus.configuration.entity_id,
4
+ body:,
5
5
  path:,
6
- body:
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: 10,
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
- 'Authorization': authorization,
39
- 'Content-Type': 'application/json'
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 :entity_id
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.entity_id = nil
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
- entity_id: PartyBus.configuration.entity_id,
5
+ connection_id:,
6
6
  payload:,
7
- resource_type:,
8
7
  resource_action:,
9
- source_id: PartyBus.configuration.source_id
8
+ resource_type:,
9
+ timestamp: Time.now
10
10
  )
11
- new(entity_id, resource_type, resource_action, payload, source_id).perform
11
+ new(connection_id, payload, resource_type, resource_action, timestamp).perform
12
12
  end
13
13
 
14
- def initialize(entity_id, resource_type, resource_action, payload, source_id)
15
- @entity_id = entity_id
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
- @source_id = source_id
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
- source_id: @source_id
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
- entity_id: pb_entity_id,
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
@@ -1,3 +1,3 @@
1
1
  module PartyBus
2
- VERSION = "0.1.16"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.16
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-20 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: after_do