From 3fffcd1a4e78ab66189c3f3a0933cc8ba92228fc Mon Sep 17 00:00:00 2001 From: Wilson Silva Date: Sat, 18 Nov 2023 18:06:53 +0700 Subject: [PATCH] Use keyword arguments for User#create_event This allows for code completion and fixes another RBS issue --- lib/nostr/user.rb | 25 +++++++++++++++++-------- sig/nostr/user.rbs | 12 ++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/nostr/user.rb b/lib/nostr/user.rb index 89246d0..0015137 100644 --- a/lib/nostr/user.rb +++ b/lib/nostr/user.rb @@ -47,17 +47,26 @@ module Nostr # content: 'Your feedback is appreciated, now pay $8' # ) # - # @param event_attributes [Hash] - # @option event_attributes [String] :pubkey 32-bytes hex-encoded public key of the event creator. - # @option event_attributes [Integer] :created_at Date of the creation of the vent. A UNIX timestamp, in seconds. - # @option event_attributes [Integer] :kind The kind of the event. An integer from 0 to 3. - # @option event_attributes [Array] :tags An array of tags. Each tag is an array of strings. - # @option event_attributes [String] :content Arbitrary string. + # @param created_at [Integer] Date of the creation of the vent. A UNIX timestamp, in seconds. + # @param kind [Integer] The kind of the event. An integer from 0 to 3. + # @param tags [Array] An array of tags. Each tag is an array of strings. + # @param content [String] Arbitrary string. # # @return [Event] # - def create_event(event_attributes) - event = Event.new(**event_attributes.merge(pubkey: keypair.public_key)) + def create_event( + kind:, + content:, + created_at: Time.now.to_i, + tags: [] + ) + event = Event.new( + pubkey: keypair.public_key, + kind:, + content:, + created_at:, + tags: + ) event.sign(keypair.private_key) end end diff --git a/sig/nostr/user.rbs b/sig/nostr/user.rbs index fb2437f..0d9609b 100644 --- a/sig/nostr/user.rbs +++ b/sig/nostr/user.rbs @@ -5,14 +5,10 @@ module Nostr def initialize: (?keypair: KeyPair | nil, ?keygen: Keygen) -> void def create_event: ( - { - pubkey: String, - created_at: Integer, - kind: Integer, - tags: Array[String], - content: String, - created_at: Integer, - } + kind: Integer, + content: String, + ?created_at: Integer, + ?tags: Array[Array[String]], ) -> Event private