Class: Bskyrb::RecordManager
- Inherits:
-
Object
- Object
- Bskyrb::RecordManager
show all
- Includes:
- RequestUtils
- Defined in:
- lib/bskyrb/records.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#at_post_link, #create_record_uri, #default_authenticated_headers, #default_headers, #delete_record_uri, #get_author_feed_uri, #get_popular_uri, #get_post_thread_uri, #get_timeline_uri, #query_obj_to_query_params, #resolve_handle, #upload_blob_uri
Constructor Details
Returns a new instance of RecordManager.
7
8
9
|
# File 'lib/bskyrb/records.rb', line 7
def initialize(session)
@session = session
end
|
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
5
6
7
|
# File 'lib/bskyrb/records.rb', line 5
def session
@session
end
|
Instance Method Details
#block(username) ⇒ Object
139
140
141
|
# File 'lib/bskyrb/records.rb', line 139
def block(username)
profile_action(username, "app.bsky.graph.block")
end
|
#create_post(text) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/bskyrb/records.rb', line 56
def create_post(text)
input = Bskyrb::ComAtprotoRepoCreaterecord::CreateRecord::Input.from_hash({
"collection" => "app.bsky.feed.post",
"$type" => "app.bsky.feed.post",
"repo" => session.did,
"record" => {
"$type" => "app.bsky.feed.post",
"createdAt" => DateTime.now.iso8601(3),
"text" => text,
},
})
create_record(input)
end
|
#create_record(input) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/bskyrb/records.rb', line 36
def create_record(input)
unless input.is_a?(Hash) || input.class.name.include?("Input")
raise "`create_record` takes an Input class or a hash"
end
HTTParty.post(
create_record_uri(session.pds),
body: input.to_h.compact.to_json,
headers: (session),
)
end
|
#create_reply(replylink, text) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/bskyrb/records.rb', line 70
def create_reply(replylink, text)
reply_to = get_post_by_url(replylink)
input = Bskyrb::ComAtprotoRepoCreaterecord::CreateRecord::Input.from_hash({
"collection" => "app.bsky.feed.post",
"$type" => "app.bsky.feed.post",
"repo" => session.did,
"record" => {
"reply" => {
"parent" => {
"uri" => reply_to.uri,
"cid" => reply_to.cid,
},
"root" => {
"uri" => reply_to.uri,
"cid" => reply_to.cid,
},
},
"$type" => "app.bsky.feed.post",
"createdAt" => DateTime.now.iso8601(3),
"text" => text,
},
})
create_record(input)
end
|
#delete_record(collection, rkey) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/bskyrb/records.rb', line 47
def delete_record(collection, rkey)
data = { collection: collection, repo: session.did, rkey: rkey }
HTTParty.post(
delete_record_uri(session),
body: data.to_json,
headers: (session),
)
end
|
#follow(username) ⇒ Object
135
136
137
|
# File 'lib/bskyrb/records.rb', line 135
def follow(username)
profile_action(username, "app.bsky.graph.follow")
end
|
#get_latest_n_posts(username, n) ⇒ Object
#get_latest_post(username) ⇒ Object
143
144
145
146
|
# File 'lib/bskyrb/records.rb', line 143
def get_latest_post(username)
feed = get_latest_n_posts(username, 1)
feed.feed.first
end
|
#get_post_by_url(url, depth = 10) ⇒ Object
#hydrate_feed(response_hash, klass) ⇒ Object
#like(post_url) ⇒ Object
125
126
127
128
|
# File 'lib/bskyrb/records.rb', line 125
def like(post_url)
post = get_post_by_url(post_url)
post_action(post, "app.bsky.feed.like")
end
|
#post_action(post, action_type) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/bskyrb/records.rb', line 109
def post_action(post, action_type)
data = {
collection: action_type,
repo: session.did,
record: {
subject: {
uri: post.uri,
cid: post.cid,
},
createdAt: DateTime.now.iso8601(3),
"$type": action_type,
},
}
create_record(data)
end
|
#profile_action(username, type) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/bskyrb/records.rb', line 96
def profile_action(username, type)
input = Bskyrb::ComAtprotoRepoCreaterecord::CreateRecord::Input.from_hash({
"collection" => type,
"repo" => session.did,
"record" => {
"subject" => resolve_handle(session.pds, username)["did"],
"createdAt" => DateTime.now.iso8601(3),
"$type" => type,
},
})
create_record(input)
end
|
#repost(post_url) ⇒ Object
130
131
132
133
|
# File 'lib/bskyrb/records.rb', line 130
def repost(post_url)
post = get_post_by_url(post_url)
post_action(post, "app.bsky.feed.repost")
end
|
#upload_blob(blob_path, content_type) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/bskyrb/records.rb', line 26
def upload_blob(blob_path, content_type)
image_bytes = File.binread(blob_path)
HTTParty.post(
upload_blob_uri(session.pds),
body: image_bytes,
headers: (session),
)
end
|