Add high-level documentation

https://nostr-ruby.com
This commit is contained in:
Wilson Silva
2023-11-13 17:42:07 +07:00
parent b206f6504e
commit d49fac49b6
23 changed files with 1014 additions and 256 deletions

View File

@@ -0,0 +1,21 @@
# Connecting to a Relay
You must connect your nostr [Client](../core/client) to a relay in order to send and receive [Events](../events).
Instantiate a [`Nostr::Client`](https://www.rubydoc.info/gems/nostr/Nostr/Client) and a
[`Nostr::Relay`](https://www.rubydoc.info/gems/nostr/Nostr/Relay) giving it the `url` of your relay. The `name`
attribute is just descriptive.
Calling [`Client#connect`](https://www.rubydoc.info/gems/nostr/Nostr/Client#connect-instance_method) attempts to
establish a WebSocket connection between the Client and the Relay.
```ruby
client = Nostr::Client.new
relay = Nostr::Relay.new(url: 'wss://relay.damus.io', name: 'Damus')
# Listen for the connect event
client.on :connect do
# When this block executes, you're connected to the relay
end
# Connect to a relay asynchronously
client.connect(relay)
```

View File

@@ -0,0 +1,29 @@
# Publishing events
Create a [signed event](../core/keys) and call the method
[`Nostr::Client#publish`](https://www.rubydoc.info/gems/nostr/Nostr/Client#publish-instance_method) to send the
event to the relay.
```ruby{4-8,17}
# Create a user with the keypair
user = Nostr::User.new(keypair: keypair)
# Create a signed event
text_note_event = user.create_event(
kind: Nostr::EventKind::TEXT_NOTE,
content: 'Your feedback is appreciated, now pay $8'
)
# Connect asynchronously to a relay
relay = Nostr::Relay.new(url: 'wss://nostr.wine', name: 'Wine')
client.connect(relay)
# Listen asynchronously for the connect event
client.on :connect do
# Send the event to the relay
client.publish(text_note_event)
end
```
The relay will verify the signature of the event with the public key. If the signature is valid, the relay should
broadcast the event to all subscribers.

View File

@@ -0,0 +1,6 @@
# Receiving events
To receive events from Relays, you must create a subscription on the relay. A subscription is a filter that defines the
events you want to receive.
For more information, read the [Subscription](../subscriptions/creating-a-subscription.md) section.