at_protocol 0.0.4.1 → 0.0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/at_protocol/at_uri.rb +4 -0
- data/lib/at_protocol/collection.rb +3 -15
- data/lib/at_protocol/requests.rb +39 -20
- data/lib/at_protocol/session.rb +4 -0
- data/lib/at_protocol/version.rb +1 -1
- data/lib/at_protocol/writes.rb +6 -5
- data/lib/at_protocol.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bac3005062f2494c16a3fcabc3af9f45daf3b127b81624872ab71603de1f9fbc
|
4
|
+
data.tar.gz: 28088b1b416163feab91d06e42245279216673cf2ae1d077eebc78bfb79a0b1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeb00d26cead39126432d2be52540da02f5d9734eebe9c5c4735dd4e4e556ae88a0886fe8455c98a72969b7728e2213ad0f957317a1d89852cdbcb687e7d44f7
|
7
|
+
data.tar.gz: deb75bae3fe96f9eb2831f0e61ce48f23aa9030b5fe1714123cb0c7293e7378ac3a13cef0850f3b653e5467376b19fbf07de5a9d50e21d2a775527ce16b507ba
|
data/lib/at_protocol/at_uri.rb
CHANGED
@@ -9,22 +9,10 @@ module ATProto
|
|
9
9
|
const(:repo, ATProto::Repo)
|
10
10
|
const(:collection, String)
|
11
11
|
|
12
|
-
sig { params(
|
13
|
-
|
14
|
-
def list(limit = 10)
|
15
|
-
self.repo.xrpc
|
16
|
-
.get.com_atproto_repo_listRecords(
|
17
|
-
repo: self.repo.did,
|
18
|
-
collection: self.collection,
|
19
|
-
limit: limit,
|
20
|
-
)["records"]
|
21
|
-
.map { |record|
|
22
|
-
ATProto::Record.from_hash(record)
|
23
|
-
}
|
24
|
-
end
|
12
|
+
sig { params(count: T.nilable(Integer)).returns(T::Array[ATProto::Record]) }
|
25
13
|
|
26
|
-
def
|
27
|
-
T.must(get_paginated_data(self.repo, :com_atproto_repo_listRecords.to_s, key: "records", params: { repo: self.repo.to_s, collection: self.to_s }, cursor: nil) do |record|
|
14
|
+
def list(count = nil)
|
15
|
+
T.must(get_paginated_data(self.repo, :com_atproto_repo_listRecords.to_s, key: "records", params: { repo: self.repo.to_s, collection: self.to_s }, count: count, cursor: nil) do |record|
|
28
16
|
ATProto::Record.from_hash(record)
|
29
17
|
end)
|
30
18
|
end
|
data/lib/at_protocol/requests.rb
CHANGED
@@ -78,6 +78,9 @@ module ATProto
|
|
78
78
|
cursor: T.nilable(
|
79
79
|
String
|
80
80
|
),
|
81
|
+
count: T.nilable(
|
82
|
+
Integer
|
83
|
+
),
|
81
84
|
map_block: T.nilable(Proc),
|
82
85
|
)
|
83
86
|
.returns(T
|
@@ -86,7 +89,7 @@ module ATProto
|
|
86
89
|
))
|
87
90
|
}
|
88
91
|
|
89
|
-
def get_paginated_data(session, method, key:, params:, cursor: nil, &map_block)
|
92
|
+
def get_paginated_data(session, method, key:, params:, cursor: nil, count: nil, &map_block)
|
90
93
|
params.merge({ limit: 100, cursor: cursor }).then do |send_data|
|
91
94
|
session.xrpc.get.public_send(method, **send_data).then do |response|
|
92
95
|
response.dig(key).then do |data|
|
@@ -94,26 +97,19 @@ module ATProto
|
|
94
97
|
return []
|
95
98
|
end
|
96
99
|
|
97
|
-
if block_given?
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
return results
|
102
|
-
else
|
103
|
-
get_paginated_data(session, method, key: key, params: params, cursor: next_cursor, &map_block).then do |next_results|
|
104
|
-
return results + next_results
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
100
|
+
results = if block_given?
|
101
|
+
data.map(&map_block)
|
102
|
+
else
|
103
|
+
data
|
108
104
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
105
|
+
|
106
|
+
response.dig("cursor").then do |next_cursor|
|
107
|
+
if next_cursor.nil? || (count && results.length >= count)
|
108
|
+
return results[0..count]
|
109
|
+
else
|
110
|
+
remaining_count = count ? count - results.length : nil
|
111
|
+
get_paginated_data(session, method, key: key, params: params, cursor: next_cursor, count: remaining_count, &map_block).then do |next_results|
|
112
|
+
return (results + next_results)
|
117
113
|
end
|
118
114
|
end
|
119
115
|
end
|
@@ -123,3 +119,26 @@ module ATProto
|
|
123
119
|
end
|
124
120
|
end
|
125
121
|
end
|
122
|
+
|
123
|
+
module ATProto
|
124
|
+
module RequestUtils
|
125
|
+
class XRPCResponseCode < T::Enum
|
126
|
+
enums do
|
127
|
+
Unknown = new(1)
|
128
|
+
InvalidResponse = new(2)
|
129
|
+
Success = new(200)
|
130
|
+
InvalidRequest = new(400)
|
131
|
+
AuthRequired = new(401)
|
132
|
+
Forbidden = new(403)
|
133
|
+
XRPCNotSupported = new(404)
|
134
|
+
PayloadTooLarge = new(413)
|
135
|
+
RateLimitExceeded = new(429)
|
136
|
+
InternalServerError = new(500)
|
137
|
+
MethodNotImplemented = new(501)
|
138
|
+
UpstreamFailure = new(502)
|
139
|
+
NotEnoughResouces = new(503)
|
140
|
+
UpstreamTimeout = new(504)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/lib/at_protocol/session.rb
CHANGED
data/lib/at_protocol/version.rb
CHANGED
data/lib/at_protocol/writes.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# typed: true
|
2
2
|
module ATProto
|
3
|
+
extend T::Sig
|
4
|
+
|
3
5
|
class Writes < T::Struct
|
4
6
|
class Write < T::Struct
|
5
7
|
class Action < T::Enum
|
@@ -101,14 +103,13 @@ module ATProto
|
|
101
103
|
|
102
104
|
class << self
|
103
105
|
extend T::Sig
|
104
|
-
sig { params(block: Proc).returns(T::Array[Write]) }
|
105
|
-
|
106
|
-
def generate(&block)
|
107
|
-
Collector.new.instance_eval(&block)
|
108
|
-
end
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
109
|
+
def self.Writes(session, &block)
|
110
|
+
Writes.new(writes: Writes::Collector.new.instance_eval(&block), session: session, repo: Repo.new(session.did))
|
111
|
+
end
|
112
|
+
|
112
113
|
class Writes
|
113
114
|
class Collector
|
114
115
|
include RequestUtils
|
data/lib/at_protocol.rb
CHANGED
@@ -15,6 +15,18 @@ class Class
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
module ATProto
|
19
|
+
class << self
|
20
|
+
def method_missing(method_name, *args, &block)
|
21
|
+
if const_defined?(method_name)
|
22
|
+
Object.const_get(method_name).new(*args, &block)
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
18
30
|
require "skyfall/cid"
|
19
31
|
require "xrpc"
|
20
32
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: at_protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.
|
4
|
+
version: 0.0.4.2
|
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-09-
|
12
|
+
date: 2023-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: xrpc
|