Sha256: eff23f6aa15e78c9871aa0cea7feecaba025ca507bab05b233a1d2c241144002

Contents?: true

Size: 879 Bytes

Versions: 7

Compression:

Stored size: 879 Bytes

Contents

module Bitmovin::Webhooks
  class WebhookSignature
    def initialize(hash = {})
      @errors = []
      hash.each do |name, value|
        instance_variable_set("@#{ActiveSupport::Inflector.underscore(name)}", value)
      end
    end

    attr_accessor :type, :key

    def valid?
      validate!
      @errors.empty?
    end

    def invalid?
      !valid?
    end

    def errors
      @errors
    end

    def to_json(args)
      collect_attributes.to_json(args)
    end

    private

    def collect_attributes
      val = Hash.new
      [:type, :key].each do |name|
        json_name = ActiveSupport::Inflector.camelize(name.to_s, false)
        val[json_name] = instance_variable_get("@#{name}")
      end
      val
    end

    def validate!
      @errors << "type cannot be blank" if @type.blank?
      @errors << "key cannot be blank" if @key.blank?
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bitmovin-ruby-0.9.1 lib/bitmovin/webhooks/webhook_signature.rb
bitmovin-ruby-0.9.0 lib/bitmovin/webhooks/webhook_signature.rb
bitmovin-ruby-0.8.1 lib/bitmovin/webhooks/webhook_signature.rb
bitmovin-ruby-0.8.0 lib/bitmovin/webhooks/webhook_signature.rb
bitmovin-ruby-0.7.0 lib/bitmovin/webhooks/webhook_signature.rb
bitmovin-ruby-0.5.0 lib/bitmovin/webhooks/webhook_signature.rb
bitmovin-ruby-0.4.0 lib/bitmovin/webhooks/webhook_signature.rb