A Ruby gem for streaming data from the Bluesky/ATProto firehose

some other tweaks in the examples

+17 -10
+12 -8
example/block_tracker.rb
··· 1 #!/usr/bin/env ruby 2 3 - # Example: monitor the network for people blocking your account or adding you to mute lists. 4 5 # load skyfall from a local folder - you normally won't need this 6 $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) ··· 21 22 sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos) 23 24 - sky.on_connect { puts "Connected, monitoring #{$monitored_did}" } 25 - sky.on_disconnect { puts "Disconnected" } 26 - sky.on_reconnect { puts "Reconnecting..." } 27 - sky.on_error { |e| puts "ERROR: #{e}" } 28 29 sky.on_message do |msg| 30 # we're only interested in repo commit messages ··· 41 process_list_item(msg, op) 42 end 43 rescue StandardError => e 44 - puts "Error: #{e}" 45 end 46 end 47 end 48 49 def process_block(msg, op) 50 if op.raw_record['subject'] == $monitored_did 51 owner_handle = get_user_handle(op.repo) 52 - puts "@#{owner_handle} has blocked you! (#{msg.time.getlocal})" 53 end 54 end 55 ··· 60 list_uri = op.raw_record['list'] 61 list_name = get_list_name(list_uri) 62 63 - puts "@#{owner_handle} has added you to list \"#{list_name}\" (#{msg.time.getlocal})" 64 end 65 end 66
··· 1 #!/usr/bin/env ruby 2 3 + # Example: monitor the network for people blocking your account or adding you to lists. 4 5 # load skyfall from a local folder - you normally won't need this 6 $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) ··· 21 22 sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos) 23 24 + sky.on_connect { log "Connected, monitoring #{$monitored_did}" } 25 + sky.on_disconnect { log "Disconnected" } 26 + sky.on_reconnect { log "Reconnecting..." } 27 + sky.on_error { |e| log "ERROR: #{e}" } 28 29 sky.on_message do |msg| 30 # we're only interested in repo commit messages ··· 41 process_list_item(msg, op) 42 end 43 rescue StandardError => e 44 + log "Error: #{e}" 45 end 46 end 47 end 48 49 + def log(msg) 50 + puts "[#{Time.now}] #{msg}" 51 + end 52 + 53 def process_block(msg, op) 54 if op.raw_record['subject'] == $monitored_did 55 owner_handle = get_user_handle(op.repo) 56 + log "@#{owner_handle} has blocked you! (#{msg.time.getlocal})" 57 end 58 end 59 ··· 64 list_uri = op.raw_record['list'] 65 list_name = get_list_name(list_uri) 66 67 + log "@#{owner_handle} has added you to list \"#{list_name}\" (#{msg.time.getlocal})" 68 end 69 end 70
+5 -2
example/print_all_posts.rb
··· 1 #!/usr/bin/env ruby 2 3 # Example: print the date and text of every new post made on the network as they appear. 4 5 # load skyfall from a local folder - you normally won't need this 6 $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) 7 8 require 'skyfall' 9 10 - sky = Skyfall::Firehose.new('bsky.network', :subscribe_repos) 11 12 sky.on_message do |msg| 13 # we're only interested in repo commit messages ··· 23 end 24 end 25 26 - sky.on_connect { puts "Connected" } 27 sky.on_disconnect { puts "Disconnected" } 28 sky.on_reconnect { puts "Reconnecting..." } 29 sky.on_error { |e| puts "ERROR: #{e}" }
··· 1 #!/usr/bin/env ruby 2 3 # Example: print the date and text of every new post made on the network as they appear. 4 + # Pass a hostname of a single PDS as the argument to only stream new posts from that PDS. 5 6 # load skyfall from a local folder - you normally won't need this 7 $LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) 8 9 require 'skyfall' 10 11 + firehose_host = ARGV[0] || 'bsky.network' 12 + 13 + sky = Skyfall::Firehose.new(firehose_host, :subscribe_repos) 14 15 sky.on_message do |msg| 16 # we're only interested in repo commit messages ··· 26 end 27 end 28 29 + sky.on_connect { puts "Connected to #{firehose_host}" } 30 sky.on_disconnect { puts "Disconnected" } 31 sky.on_reconnect { puts "Reconnecting..." } 32 sky.on_error { |e| puts "ERROR: #{e}" }