skyfall 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +182 -29
  4. data/example/block_tracker.rb +1 -1
  5. data/example/{monitor_phrases.rb → jet_monitor_phrases.rb} +3 -2
  6. data/example/print_all_posts.rb +1 -1
  7. data/example/push_notifications.rb +1 -1
  8. data/lib/skyfall/collection.rb +44 -14
  9. data/lib/skyfall/faye_ext.rb +48 -0
  10. data/lib/skyfall/{messages → firehose}/account_message.rb +3 -1
  11. data/lib/skyfall/{messages → firehose}/commit_message.rb +9 -3
  12. data/lib/skyfall/firehose/handle_message.rb +14 -0
  13. data/lib/skyfall/firehose/identity_message.rb +9 -0
  14. data/lib/skyfall/{messages → firehose}/info_message.rb +3 -1
  15. data/lib/skyfall/{messages → firehose}/labels_message.rb +2 -2
  16. data/lib/skyfall/{messages/websocket_message.rb → firehose/message.rb} +19 -11
  17. data/lib/skyfall/firehose/operation.rb +58 -0
  18. data/lib/skyfall/firehose/sync_message.rb +9 -0
  19. data/lib/skyfall/firehose/tombstone_message.rb +11 -0
  20. data/lib/skyfall/firehose/unknown_message.rb +6 -0
  21. data/lib/skyfall/firehose.rb +79 -0
  22. data/lib/skyfall/jetstream/account_message.rb +19 -0
  23. data/lib/skyfall/jetstream/commit_message.rb +16 -0
  24. data/lib/skyfall/jetstream/identity_message.rb +15 -0
  25. data/lib/skyfall/jetstream/message.rb +54 -0
  26. data/lib/skyfall/jetstream/operation.rb +58 -0
  27. data/lib/skyfall/jetstream/unknown_message.rb +6 -0
  28. data/lib/skyfall/jetstream.rb +121 -0
  29. data/lib/skyfall/stream.rb +45 -59
  30. data/lib/skyfall/version.rb +1 -1
  31. data/lib/skyfall.rb +4 -2
  32. metadata +24 -18
  33. data/example/follower_tracker.rb +0 -84
  34. data/lib/skyfall/messages/handle_message.rb +0 -12
  35. data/lib/skyfall/messages/identity_message.rb +0 -7
  36. data/lib/skyfall/messages/tombstone_message.rb +0 -9
  37. data/lib/skyfall/messages/unknown_message.rb +0 -4
  38. data/lib/skyfall/operation.rb +0 -74
data/lib/skyfall.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'skyfall/stream'
4
- require_relative 'skyfall/messages/websocket_message'
3
+ require_relative 'skyfall/firehose'
4
+ require_relative 'skyfall/firehose/message'
5
+ require_relative 'skyfall/jetstream'
6
+ require_relative 'skyfall/jetstream/message'
5
7
  require_relative 'skyfall/version'
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skyfall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuba Suder
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
10
+ date: 2025-05-19 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: base32
@@ -114,8 +113,7 @@ files:
114
113
  - LICENSE.txt
115
114
  - README.md
116
115
  - example/block_tracker.rb
117
- - example/follower_tracker.rb
118
- - example/monitor_phrases.rb
116
+ - example/jet_monitor_phrases.rb
119
117
  - example/print_all_posts.rb
120
118
  - example/push_notifications.rb
121
119
  - lib/skyfall.rb
@@ -124,17 +122,27 @@ files:
124
122
  - lib/skyfall/collection.rb
125
123
  - lib/skyfall/errors.rb
126
124
  - lib/skyfall/extensions.rb
