Atmosfire 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/atmosfire/at_uri.rb +18 -24
- data/lib/atmosfire/collection.rb +12 -9
- data/lib/atmosfire/record.rb +18 -12
- data/lib/atmosfire/repo.rb +16 -1
- data/lib/atmosfire/requests.rb +1 -4
- data/lib/atmosfire/session.rb +0 -2
- data/lib/atmosfire/version.rb +2 -1
- data/lib/atmosfire.rb +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83cc1ffc021213e0fc91521cedcb674b095521c8d426ec78736b8729511cc763
|
4
|
+
data.tar.gz: 48b36faf67694ee803c68c21e30f411e125b1b265edc7eba14bf9c5fc35f83f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b11ff02dd2a66ae2f6dbc441646e8c004336aa5c3ba1feedf0931e68f951ebb87d4f2e9feaf6931485666ae0e4f49c286d8b7b39119fa6069f5bfe198845768e
|
7
|
+
data.tar.gz: 5cb83d2bdce1178192334682cca26954744f8f9d7afaa117d5dc86eb39c6c30d9011846d4bea81362f680378091ea20d2e24989a4b68c96b08cc89ddd231d38b
|
data/lib/atmosfire/at_uri.rb
CHANGED
@@ -8,19 +8,7 @@ module Atmosfire
|
|
8
8
|
sig { params(url: String, atp_host: String).returns(T.nilable(AtUri)) }
|
9
9
|
|
10
10
|
def at_uri(url, atp_host = "https://bsky.social")
|
11
|
-
|
12
|
-
AtUriParser.create_rule(%r{^#{Regexp.escape("https://")}(bsky\.app)/profile/(.+)/post/([\w]+)$}) do |handle, collection, rkey, pds|
|
13
|
-
handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds)
|
14
|
-
AtUri.new(did, "app.bsky.feed.post", rkey)
|
15
|
-
end,
|
16
|
-
|
17
|
-
AtUriParser.create_rule(%r{^at://(.+)/(.+)/(\w+)$}) do |handle, collection, rkey, pds|
|
18
|
-
handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds)
|
19
|
-
AtUri.new(did, collection, rkey)
|
20
|
-
end,
|
21
|
-
|
22
|
-
]
|
23
|
-
AtUriParser.parse(url, rulesets, pds: atp_host)
|
11
|
+
AtUriParser.parse(url, AtUriParser::RuleSets, pds: atp_host)
|
24
12
|
end
|
25
13
|
end
|
26
14
|
end
|
@@ -28,6 +16,8 @@ end
|
|
28
16
|
module Atmosfire
|
29
17
|
module AtUriParser
|
30
18
|
extend T::Sig
|
19
|
+
include RequestUtils
|
20
|
+
|
31
21
|
Rule = Struct.new(:pattern, :transform)
|
32
22
|
|
33
23
|
sig { params(url: String, rulesets: T::Array[Rule], pds: String).returns(T.nilable(AtUri)) }
|
@@ -49,20 +39,24 @@ module Atmosfire
|
|
49
39
|
end
|
50
40
|
Rule.new(pattern, transform)
|
51
41
|
end
|
42
|
+
RuleSets = [
|
43
|
+
AtUriParser.create_rule(%r{^#{Regexp.escape("https://")}(bsky\.app)/profile/(.+)/post/([\w]+)$}) do |handle, collection, rkey, pds|
|
44
|
+
handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds)
|
45
|
+
AtUri.new(repo: did, collection: "app.bsky.feed.post", rkey: rkey)
|
46
|
+
end,
|
47
|
+
|
48
|
+
AtUriParser.create_rule(%r{^at://(.+)/(.+)/(\w+)$}) do |handle, collection, rkey, pds|
|
49
|
+
handle.start_with?("did:") ? did = handle : did = resolve_handle(handle, pds)
|
50
|
+
AtUri.new(repo: did, collection: collection, rkey: rkey)
|
51
|
+
end,
|
52
|
+
]
|
52
53
|
end
|
53
54
|
|
54
|
-
AtUri
|
55
|
+
class AtUri < T::Struct
|
55
56
|
extend T::Sig
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
parts = args[0].split("/")
|
60
|
-
repo, collection, rkey = parts[2], parts[3], parts[4]
|
61
|
-
elsif args.count == 3
|
62
|
-
repo, collection, rkey = args
|
63
|
-
end
|
64
|
-
super(repo, collection, rkey)
|
65
|
-
end
|
57
|
+
const :repo, T.any(Atmosfire::Repo, String)
|
58
|
+
const :collection, T.nilable(T.any(Atmosfire::Repo::Collection, String))
|
59
|
+
const :rkey, T.nilable(String)
|
66
60
|
|
67
61
|
sig { returns(String) }
|
68
62
|
|
data/lib/atmosfire/collection.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
2
|
module Atmosfire
|
3
3
|
class Repo
|
4
|
-
Collection
|
4
|
+
class Collection < T::Struct
|
5
5
|
include RequestUtils
|
6
6
|
extend T::Sig
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(repo, lexicon_name)
|
11
|
-
super(repo, lexicon_name)
|
12
|
-
end
|
8
|
+
const(:repo, Atmosfire::Repo)
|
9
|
+
const(:collection, String)
|
13
10
|
|
14
11
|
sig { params(limit: Integer).returns(T::Array[Atmosfire::Record]) }
|
15
12
|
|
16
|
-
def
|
13
|
+
def list(limit = 10)
|
17
14
|
self.repo.pds_endpoint
|
18
15
|
.get.com_atproto_repo_listRecords(
|
19
16
|
repo: self.repo.did,
|
@@ -27,10 +24,16 @@ module Atmosfire
|
|
27
24
|
|
28
25
|
sig { returns(String) }
|
29
26
|
|
30
|
-
def
|
27
|
+
def to_uri
|
31
28
|
"at://#{self.repo.did}/#{self.collection}"
|
32
29
|
end
|
33
30
|
|
31
|
+
sig { returns(String) }
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
@collection
|
35
|
+
end
|
36
|
+
|
34
37
|
sig { params(rkey: String).returns(T.nilable(Atmosfire::Record)) }
|
35
38
|
|
36
39
|
def [](rkey)
|
data/lib/atmosfire/record.rb
CHANGED
@@ -4,24 +4,32 @@ module Atmosfire
|
|
4
4
|
extend T::Sig
|
5
5
|
class << self
|
6
6
|
extend T::Sig
|
7
|
+
include RequestUtils
|
7
8
|
|
8
9
|
sig { params(json_hash: Hash).returns(T.nilable(Atmosfire::Record)) }
|
9
10
|
|
10
11
|
def from_hash(json_hash)
|
12
|
+
return nil if json_hash["value"].nil?
|
11
13
|
timestamp = nil
|
12
|
-
timestamp = Time.parse json_hash["value"]["createdAt"] if json_hash["value"]["createdAt"]
|
14
|
+
timestamp = Time.parse json_hash["value"]["createdAt"] if json_hash["value"] && json_hash["value"]["createdAt"]
|
13
15
|
raw_content = json_hash["value"]
|
14
|
-
new(
|
16
|
+
new(
|
17
|
+
at_uri(
|
18
|
+
T.must(json_hash["uri"])
|
19
|
+
),
|
20
|
+
json_hash["cid"],
|
21
|
+
timestamp, raw_content
|
22
|
+
)
|
15
23
|
end
|
16
24
|
|
17
25
|
sig { params(uri: Atmosfire::AtUri, pds: String).returns(T.nilable(Atmosfire::Record)) }
|
18
26
|
|
19
27
|
def from_uri(uri, pds = "https://bsky.social")
|
20
|
-
|
21
|
-
repo: uri.repo,
|
22
|
-
collection: uri.collection,
|
28
|
+
from_hash(XRPC::Client.new(pds).get.com_atproto_repo_getRecord(
|
29
|
+
repo: uri.repo.to_s,
|
30
|
+
collection: "#{uri.collection}",
|
23
31
|
rkey: uri.rkey,
|
24
|
-
)
|
32
|
+
))
|
25
33
|
end
|
26
34
|
|
27
35
|
sig { params(content_hash: Hash, session: Atmosfire::Session, rkey: T.nilable(String)).returns(T.nilable(Atmosfire::Record)) }
|
@@ -29,19 +37,17 @@ module Atmosfire
|
|
29
37
|
def create(content_hash, session, rkey = nil)
|
30
38
|
return nil if content_hash["$type"].nil?
|
31
39
|
if rkey.nil?
|
32
|
-
|
40
|
+
from_uri(at_uri(session.xrpc.post.com_atproto_repo_createRecord(
|
33
41
|
repo: session.did,
|
34
42
|
collection: content_hash["$type"],
|
35
43
|
record: content_hash,
|
36
|
-
)["uri"])
|
37
|
-
|
38
|
-
else rec = from_uri(session.xrpc.post.com_atproto_repo_createRecord(
|
44
|
+
)["uri"]))
|
45
|
+
else from_uri(at_uri(session.xrpc.post.com_atproto_repo_createRecord(
|
39
46
|
repo: session.did,
|
40
47
|
collection: content_hash["$type"],
|
41
48
|
rkey: rkey,
|
42
49
|
record: content_hash,
|
43
|
-
)["uri"])
|
44
|
-
return rec; end
|
50
|
+
)["uri"])) end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
data/lib/atmosfire/repo.rb
CHANGED
@@ -6,6 +6,11 @@ class Atmosfire::Repo
|
|
6
6
|
|
7
7
|
sig { params(username: String, pds: String, open: T::Boolean, authenticate: T.nilable(Atmosfire::Session)).void }
|
8
8
|
|
9
|
+
# @param username [String] The username or DID (Decentralized Identifier) to use.
|
10
|
+
# @param pds [String] The URL of the personal data server (default: "https://bsky.social").
|
11
|
+
# @param open [Boolean] Whether to open the repository or not (default: true).
|
12
|
+
# @param authenticate [NilClass, Object] Additional authentication data (default: nil).
|
13
|
+
|
9
14
|
def initialize(username, pds = "https://bsky.social", open: true, authenticate: nil)
|
10
15
|
@pds = pds
|
11
16
|
@pds_endpoint = XRPC::Client.new(pds)
|
@@ -24,6 +29,16 @@ class Atmosfire::Repo
|
|
24
29
|
@collections = describe_repo["collections"]
|
25
30
|
end
|
26
31
|
|
32
|
+
sig { returns(String) }
|
33
|
+
|
34
|
+
def to_uri
|
35
|
+
"at://#{@did}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
@did
|
40
|
+
end
|
41
|
+
|
27
42
|
sig { returns(Hash) }
|
28
43
|
|
29
44
|
def describe_repo
|
@@ -39,7 +54,7 @@ class Atmosfire::Repo
|
|
39
54
|
sig { params(collection: String).returns(Atmosfire::Repo::Collection) }
|
40
55
|
|
41
56
|
def [](collection)
|
42
|
-
Collection.new(self, collection)
|
57
|
+
Collection.new(repo: self, collection: collection)
|
43
58
|
end
|
44
59
|
|
45
60
|
attr_reader :did, :record_list, :pds, :pds_endpoint
|
data/lib/atmosfire/requests.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# typed: true
|
1
2
|
module Atmosfire
|
2
3
|
class Error < StandardError; end
|
3
4
|
|
@@ -38,10 +39,6 @@ module Atmosfire
|
|
38
39
|
"#{pds}/xrpc/com.atproto.server.getSession"
|
39
40
|
end
|
40
41
|
|
41
|
-
def create_record_uri(pds)
|
42
|
-
"#{pds}/xrpc/com.atproto.repo.createRecord"
|
43
|
-
end
|
44
|
-
|
45
42
|
def delete_record_uri(pds)
|
46
43
|
"#{pds}/xrpc/com.atproto.repo.deleteRecord"
|
47
44
|
end
|
data/lib/atmosfire/session.rb
CHANGED
data/lib/atmosfire/version.rb
CHANGED
data/lib/atmosfire.rb
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
require "sorbet-runtime"
|
4
4
|
require "xrpc"
|
5
|
-
require "atmosfire/
|
5
|
+
require "atmosfire/requests"
|
6
6
|
require "atmosfire/session"
|
7
7
|
require "atmosfire/collection"
|
8
8
|
require "atmosfire/repo"
|
9
9
|
require "atmosfire/record"
|
10
|
+
require "atmosfire/at_uri"
|