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:

  • data (Hash)

    raw label JSON

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/skyfall/label.rb', line 32

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:

  • (Hash)

    the label's JSON data



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

def data
  @data
end

Instance Method Details

#authorityString Also known as: src

DID of the labelling authority (the labeller service).

Returns:

  • (String)


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

def authority
  @data['src']
end

#cidOxygene::CID?

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

Returns:

  • (Oxygene::CID, nil)

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



65
66
67
# File 'lib/skyfall/label.rb', line 65

def cid
  @cid ||= @data['cid'] && Oxygene::CID.from_json(@data['cid'])
end

#created_atTime Also known as: cts

Returns timestamp when the label was created.

Returns:

  • (Time)

    timestamp when the label was created



80
81
82
# File 'lib/skyfall/label.rb', line 80

def created_at
  @created_at ||= Time.parse(@data['cts'])
end

#expires_atTime? Also known as: exp

Returns optional timestamp when the label expires.

Returns:

  • (Time, nil)

    optional timestamp when the label expires



85
86
87
# File 'lib/skyfall/label.rb', line 85

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:

  • (Boolean)

    if true, then this is a negation (delete) of an existing label



75
76
77
# File 'lib/skyfall/label.rb', line 75

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:

  • (String)


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

def subject
  @data['uri']
end

#valueString Also known as: val

Returns label value.

Returns:

  • (String)

    label value



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

def value
  @data['val']
end

#versionInteger Also known as: ver

Returns label format version number.

Returns:

  • (Integer)

    label format version number



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

def version
  @data['ver']
end