Sha256: 20af235ab6660b9377ded1b173b87d8b0dd20a92ee816dc1784eeae273f99774

Contents?: true

Size: 1022 Bytes

Versions: 10

Compression:

Stored size: 1022 Bytes

Contents

require 'forwardable'

require 'macaroons/raw_macaroon'

module Macaroons
  class Macaroon
    extend Forwardable

    def initialize(key: nil, identifier: nil, location: nil, raw_macaroon: nil)
      @raw_macaroon = raw_macaroon || RawMacaroon.new(key: key, identifier: identifier, location: location)
    end

    def_delegators :@raw_macaroon, :identifier, :location, :signature, :caveats,
      :serialize, :serialize_json, :add_first_party_caveat, :add_third_party_caveat, :prepare_for_request

    def self.from_binary(serialized)
      raw_macaroon = RawMacaroon.from_binary(serialized: serialized)
      macaroon = Macaroons::Macaroon.new(raw_macaroon: raw_macaroon)
    end

    def self.from_json(serialized)
      raw_macaroon = RawMacaroon.from_json(serialized: serialized)
      macaroon = Macaroons::Macaroon.new(raw_macaroon: raw_macaroon)
    end

    def first_party_caveats
      caveats.select(&:first_party?)
    end

    def third_party_caveats
      caveats.select(&:third_party?)
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
macaroons-1.0.0 lib/macaroons/macaroons.rb
macaroons-0.7.1 lib/macaroons/macaroons.rb
macaroons-0.7.0 lib/macaroons/macaroons.rb
macaroons-0.6.3 lib/macaroons/macaroons.rb
macaroons-0.6.2 lib/macaroons/macaroons.rb
macaroons-0.6.1 lib/macaroons/macaroons.rb
macaroons-0.6.0 lib/macaroons/macaroons.rb
macaroons-0.5.3 lib/macaroons/macaroons.rb
macaroons-0.5.2 lib/macaroons/macaroons.rb
macaroons-0.5.1 lib/macaroons/macaroons.rb