125
+ - lib/skyfall/faye_ext.rb
126
+ - lib/skyfall/firehose.rb
127
+ - lib/skyfall/firehose/account_message.rb
128
+ - lib/skyfall/firehose/commit_message.rb
129
+ - lib/skyfall/firehose/handle_message.rb
130
+ - lib/skyfall/firehose/identity_message.rb
131
+ - lib/skyfall/firehose/info_message.rb
132
+ - lib/skyfall/firehose/labels_message.rb
133
+ - lib/skyfall/firehose/message.rb
134
+ - lib/skyfall/firehose/operation.rb
135
+ - lib/skyfall/firehose/sync_message.rb
136
+ - lib/skyfall/firehose/tombstone_message.rb
137
+ - lib/skyfall/firehose/unknown_message.rb
138
+ - lib/skyfall/jetstream.rb
139
+ - lib/skyfall/jetstream/account_message.rb
140
+ - lib/skyfall/jetstream/commit_message.rb
141
+ - lib/skyfall/jetstream/identity_message.rb
142
+ - lib/skyfall/jetstream/message.rb
143
+ - lib/skyfall/jetstream/operation.rb
144
+ - lib/skyfall/jetstream/unknown_message.rb
127
145
  - lib/skyfall/label.rb
128
- - lib/skyfall/messages/account_message.rb
129
- - lib/skyfall/messages/commit_message.rb
130
- - lib/skyfall/messages/handle_message.rb
131
- - lib/skyfall/messages/identity_message.rb
132
- - lib/skyfall/messages/info_message.rb
133
- - lib/skyfall/messages/labels_message.rb
134
- - lib/skyfall/messages/tombstone_message.rb
135
- - lib/skyfall/messages/unknown_message.rb
136
- - lib/skyfall/messages/websocket_message.rb
137
- - lib/skyfall/operation.rb
138
146
  - lib/skyfall/stream.rb
139
147
  - lib/skyfall/version.rb
140
148
  - sig/skyfall.rbs
@@ -145,7 +153,6 @@ metadata:
145
153
  bug_tracker_uri: https://github.com/mackuba/skyfall/issues
146
154
  changelog_uri: https://github.com/mackuba/skyfall/blob/master/CHANGELOG.md
147
155
  source_code_uri: https://github.com/mackuba/skyfall
148
- post_install_message:
149
156
  rdoc_options: []
150
157
  require_paths:
151
158
  - lib
@@ -160,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
167
  - !ruby/object:Gem::Version
161
168
  version: '0'
162
169
  requirements: []
163
- rubygems_version: 3.4.10
164
- signing_key:
170
+ rubygems_version: 3.6.2
165
171
  specification_version: 4
166
172
  summary: A Ruby gem for streaming data from the Bluesky/AtProto firehose
