icalia-sdk-event-notification 0.3.5 → 0.3.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/.DS_Store +0 -0
- data/lib/{icalia-sdk-event-notification → icalia/event}/publisher.rb +0 -0
- data/lib/{icalia-sdk-event-notification → icalia/event}/subscriber.rb +35 -10
- data/lib/{icalia-sdk-event-notification → icalia/event}/topic_message_processing.rb +0 -0
- data/lib/icalia-sdk-event-notification/version.rb +2 -2
- data/lib/icalia-sdk-event-notification.rb +5 -8
- metadata +24 -24
- data/lib/icalia-sdk-event-notification/notification.rb +0 -75
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 25f360199220ebfebf4f8972db5b954b1044ec14e111ba9b7cad966eaa03d6fe
         | 
| 4 | 
            +
              data.tar.gz: 267b0b982f36eb46077e9d2386a89db633e986f53c9d8f9f8d160608d6a71a4e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a818ce3ec588833fde85132789b32b89972e95bda13178a8c9f389d028ca598244083ac8677a6d95b75992696304dc0ee5531fe21bf37f93ffa6bb4161523904
         | 
| 7 | 
            +
              data.tar.gz: a023c7c6125a18c89280e208c8e4608290b98dcc5c3c171fd1e5371f891ceac2bc87525887f0d7012a264798bb67ff7d2989d37b6f6440341220cd66b8f27bca
         | 
    
        data/lib/.DS_Store
    ADDED
    
    | Binary file | 
| 
            File without changes
         | 
| @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'icalia-sdk- | 
| 3 | 
            +
            require 'icalia-sdk-core'
         | 
| 4 4 |  | 
| 5 5 | 
             
            module Icalia::Event
         | 
| 6 6 | 
             
              module Subscriber
         | 
| @@ -18,7 +18,7 @@ module Icalia::Event | |
| 18 18 |  | 
| 19 19 | 
             
                def perform(message)
         | 
| 20 20 | 
             
                  raw_data = MessagePack.unpack(message.data)
         | 
| 21 | 
            -
                  event = Icalia:: | 
| 21 | 
            +
                  event = Icalia::Deserializer.new(raw_data).perform
         | 
| 22 22 | 
             
                  event_class_name = event.class.name.demodulize
         | 
| 23 23 |  | 
| 24 24 | 
             
                  if (processor_class = processor_map[event_class_name])
         | 
| @@ -37,25 +37,50 @@ 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 parent_name_deprecated?
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    rails_app_name_until_rails_six
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  def parent_name_deprecated?
         | 
| 74 | 
            +
                    Rails::VERSION::MAJOR >= 6
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                  def rails_app_name_until_rails_six
         | 
| 78 | 
            +
                    Rails.application.class.parent_name
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  def rails_app_name_since_rails_six
         | 
| 82 | 
            +
                    Rails.application.class.module_parent_name
         | 
| 83 | 
            +
                  end
         | 
| 59 84 | 
             
                end
         | 
| 60 85 | 
             
              end
         | 
| 61 86 | 
             
            end
         | 
| 
            File without changes
         | 
| @@ -1,19 +1,16 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'icalia-sdk- | 
| 3 | 
            +
            require 'icalia-sdk-core'
         | 
| 4 | 
            +
            require 'icalia-sdk-event-notification/version'
         | 
| 4 5 |  | 
| 5 6 | 
             
            require 'active_support'
         | 
| 6 7 | 
             
            require 'active_support/core_ext/object/blank'
         | 
| 7 8 |  | 
| 8 9 | 
             
            module Icalia
         | 
| 9 10 | 
             
              module Event
         | 
| 10 | 
            -
                autoload : | 
| 11 | 
            -
                autoload : | 
| 12 | 
            -
                autoload : | 
| 13 | 
            -
                autoload :Notification, 'icalia-sdk-event-notification/notification'
         | 
| 14 | 
            -
                
         | 
| 15 | 
            -
                autoload :TopicMessageProcessing,
         | 
| 16 | 
            -
                         'icalia-sdk-event-notification/topic_message_processing'
         | 
| 11 | 
            +
                autoload :Publisher, 'icalia/event/publisher'
         | 
| 12 | 
            +
                autoload :Subscriber, 'icalia/event/subscriber'
         | 
| 13 | 
            +
                autoload :TopicMessageProcessing, 'icalia/event/topic_message_processing'
         | 
| 17 14 |  | 
| 18 15 | 
             
                mattr_reader :deferred_publishing, default: true
         | 
| 19 16 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,71 +1,71 @@ | |
| 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.9
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Roberto Quintanilla
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2022-02-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            -
              name: icalia-sdk- | 
