bskyrb 0.5.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ae64c99f896f5ec3366f9c4e028d61c9006563351c34be989881ccb4fac52d9
4
- data.tar.gz: 57903df97da314a87e257fad02d8536ad783ea88511c2f5b7efbf774ad36b4b4
3
+ metadata.gz: 625dd8f4aea0135203e2260691d4b1d679018a6d285dafd51ed1da28f56dd931
4
+ data.tar.gz: 1f489ca704620817495c65bfd82247cd6289045a626a8f656e3cc84cf817d2c5
5
5
  SHA512:
6
- metadata.gz: 447074d457ecb73774ce6e355f3cd18820b13e508c58f144361105b8bb1bf6fe7547ac994d62c5a2fbdec49b3d56b96fd8fdcadfeb6d967cc521e983c7a84f26
7
- data.tar.gz: f3440ccc3800260c21481da110ea68aa40e4d48ca70ab1e6292d80435820f389f0f59f3f02c31029812d2d9335d42cbddcefc3f40c1e667d0a21e139642e5d7c
6
+ metadata.gz: 95d7d5cdf09126a6df3de48eca3e15d4d514cbb2812bbe0d8af92340146c6495249c50e918d57fa92a5f8f6565d9c7b956fa6a0bd3d855437d908092bb44eced
7
+ data.tar.gz: d289b2cdc09d08ef67c55aa4e1c6a7eef5087c773293aa1e771bbb25b957021e3b85abbb451e48adb6be8d924ca823ac10573aca360da9cc6fbbae69d1f11783
@@ -24,7 +24,7 @@ module Bskyrb
24
24
  end
25
25
 
26
26
  def upload_blob(blob_path, content_type)
27
- # only images?
27
+ # only images
28
28
  image_bytes = File.binread(blob_path)
29
29
  HTTParty.post(
30
30
  upload_blob_uri(session.pds),
@@ -53,7 +53,7 @@ module Bskyrb
53
53
  )
54
54
  end
55
55
 
56
- def create_post(text)
56
+ def create_post_or_reply(text, reply_to = nil)
57
57
  input = Bskyrb::ComAtprotoRepoCreaterecord::CreateRecord::Input.from_hash({
58
58
  "collection" => "app.bsky.feed.post",
59
59
  "$type" => "app.bsky.feed.post",
@@ -64,33 +64,28 @@ module Bskyrb
64
64
  "text" => text,
65
65
  },
66
66
  })
67
+ if reply_to
68
+ input.record["reply"] = {
69
+ "parent" => {
70
+ "uri" => reply_to.uri,
71
+ "cid" => reply_to.cid,
72
+ },
73
+ "root" => {
74
+ "uri" => reply_to.uri,
75
+ "cid" => reply_to.cid,
76
+ },
77
+ }
78
+ end
67
79
  create_record(input)
68
80
  end
69
81
 
82
+ def create_post(text)
83
+ create_post_or_reply(text)
84
+ end
85
+
70
86
  def create_reply(replylink, text)
71
87
  reply_to = get_post_by_url(replylink)
72
- input = Bskyrb::ComAtprotoRepoCreaterecord::CreateRecord::Input.from_hash({
73
- "collection" => "app.bsky.feed.post",
74
- "$type" => "app.bsky.feed.post",
75
- "repo" => session.did,
76
-
77
- "record" => {
78
- "reply" => {
79
- "parent" => {
80
- "uri" => reply_to.uri,
81
- "cid" => reply_to.cid,
82
- },
83
- "root" => {
84
- "uri" => reply_to.uri,
85
- "cid" => reply_to.cid,
86
- },
87
- },
88
- "$type" => "app.bsky.feed.post",
89
- "createdAt" => DateTime.now.iso8601(3),
90
- "text" => text,
91
- },
92
- })
93
- create_record(input)
88
+ create_post_or_reply(text, reply_to)
94
89
  end
95
90
 
96
91
  def profile_action(username, type)
@@ -140,40 +135,40 @@ module Bskyrb
140
135
  profile_action(username, "app.bsky.graph.block")
141
136
  end
142
137
 
138
+ def mute(username)
139
+ HTTParty.post(
140
+ mute_actor_uri(session.pds),
141
+ body: { actor: username }.to_json,
142
+ headers: default_authenticated_headers(session),
143
+ )
144
+ end
145
+
143
146
  def get_latest_post(username)
144
147
  feed = get_latest_n_posts(username, 1)
145
148
  feed.feed.first
146
149
  end
147
150
 
148
151
  def get_latest_n_posts(username, n)
149
- query = Bskyrb::AppBskyFeedGetauthorfeed::GetAuthorFeed::Input.new.tap do |q|
150
- q.actor = username
151
- q.limit = n
152
- end
153
- hydrate_feed HTTParty.get(
154
- get_author_feed_uri(session.pds, query),
155
- headers: default_authenticated_headers(session),
156
- ), Bskyrb::AppBskyFeedGetauthorfeed::GetAuthorFeed::Output
152
+ endpoint = XRPC::EasyEndpoint.new(session.pds, "app.bsky.feed.getAuthorFeed", authenticated: true)
153
+ endpoint.authenticate(session.access_token)
154
+ hydrate_feed endpoint.get(actor: username, limit: n), Bskyrb::AppBskyFeedGetauthorfeed::GetAuthorFeed::Output
157
155
  end
