lib/macaroons/macaroons.rb in macaroons-0.4.1 vs lib/macaroons/macaroons.rb in macaroons-0.5.1
- old
+ new
@@ -1,63 +1,35 @@
+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 identifier
- @raw_macaroon.identifier
- end
+ def_delegators :@raw_macaroon, :identifier, :location, :signature, :caveats,
+ :serialize, :serialize_json, :add_first_party_caveat, :add_third_party_caveat, :prepare_for_request
- def location
- @raw_macaroon.location
- end
-
- def signature
- @raw_macaroon.signature
- end
-
- def caveats
- @raw_macaroon.caveats
- end
-
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 serialize
- @raw_macaroon.serialize()
- end
-
- def serialize_json
- @raw_macaroon.serialize_json()
- end
-
- def add_first_party_caveat(predicate)
- @raw_macaroon.add_first_party_caveat(predicate)
- end
-
def first_party_caveats
caveats.select(&:first_party?)
end
- def add_third_party_caveat(caveat_key, caveat_id, caveat_location)
- @raw_macaroon.add_third_party_caveat(caveat_key, caveat_id, caveat_location)
- end
-
def third_party_caveats
caveats.select(&:third_party?)
end
- def prepare_for_request(macaroon)
- @raw_macaroon.prepare_for_request(macaroon)
- end
end
end