icalia-sdk-event-notification 0.3.6 → 0.3.7
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:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3e583e484d0a970df2edc56f33704aebe466cecd93fa6ef6dcaeeb5b4d7c6f08
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e80864146a628dff860b33c16a09fb706a4ea790a98b600512ad1ff62c5cdfde
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 94b811d44aa4791850f9e8579dfe52709414b985cc39a32f45c4e4b7ce6ae16c29a7c1055ce0e08688a660c6da6218b53cc2ec99abc320bfe9a9949cad55a80c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 55d0b60702888eac4cf3d534372e95d98811c7c596e38956e5eb1b3b0039c79cb74dd1f9f3fc56dca3304877d7b5a6f121e11f153663b18ddc98a36031ac991c
         
     | 
| 
         @@ -10,7 +10,6 @@ module Icalia 
     | 
|
| 
       10 
10 
     | 
    
         
             
              module Event
         
     | 
| 
       11 
11 
     | 
    
         
             
                autoload :Publisher, 'icalia/event/publisher'
         
     | 
| 
       12 
12 
     | 
    
         
             
                autoload :Subscriber, 'icalia/event/subscriber'
         
     | 
| 
       13 
     | 
    
         
            -
                autoload :Notification, 'icalia/event/notification'
         
     | 
| 
       14 
13 
     | 
    
         
             
                autoload :TopicMessageProcessing, 'icalia/event/topic_message_processing'
         
     | 
| 
       15 
14 
     | 
    
         | 
| 
       16 
15 
     | 
    
         
             
                mattr_reader :deferred_publishing, default: true
         
     | 
| 
         @@ -37,25 +37,46 @@ module Icalia::Event 
     | 
|
| 
       37 
37 
     | 
    
         
             
                  end
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                  def subscription_name
         
     | 
| 
       40 
     | 
    
         
            -
                     
     | 
| 
       41 
     | 
    
         
            -
                    '-' +
         
     | 
| 
       42 
     | 
    
         
            -
                    ENV.fetch('DEPLOYMENT_NAME', Rails.env).downcase +
         
     | 
| 
       43 
     | 
    
         
            -
                    "-#{topic_name}"
         
     | 
| 
      
 40 
     | 
    
         
            +
                    "#{subscription_name_prefix}-#{topic_name}"
         
     | 
| 
       44 
41 
     | 
    
         
             
                  end
         
     | 
| 
       45 
42 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                  def  
     | 
| 
      
 43 
     | 
    
         
            +
                  def auto_subscribe
         
     | 
| 
       47 
44 
     | 
    
         
             
                    client = Subserver::Pubsub.client
         
     | 
| 
       48 
45 
     | 
    
         
             
                    topic = client.topic(topic_name) || client.create_topic(topic_name)
         
     | 
| 
       49 
46 
     | 
    
         | 
| 
       50 
47 
     | 
    
         
             
                    topic.subscription(subscription_name) ||
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
                      topic.subscribe(subscription_name)
         
     | 
| 
       52 
49 
     | 
    
         
             
                  end
         
     | 
| 
       53 
50 
     | 
    
         | 
| 
       54 
51 
     | 
    
         
             
                  def process(event_class_name, options = {})
         
     | 
| 
       55 
     | 
    
         
            -
                    processor = options.delete 
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
                    return unless (processor = options.delete(:with)).present?
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
       57 
54 
     | 
    
         
             
                    processor_map[event_class_name] = processor
         
     | 
| 
       58 
55 
     | 
    
         
             
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                  protected
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                  def subscription_name_prefix
         
     | 
| 
      
 60 
     | 
    
         
            +
                    "#{rails_app_name.underscore}-#{deployment_name.underscore}"
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  def deployment_name
         
     | 
| 
      
 64 
     | 
    
         
            +
                    ENV.fetch('DEPLOYMENT_NAME', Rails.env)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  def rails_app_name
         
     | 
| 
      
 68 
     | 
    
         
            +
                    return rails_app_name_since_rails_six if Rails.version.starts_with?('6')
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                    rails_app_name_until_rails_six
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  def rails_app_name_until_rails_six
         
     | 
| 
      
 74 
     | 
    
         
            +
                    Rails.application.class.parent_name
         
     | 
| 
      
 75 
     | 
    
         
            +
                  end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                  def rails_app_name_since_rails_six
         
     | 
| 
      
 78 
     | 
    
         
            +
                    Rails.application.class.module_parent_name
         
     | 
| 
      
 79 
     | 
    
         
            +
                  end
         
     | 
| 
       59 
80 
     | 
    
         
             
                end
         
     | 
| 
       60 
81 
     | 
    
         
             
              end
         
     | 
| 
       61 
82 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: icalia-sdk-event-notification
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.7
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Roberto Quintanilla
         
     | 
| 
         @@ -16,14 +16,14 @@ dependencies: 
     | 
|
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
17 
     | 
    
         
             
                - - '='
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
     | 
    
         
            -
                    version: 0.3. 
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 0.3.7
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
24 
     | 
    
         
             
                - - '='
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
     | 
    
         
            -
                    version: 0.3. 
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 0.3.7
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
28 
     | 
    
         
             
              name: activesupport
         
     | 
| 
       29 
29 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -116,10 +116,8 @@ executables: [] 
     | 
|
| 
       116 
116 
     | 
    
         
             
            extensions: []
         
     | 
| 
       117 
117 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       118 
118 
     | 
    
         
             
            files:
         
     | 