158
156
 
159
157
  def get_skyline(n)
160
- query = Bskyrb::AppBskyFeedGettimeline::GetTimeline::Input.new.tap do |q|
161
- q.limit = n
162
- end
163
- hydrate_feed HTTParty.get(
164
- get_timeline_uri(session.pds, query),
165
- headers: default_authenticated_headers(session),
166
- ), Bskyrb::AppBskyFeedGettimeline::GetTimeline::Output
158
+ endpoint = XRPC::EasyEndpoint.new(session.pds, "app.bsky.feed.getTimeline", authenticated: true)
159
+ endpoint.authenticate(session.access_token)
160
+ hydrate_feed endpoint.get(limit: n), Bskyrb::AppBskyFeedGettimeline::GetTimeline::Output
161
+ end
162
+
163
+ def list_records(collection, username, limit = 10)
164
+ listRecords = XRPC::EasyEndpoint.new(session.pds, "com.atproto.repo.listRecords")
165
+ listRecords.get(repo: resolve_handle(session.pds, username)["did"], collection: collection, limit: limit)["records"]
167
166
  end
168
167
 
169
168
  def get_popular(n)
170
- query = Bskyrb::AppBskyUnspeccedGetpopular::GetPopular::Input.new.tap do |q|
171
- q.limit = n
172
- end
173
- hydrate_feed HTTParty.get(
174
- get_popular_uri(session.pds, query),
175
- headers: default_authenticated_headers(session),
176
- ), Bskyrb::AppBskyUnspeccedGetpopular::GetPopular::Output
169
+ endpoint = XRPC::EasyEndpoint.new session.pds, "app.bsky.unspecced.getPopular", authenticated: true
170
+ endpoint.authenticate session.access_token
171
+ hydrate_feed endpoint.get(limit: n), Bskyrb::AppBskyUnspeccedGetpopular::GetPopular::Output
177
172
  end
178
173
 
179
174
  def hydrate_feed(response_hash, klass)
@@ -1,12 +1,9 @@
1
1
  # typed: false
2
- require "uri"
3
- require "httparty"
4
2
 
5
3
  module Bskyrb
6
- module RequestUtils
4
+ module RequestUtils # Goal is to replace with pure XRPC eventually
7
5
  def resolve_handle(pds, username)
8
- resolveHandle = XRPC::Endpoint.new(pds, "com.atproto.identity.resolveHandle", :handle)
9
- resolveHandle.get(handle: username)
6
+ XRPC.request(pds, "com.atproto.identity.resolveHandle", handle: username)
10
7
  end
11
8
 
12
9
  def query_obj_to_query_params(q)
@@ -29,6 +26,10 @@ module Bskyrb
29
26
  "#{pds}/xrpc/com.atproto.repo.deleteRecord"
30
27
  end
31
28
 
29
+ def mute_actor_uri(pds)
30
+ "#{pds}/xrpc/app.bsky.graph.muteActor"
31
+ end
32
+
32
33
  def upload_blob_uri(pds)
33
34
  "#{pds}/xrpc/com.atproto.repo.uploadBlob"
34
35
  end
@@ -37,18 +38,6 @@ module Bskyrb
37
38
  "#{pds}/xrpc/app.bsky.feed.getPostThread#{query_obj_to_query_params(query)}"
38
39
  end
39
40
 
40
- def get_author_feed_uri(pds, query)
41
- "#{pds}/xrpc/app.bsky.feed.getAuthorFeed#{query_obj_to_query_params(query)}"
42
- end
43
-
44
- def get_timeline_uri(pds, query)
45
- "#{pds}/xrpc/app.bsky.feed.getTimeline#{query_obj_to_query_params(query)}"
46
- end
47
-
48
- def get_popular_uri(pds, query)
49
- "#{pds}/xrpc/app.bsky.unspecced.getPopular#{query_obj_to_query_params(query)}"
50
- end
51
-
52
41
  def default_authenticated_headers(session)
53
42
  default_headers.merge({
54
43
  Authorization: "Bearer #{session.access_token}",
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Bskyrb
5
- VERSION = "0.5.1"
5
+ VERSION = "0.5.3"
6
6
  end
data/lib/bskyrb.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "bskyrb/error"
5
- require "bskyrb/session"
6
- require "bskyrb/records"
7
- require "bskyrb/generated_classes"
8
- require "xrpc"
4
+ require 'bskyrb/error'
5
+ require 'bskyrb/session'
6
+ require 'bskyrb/records'
7
+ require 'bskyrb/generated_classes'
8
+ require 'xrpc'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bskyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shreyan Jain
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-05-15 00:00:00.000000000 Z
12
+ date: 2023-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -31,28 +31,42 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 3.3.3
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: 3.3.3
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: httparty
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: 0.21.0
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: 0.21.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: xrpc
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.0.4
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.0.4
56
70
  description: A Ruby gem for interacting with bsky/atproto
57
71
  email:
58
72
  - shreyan.jain.9@outlook.com