herdst_servicecall 0.1.8 → 0.1.9

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: d8b9041db86e040a3357712f358d302d572e3b2f2968c52f2ddd91784c3843a0
4
- data.tar.gz: 876226434fc37cba0fcff8ac8d6bc6b1616d9e99b1897fc6567bb524c58469d5
3
+ metadata.gz: 86923a697f8a6c3832d2e31d5481511fa1f7d87928ff45810a24d664113af7a6
4
+ data.tar.gz: 20e0e710899c921d1eb4bf81688159dd53e1667bca962fc5b64d848faeafc148
5
5
  SHA512:
6
- metadata.gz: ef86bddc9c3e086e94279e3af4a3db32105dd0a41290dfdd235f565ac9a72873b03de63eec2acd3ed909cacc946e29cf50479fb8da8f5060352b4e6f8b17632f
7
- data.tar.gz: aa2589d4ad015d9032f6160bb4873305cf60f0751028ef67c45526d49856745674bfe5e588631c00e0ef0a0cfca70660f032fb7d12661165d31cda2e2ab20c32
6
+ metadata.gz: 62f013f01eadfe00cc4f2d2326a52f66e9543148d4913b7eb867f688f5d9d8efd01b4e79e197aa6025a726d249969503e70b0faf0c1b8ac87acd8da428a19ab3
7
+ data.tar.gz: 7b0ccd697407d36b4f8727369e7b97048cea300e43aba871b5a134d61c5fe825f242a51eb297a814d626e7b55124994e4d1c440fae02dfe7079d5c6edeb35044
@@ -2,6 +2,7 @@
2
2
  HerdstServicecall.setup do |config|
3
3
 
4
4
  config.jwt_secret "secret"
5
+ config.context = lambda { { :context => "value" } }
5
6
 
6
7
  config.register_service :service_one, "http://localhost:3000"
7
8
  config.register_service :service_two, "http://localhost:3001"
@@ -20,8 +20,9 @@ module HerdstServicecall
20
20
  raise "No service endpoint!" unless service_endpoint
21
21
 
22
22
  call_endpoint = service_endpoint + @config.event_path + "?" + { :token => get_token }.to_query
23
+ context = @config.get_context
23
24
 
24
- response = send_request!(call_endpoint, Request.new(event_name, data))
25
+ response = send_request!(call_endpoint, Request.new(event_name, data, context))
25
26
 
26
27
  Response.parse(response)
27
28
  end
@@ -9,6 +9,7 @@ module HerdstServicecall
9
9
  @config[:event_path] = "/servicecall/event"
10
10
  @config[:jwt_secret] = nil
11
11
  @config[:jwt_algorithm] = "HS256"
12
+ @config[:context] = nil
12
13
  end
13
14
 
14
15
 
@@ -22,6 +23,13 @@ module HerdstServicecall
22
23
  end
23
24
 
24
25
 
26
+ def get_context
27
+ @config[:context].respond_to?(:call) ?
28
+ @config[:context].call :
29
+ @config[:context]
30
+ end
31
+
32
+
25
33
  def on(event_name, action)
26
34
  @config[:events][event_name.to_sym] = action
27
35
  end
@@ -11,7 +11,7 @@ module HerdstServicecall
11
11
 
12
12
 
13
13
  def receive(token, data)
14
- request = Request.new(nil, nil)
14
+ request = Request.new(nil, nil, nil)
15
15
 
16
16
  begin
17
17
  verify_token!(token)
@@ -23,7 +23,7 @@ module HerdstServicecall
23
23
  raise ResponderError.new(request.event, "Invalid event") unless action
24
24
 
25
25
  action_class_name, action_name = action.split("#")
26
- action_class = "#{action_class_name.classify}ServiceEvent".constantize.new(request.event, request.body)
26
+ action_class = "#{action_class_name.classify}ServiceEvent".constantize.new(request.event, request.body, request.context)
27
27
  response = action_class.send(action_name, request.body)
28
28
 
29
29
  Response.new(request.event, 200, response)
@@ -2,21 +2,21 @@ module HerdstServicecall
2
2
  class Request
3
3
 
4
4
 
5
- attr_accessor :event, :body
5
+ attr_accessor :event, :body, :context
6
6
 
7
7
 
8
- def initialize(event, body)
8
+ def initialize(event, body, context)
9
9
  self.event = event
10
- self.body = body ?
11
- (body.respond_to?(:with_indifferent_access) ? body.with_indifferent_access : body) :
12
- nil
10
+ self.body = self.make_indifferent(body)
11
+ self.context = self.make_indifferent(context)
13
12
  end
14
13
 
15
14
 
16
15
  def to_json
17
16
  {
18
17
  :event => self.event,
19
- :data => self.body
18
+ :data => self.body,
19
+ :context => self.context
20
20
  }.to_json
21
21
  end
22
22
 
@@ -27,11 +27,17 @@ module HerdstServicecall
27
27
  raise "Invalid body" unless body
28
28
 
29
29
  self.event = body["event"]
30
- self.body = body["data"].respond_to?(:with_indifferent_access) ?
31
- body["data"].with_indifferent_access :
32
- body["data"]
30
+ self.body = self.make_indifferent(body["data"])
31
+ self.context = self.make_indifferent(body["context"])
33
32
  end
34
33
 
34
+
35
+ private
36
+ def make_indifferent(data)
37
+ return (data.respond_to?(:with_indifferent_access) ? data.with_indifferent_access : data) if data
38
+ return nil
39
+ end
40
+
35
41
 
36
42
  end
37
43
  end
@@ -2,9 +2,10 @@ module HerdstServicecall
2
2
  class Responder
3
3
 
4
4
 
5
- def initialize(event, data)
5
+ def initialize(event, data, context)
6
6
  @event = event
7
7
  @data = data
8
+ @context = context
8
9
  end
9
10
 
10
11
 
@@ -1,3 +1,3 @@
1
1
  module HerdstServicecall
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herdst_servicecall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herd.St
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-05 00:00:00.000000000 Z
11
+ date: 2021-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails