Sha256: 54eed3cdaa66dd5aaf757b620035fea64f5b375ad3fef5f28a834ff6250ae2b5

Contents?: true

Size: 973 Bytes

Versions: 3

Compression:

Stored size: 973 Bytes

Contents

module Nuntius
  class Envelope
    include Enumerable
    attr_accessor :data, :key, :signature

    def initialize(attributes)
      self.data      = attributes[:raw_data]      ? encode(attributes[:raw_data])      : attributes[:data]
      self.key       = attributes[:raw_key]       ? encode(attributes[:raw_key])       : attributes[:key]
      self.signature = attributes[:raw_signature] ? encode(attributes[:raw_signature]) : attributes[:signature]
    end

    def to_hash
      {
        :data => data,
        :key => key,
        :signature => signature
      }
    end

    def raw_data
      decode data
    end

    def raw_key
      decode key
    end

    def raw_signature
      decode signature
    end

    def each(&block)
      self.to_hash.each(&block)
    end

    protected
      def encode(string)
        Encodings::URLSafeBase64.encode(string)
      end

      def decode(string)
        Encodings::URLSafeBase64.decode(string)
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nuntius-0.1.2 lib/nuntius/envelope.rb
nuntius-0.1.1 lib/nuntius/envelope.rb
nuntius-0.1.0 lib/nuntius/envelope.rb