Class: Nostr::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/nostr/subscription.rb

Overview

A subscription the result of a request to receive events from a relay

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter:, id: SecureRandom.hex) ⇒ Subscription

Initializes a subscription

Examples:

Creating a subscription with no id and no filters

subscription = Nostr::Subscription.new

Creating a subscription with an ID

subscription = Nostr::Subscription.new(id: 'c24881c305c5cfb7c1168be7e9b0e150')

Subscribing to all events created after a certain time

subscription = Nostr::Subscription.new(filter: Nostr::Filter.new(since: 1230981305))

Parameters:

  • id (String) (defaults to: SecureRandom.hex)

    An arbitrary, non-empty string of max length 64 chars used to represent a subscription

  • filter (Filter)

    An object that determines what events will be sent in that subscription



47
48
49
50
# File 'lib/nostr/subscription.rb', line 47

def initialize(filter:, id: SecureRandom.hex)
  @id = id
  @filter = filter
end

Instance Attribute Details

#filterFilter (readonly)

An object that determines what events will be sent in the subscription

Examples:

subscription.filter # => #<Nostr::Subscription:0x0000000110eea460 @filter=#<Nostr::Filter:0x0000000110c24de8>,
@id="0dd7f3fa06cd5f797438dd0b7477f3c7">

Returns:



29
30
31
# File 'lib/nostr/subscription.rb', line 29

def filter
  @filter
end

#idString (readonly)

An arbitrary, non-empty string of max length 64 chars used to represent a subscription

Examples:

subscription.id # => 'c24881c305c5cfb7c1168be7e9b0e150'

Returns:

  • (String)


17
18
19
# File 'lib/nostr/subscription.rb', line 17

def id
  @id
end

Instance Method Details

#==(other) ⇒ Boolean

Compares two subscriptions. Returns true if all attributes are equal and false otherwise

Examples:

subscription1 == subscription1 # => true

Returns:

  • (Boolean)

    True if all attributes are equal and false otherwise



61
62
63
# File 'lib/nostr/subscription.rb', line 61

def ==(other)
  id == other.id && filter == other.filter
end