| 
       119 
     | 
    
         
            -
            - lib/.DS_Store
         
     | 
| 
       120 
119 
     | 
    
         
             
            - lib/icalia-sdk-event-notification.rb
         
     | 
| 
       121 
120 
     | 
    
         
             
            - lib/icalia-sdk-event-notification/version.rb
         
     | 
| 
       122 
     | 
    
         
            -
            - lib/icalia/event/notification.rb
         
     | 
| 
       123 
121 
     | 
    
         
             
            - lib/icalia/event/publisher.rb
         
     | 
| 
       124 
122 
     | 
    
         
             
            - lib/icalia/event/subscriber.rb
         
     | 
| 
       125 
123 
     | 
    
         
             
            - lib/icalia/event/topic_message_processing.rb
         
     | 
    
        data/lib/.DS_Store
    DELETED
    
    | 
         Binary file 
     | 
| 
         @@ -1,75 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Icalia::Event
         
     | 
| 
       4 
     | 
    
         
            -
              #= Icalia::Event::Notification
         
     | 
| 
       5 
     | 
    
         
            -
              class Notification
         
     | 
| 
       6 
     | 
    
         
            -
                attr_reader :data,
         
     | 
| 
       7 
     | 
    
         
            -
                            :topic,
         
     | 
| 
       8 
     | 
    
         
            -
                            :event_data,
         
     | 
| 
       9 
     | 
    
         
            -
                            :included_data,
         
     | 
| 
       10 
     | 
    
         
            -
                            :metadata
         
     | 
| 
       11 
     | 
    
         
            -
                
         
     | 
| 
       12 
     | 
    
         
            -
                def initialize(raw_notification)
         
     | 
| 
       13 
     | 
    
         
            -
                  @data = parse_raw_notification raw_notification
         
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                def topic_arn; data.fetch :topic_arn; end
         
     | 
| 
       17 
     | 
    
         
            -
                def topic;     @topic ||= topic_arn.split(':')[5..-1].join(':'); end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                def metadata;  @metadata ||= data.dig :message, :meta; end
         
     | 
| 
       20 
     | 
    
         
            -
                def emitter;   metadata.dig :emitter; end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                def message;   data.fetch :message; end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                def event_data; @event_data ||= deserialize_data(message.fetch(:data)); end
         
     | 
| 
       25 
     | 
    
         
            -
                def action; event_data.fetch(:action, 'message'); end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                def included_data
         
     | 
| 
       28 
     | 
    
         
            -
                  @included_data ||= message
         
     | 
| 
       29 
     | 
    
         
            -
                  .fetch(:included)
         
     | 
| 
       30 
     | 
    
         
            -
                  .each_with_object({}) do |data, included|
         
     | 
| 
       31 
     | 
    
         
            -
                    included[data.slice(:id, :type)] = deserialize_data(data)
         
     | 
| 
       32 
     | 
    
         
            -
                  end
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                def fetch_data(property_name)
         
     | 
| 
       36 
     | 
    
         
            -
                  fetched_property = fetch_attribute property_name
         
     | 
| 
       37 
     | 
    
         
            -
                  return fetched_property if fetched_property.present?
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  fetch_relationship property_name
         
     | 
| 
       40 
     | 
    
         
            -
                end
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                delegate :parse_raw_notification, :deserialize_data, to: :class
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                class << self
         
     | 
| 
       45 
     | 
    
         
            -
                  delegate :decode, to: ActiveSupport::JSON, prefix: :json
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                  def parse_raw_notification(raw_notification)
         
     | 
| 
       48 
     | 
    
         
            -
                    json_decode(raw_notification)
         
     | 
| 
       49 
     | 
    
         
            -
                      .transform_keys(&:underscore)
         
     | 
| 
       50 
     | 
    
         
            -
                      .tap { |parsed| parsed['message'] = json_decode parsed['message'] }
         
     | 
| 
       51 
     | 
    
         
            -
                      .with_indifferent_access
         
     | 
| 
       52 
     | 
    
         
            -
                  end
         
     | 
| 
       53 
     | 
    
         
            -
              
         
     | 
| 
       54 
     | 
    
         
            -
                  def deserialize_data(data)
         
     | 
| 
       55 
     | 
    
         
            -
                    klass = data.fetch(:type).underscore.classify
         
     | 
| 
       56 
     | 
    
         
            -
                    deserializer = "Icalia::Event::Deserializable#{klass}".constantize
         
     | 
| 
       57 
     | 
    
         
            -
                    deserializer.call(data).with_indifferent_access
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
       59 
     | 
    
         
            -
                end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                private
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                def fetch_attribute(attribute_name)
         
     | 
| 
       64 
     | 
    
         
            -
                  message.dig(:data, :attributes, attribute_name) ||
         
     | 
| 
       65 
     | 
    
         
            -
                  message.dig(:data, :attributes, attribute_name.to_s.dasherize)
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                def fetch_relationship(relationship_name)
         
     | 
| 
       69 
     | 
    
         
            -
                  rel = message.dig(:data, :relationships, relationship_name) ||
         
     | 
| 
       70 
     | 
    
         
            -
                        message.dig(:data, :relationships, relationship_name.to_s.dasherize)
         
     | 
| 
       71 
     | 
    
         
            -
                  return unless rel.present?
         
     | 
| 
       72 
     | 
    
         
            -
                  included_data[rel.fetch(:data)]
         
     | 
| 
       73 
     | 
    
         
            -
                end
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
     | 
    
         
            -
            end
         
     |