Class: Skyfall::Label
- Inherits:
-
Object
- Object
- Skyfall::Label
- Defined in:
- lib/skyfall/label.rb
Overview
A single label emitted from the “subscribeLabels” firehose of a labeller service.
The label assigns some specific value - from a list of available values defined by this labeller - to a specific target (at:// URI or a DID). In general, this will usually be either a “badge” that a user requested to be assigned to themselves from a fun/informative labeller, or some kind of (likely negative) label assigned to a user or post by a moderation labeller.
You generally don’t need to create instances of this class manually, but will receive them from Firehose that’s connected to :subscribe_labels in the Stream#on_message callback handler (wrapped in a Firehose::LabelsMessage).
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The label’s JSON data.
Instance Method Summary collapse
-
#authority ⇒ String
(also: #src)
DID of the labelling authority (the labeller service).
-
#cid ⇒ CID?
CID of the specific version of the subject that this label applies to.
-
#created_at ⇒ Time
(also: #cts)
Timestamp when the label was created.
-
#expires_at ⇒ Time?
(also: #exp)
Optional timestamp when the label expires.
-
#initialize(data) ⇒ Label
constructor
A new instance of Label.
-
#negation? ⇒ Boolean
(also: #neg)
If true, then this is a negation (delete) of an existing label.
-
#subject ⇒ String
(also: #uri)
AT URI or DID of the labelled subject (e.g. a user or post).
-
#value ⇒ String
(also: #val)
Label value.
-
#version ⇒ Integer
(also: #ver)
Label format version number.
Constructor Details
#initialize(data) ⇒ Label
Returns a new instance of Label.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/skyfall/label.rb', line 31 def initialize(data) @data = data raise DecodeError.new("Missing version: #{data}") unless data.has_key?('ver') raise DecodeError.new("Invalid version: #{ver}") unless ver.is_a?(Integer) && ver >= 1 raise UnsupportedError.new("Unsupported version: #{ver}") unless ver == 1 raise DecodeError.new("Missing source: #{data}") unless data.has_key?('src') raise DecodeError.new("Invalid source: #{src}") unless src.is_a?(String) && src.start_with?('did:') raise DecodeError.new("Missing uri: #{data}") unless data.has_key?('uri') raise DecodeError.new("Invalid uri: #{uri}") unless uri.is_a?(String) raise DecodeError.new("Invalid uri: #{uri}") unless uri.start_with?('at://') || uri.start_with?('did:') end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns the label’s JSON data.
24 25 26 |
# File 'lib/skyfall/label.rb', line 24 def data @data end |
Instance Method Details
#authority ⇒ String Also known as: src
DID of the labelling authority (the labeller service).
53 54 55 |
# File 'lib/skyfall/label.rb', line 53 def @data['src'] end |
#cid ⇒ CID?
Returns CID of the specific version of the subject that this label applies to.
64 65 66 |
# File 'lib/skyfall/label.rb', line 64 def cid @cid ||= @data['cid'] && CID.from_json(@data['cid']) end |
#created_at ⇒ Time Also known as: cts
Returns timestamp when the label was created.
79 80 81 |
# File 'lib/skyfall/label.rb', line 79 def created_at @created_at ||= Time.parse(@data['cts']) end |
#expires_at ⇒ Time? Also known as: exp
Returns optional timestamp when the label expires.
84 85 86 |
# File 'lib/skyfall/label.rb', line 84 def expires_at @expires_at ||= @data['exp'] && Time.parse(@data['exp']) end |
#negation? ⇒ Boolean Also known as: neg
Returns if true, then this is a negation (delete) of an existing label.
74 75 76 |
# File 'lib/skyfall/label.rb', line 74 def negation? !!@data['neg'] end |
#subject ⇒ String Also known as: uri
AT URI or DID of the labelled subject (e.g. a user or post).
59 60 61 |
# File 'lib/skyfall/label.rb', line 59 def subject @data['uri'] end |
#value ⇒ String Also known as: val
Returns label value.
69 70 71 |
# File 'lib/skyfall/label.rb', line 69 def value @data['val'] end |
#version ⇒ Integer Also known as: ver
Returns label format version number.
47 48 49 |
# File 'lib/skyfall/label.rb', line 47 def version @data['ver'] end |