Sha256: 1ecae7e2472898a88214abea197cf5ad656e9966beef0e03670886d3b3d93270

Contents?: true

Size: 880 Bytes

Versions: 7

Compression:

Stored size: 880 Bytes

Contents

module Bitmovin::Webhooks
  class WebhookEncryption
    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_encryption.rb
bitmovin-ruby-0.9.0 lib/bitmovin/webhooks/webhook_encryption.rb
bitmovin-ruby-0.8.1 lib/bitmovin/webhooks/webhook_encryption.rb
bitmovin-ruby-0.8.0 lib/bitmovin/webhooks/webhook_encryption.rb
bitmovin-ruby-0.7.0 lib/bitmovin/webhooks/webhook_encryption.rb
bitmovin-ruby-0.5.0 lib/bitmovin/webhooks/webhook_encryption.rb
bitmovin-ruby-0.4.0 lib/bitmovin/webhooks/webhook_encryption.rb