167
173
  test_files: []
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # Example: track when people follow and unfollow your account.
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 'json'
9
- require 'open-uri'
10
- require 'skyfall'
11
-
12
- $monitored_did = ARGV[0]
13
-
14
- if $monitored_did.to_s.empty?
15
- puts "Usage: #{$PROGRAM_NAME} <monitored_did>"
16
- exit 1
17
- elsif ARGV[0] !~ /^did:plc:[a-z0-9]{24}$/
18
- puts "Not a valid DID: #{$monitored_did}"
19
- exit 1
20
- end
21
-
22
- sky = Skyfall::Stream.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
31
- next if msg.type != :commit
32
-
33
- msg.operations.each do |op|
34
- next if op.action != :create
35
-
36
- begin
37
- case op.type
38
- when :bsky_block
39
- process_block(msg, op)
40
- when :bsky_listitem
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
-
56
- def process_list_item(msg, op)
57
- if op.raw_record['subject'] == $monitored_did
58
- owner_handle = get_user_handle(op.repo)
59
-
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
-
67
- def get_user_handle(did)
68
- url = "https://plc.directory/#{did}"
69
- json = JSON.parse(URI.open(url).read)
70
- json['alsoKnownAs'][0].gsub('at://', '')
71
- end
72
-
73
- def get_list_name(list_uri)
74
- repo, type, rkey = list_uri.gsub('at://', '').split('/')
75
- url = "https://bsky.social/xrpc/com.atproto.repo.getRecord?repo=#{repo}&collection=#{type}&rkey=#{rkey}"
76
-
77
- json = JSON.parse(URI.open(url).read)
78
- json['value']['name']
79
- end
80
-
81
- # close the connection cleanly on Ctrl+C
82
- trap("SIGINT") { sky.disconnect }
83
-
84
- sky.connect
@@ -1,12 +0,0 @@
1
- module Skyfall
2
-
3
- #
4
- # Note: this event type is deprecated and will stop being emitted at some point.
5
- # You should instead listen for 'identity' events (Skyfall::IdentityMessage).
6
- #
7
- class HandleMessage < WebsocketMessage
8
- def handle
9
- @data_object['handle']
10
- end
11
- end
12
- end
@@ -1,7 +0,0 @@
1
- module Skyfall
2
- class IdentityMessage < WebsocketMessage
3
- def handle
4
- @data_object['handle']
5
- end
6
- end
7
- end
@@ -1,9 +0,0 @@
1
- module Skyfall
2
-
3
- #
4
- # Note: this event type is deprecated and will stop being emitted at some point.
5
- # You should instead listen for 'account' events (Skyfall::AccountMessage).
6
- #
7
- class TombstoneMessage < WebsocketMessage
8
- end
9
- end
@@ -1,4 +0,0 @@
1
- module Skyfall
2
- class UnknownMessage < WebsocketMessage
3
- end
4
- end
@@ -1,74 +0,0 @@
1
- require_relative 'collection'
2
-
3
- module Skyfall
4
- class Operation
5
- def initialize(message, json)
6
- @message = message
7
- @json = json
8
- end
9
-
10
- def repo
11
- @message.repo
12
- end
13
-
14
- alias did repo
15
-
16
- def path
17
- @json['path']
18
- end
19
-
20
- def action
21
- @json['action'].to_sym
22
- end
23
-
24
- def collection
25
- @json['path'].split('/')[0]
26
- end
27
-
28
- def rkey
29
- @json['path'].split('/')[1]
30
- end
31
-
32
- def uri
33
- "at://#{repo}/#{path}"
34
- end
35
-
36
- def cid
37
- @cid ||= @json['cid'] && CID.from_cbor_tag(@json['cid'])
38
- end
39
-
40
- def raw_record
41
- @raw_record ||= cid && @message.blocks.section_with_cid(cid)
42
- end
43
-
44
- def type
45
- case collection
46
- when Collection::BSKY_BLOCK then :bsky_block
47
- when Collection::BSKY_FEED then :bsky_feed
48
- when Collection::BSKY_FOLLOW then :bsky_follow
49
- when Collection::BSKY_LABELER then :bsky_labeler
50
- when Collection::BSKY_LIKE then :bsky_like
51
- when Collection::BSKY_LIST then :bsky_list
52
- when Collection::BSKY_LISTBLOCK then :bsky_listblock
53
- when Collection::BSKY_LISTITEM then :bsky_listitem
54
- when Collection::BSKY_POST then :bsky_post
55
- when Collection::BSKY_POSTGATE then :bsky_postgate
56
- when Collection::BSKY_PROFILE then :bsky_profile
57
- when Collection::BSKY_REPOST then :bsky_repost
58
- when Collection::BSKY_STARTERPACK then :bsky_starterpack
59
- when Collection::BSKY_THREADGATE then :bsky_threadgate
60
- when Collection::BSKY_CHAT_DECLARATION then :bsky_chat_declaration
61
- else :unknown
62
- end
63
- end
64
-
65
- def inspectable_variables
66
- instance_variables - [:@message]
67
- end
68
-
69
- def inspect
70
- vars = inspectable_variables.map { |v| "#{v}=#{instance_variable_get(v).inspect}" }.join(", ")
71
- "#<#{self.class}:0x#{object_id} #{vars}>"
72
- end
73
- end
74
- end