| 14 | 
            +
              name: icalia-sdk-core
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - '='
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: 0.3. | 
| 19 | 
            +
                    version: 0.3.9
         | 
| 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.9
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: activesupport
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - ">="
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: 5.2 | 
| 33 | 
            +
                    version: '5.2'
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 38 | 
             
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: 5.2 | 
| 40 | 
            +
                    version: '5.2'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            -
              name:  | 
| 42 | 
            +
              name: google-cloud-pubsub
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 | 
            -
                - - " | 
| 45 | 
            +
                - - ">="
         | 
| 46 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: ' | 
| 47 | 
            +
                    version: '0'
         | 
| 48 48 | 
             
              type: :runtime
         | 
| 49 49 | 
             
              prerelease: false
         | 
| 50 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 | 
            -
                - - " | 
| 52 | 
            +
                - - ">="
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: ' | 
| 54 | 
            +
                    version: '0'
         | 
| 55 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            -
              name:  | 
| 56 | 
            +
              name: msgpack
         | 
| 57 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 58 | 
             
                requirements:
         | 
| 59 59 | 
             
                - - "~>"
         | 
| 60 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            -
                    version: ' | 
| 61 | 
            +
                    version: '1.3'
         | 
| 62 62 | 
             
              type: :runtime
         | 
| 63 63 | 
             
              prerelease: false
         | 
| 64 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 65 | 
             
                requirements:
         | 
| 66 66 | 
             
                - - "~>"
         | 
| 67 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            -
                    version: ' | 
| 68 | 
            +
                    version: '1.3'
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: bundler
         | 
| 71 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -86,14 +86,14 @@ dependencies: | |
| 86 86 | 
             
                requirements:
         | 
| 87 87 | 
             
                - - "~>"
         | 
| 88 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version: ' | 
| 89 | 
            +
                    version: '13.0'
         | 
| 90 90 | 
             
              type: :development
         | 
| 91 91 | 
             
              prerelease: false
         | 
| 92 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 93 | 
             
                requirements:
         | 
| 94 94 | 
             
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version: ' | 
| 96 | 
            +
                    version: '13.0'
         | 
| 97 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 98 | 
             
              name: rspec
         | 
| 99 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -108,20 +108,20 @@ dependencies: | |
| 108 108 | 
             
                - - "~>"
         | 
| 109 109 | 
             
                  - !ruby/object:Gem::Version
         | 
| 110 110 | 
             
                    version: '3.0'
         | 
| 111 | 
            -
            description: Official Ruby gem for Icalia  | 
| 112 | 
            -
              This gem is part of the Icalia SDK for Ruby.
         | 
| 111 | 
            +
            description: Official Ruby gem for Icalia Event Notification via Google Cloud Pub/Sub
         | 
| 112 | 
            +
              Service. This gem is part of the Icalia SDK for Ruby.
         | 
| 113 113 | 
             
            email:
         | 
| 114 114 | 
             
            - vov@icalialabs.com
         | 
| 115 115 | 
             
            executables: []
         | 
| 116 116 | 
             
            extensions: []
         | 
| 117 117 | 
             
            extra_rdoc_files: []
         | 
| 118 118 | 
             
            files:
         | 
| 119 | 
            +
            - lib/.DS_Store
         | 
| 119 120 | 
             
            - lib/icalia-sdk-event-notification.rb
         | 
| 120 | 
            -
            - lib/icalia-sdk-event-notification/notification.rb
         | 
| 121 | 
            -
            - lib/icalia-sdk-event-notification/publisher.rb
         | 
| 122 | 
            -
            - lib/icalia-sdk-event-notification/subscriber.rb
         | 
| 123 | 
            -
            - lib/icalia-sdk-event-notification/topic_message_processing.rb
         | 
| 124 121 | 
             
            - lib/icalia-sdk-event-notification/version.rb
         | 
| 122 | 
            +
            - lib/icalia/event/publisher.rb
         | 
| 123 | 
            +
            - lib/icalia/event/subscriber.rb
         | 
| 124 | 
            +
            - lib/icalia/event/topic_message_processing.rb
         | 
| 125 125 | 
             
            homepage: https://github.com/IcaliaLabs/icalia-sdk-ruby
         | 
| 126 126 | 
             
            licenses:
         | 
| 127 127 | 
             
            - MIT
         | 
| @@ -148,5 +148,5 @@ requirements: [] | |
| 148 148 | 
             
            rubygems_version: 3.0.3
         | 
| 149 149 | 
             
            signing_key: 
         | 
| 150 150 | 
             
            specification_version: 4
         | 
| 151 | 
            -
            summary: Icalia SDK  | 
| 151 | 
            +
            summary: Icalia SDK Event Notification for Ruby
         | 
| 152 152 | 
             
            test_files: []
         | 
| @@ -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
         |