Class: Skyfall::Label

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Label

Returns a new instance of Label.

Parameters:

  • raw label JSON

Raises:

  • if the data has an invalid format

  • if the label is in an unsupported future version



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

#dataHash (readonly)

Returns the label’s JSON data.

Returns:

  • the label’s JSON data



24
25
26
# File 'lib/skyfall/label.rb', line 24

def data
  @data
end

Instance Method Details

#authorityString Also known as: src

DID of the labelling authority (the labeller service).

Returns:



53
54
55
# File 'lib/skyfall/label.rb', line 53

def authority
  @data['src']
end

#cidCID?

Returns CID of the specific version of the subject that this label applies to.

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_atTime Also known as: cts

Returns timestamp when the label was created.

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_atTime? Also known as: exp

Returns optional timestamp when the label expires.

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.

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

#subjectString Also known as: uri

AT URI or DID of the labelled subject (e.g. a user or post).

Returns:



59
60
61
# File 'lib/skyfall/label.rb', line 59

def subject
  @data['uri']
end

#valueString Also known as: val

Returns label value.

Returns:

  • label value



69
70
71
# File 'lib/skyfall/label.rb', line 69

def value
  @data['val']
end

#versionInteger Also known as: ver

Returns label format version number.

Returns:

  • label format version number



47
48
49
# File 'lib/skyfall/label.rb', line 47

def version
  @data['ver']
end