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 +4 -4
 - data/lib/generators/templates/herdst_servicecall.rb +1 -0
 - data/lib/herdst_servicecall/caller.rb +2 -1
 - data/lib/herdst_servicecall/configurator.rb +8 -0
 - data/lib/herdst_servicecall/receiver.rb +2 -2
 - data/lib/herdst_servicecall/request.rb +15 -9
 - data/lib/herdst_servicecall/responder.rb +2 -1
 - data/lib/herdst_servicecall/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: 86923a697f8a6c3832d2e31d5481511fa1f7d87928ff45810a24d664113af7a6
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 20e0e710899c921d1eb4bf81688159dd53e1667bca962fc5b64d848faeafc148
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 62f013f01eadfe00cc4f2d2326a52f66e9543148d4913b7eb867f688f5d9d8efd01b4e79e197aa6025a726d249969503e70b0faf0c1b8ac87acd8da428a19ab3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 7b0ccd697407d36b4f8727369e7b97048cea300e43aba871b5a134d61c5fe825f242a51eb297a814d626e7b55124994e4d1c440fae02dfe7079d5c6edeb35044
         
     | 
| 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
       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"] 
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       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
         
     | 
    
        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. 
     | 
| 
      
 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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-10-04 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     |