bskyrb 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/bskyrb.rb +53 -14
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3ecd9b24a2ae044cfcc5ff1825f0f28f903089f62e6961b2c4404e1b24864c
|
4
|
+
data.tar.gz: e171427efd25ba3cc22e8deb0c3e1819c6bc0b3131d985a367e4349c77b905bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d1ad04723d948e14e63fdbefcb902bb81448707018a1d8bf0344ec5aac46176bc1db5fc482f267456eaf0b7adf8daf116adff1e29496975ba106ce6974c15a
|
7
|
+
data.tar.gz: d6eeb0e934ef49a29f58ea4eaba92d131b4c37f6277bc6becbe390f96f9797fd0617a2d163070ac117de38ec0eafdddeba8410ccd720f172aad16af8e79a2342
|
data/lib/bskyrb.rb
CHANGED
@@ -3,20 +3,22 @@
|
|
3
3
|
# require_relative "bskyrb/version"
|
4
4
|
require 'json'
|
5
5
|
require 'net/http'
|
6
|
+
require 'httparty'
|
6
7
|
require 'date'
|
7
8
|
module ATProto
|
8
9
|
class Session
|
9
|
-
def initialize(username, password)
|
10
|
-
@atp_host =
|
10
|
+
def initialize(username, password, pds)
|
11
|
+
@atp_host = pds
|
11
12
|
@atp_auth_token = ""
|
12
13
|
@did = ""
|
13
14
|
@username = username
|
14
|
-
|
15
|
+
# headers = { "Content-Type" => "application/json" }
|
15
16
|
data = { "identifier" => username, "password" => password }.to_json
|
16
17
|
|
17
18
|
uri = URI("#{@atp_host}/xrpc/com.atproto.server.createSession")
|
18
19
|
response = Net::HTTP.post(uri, data, 'Content-Type' => 'application/json')
|
19
|
-
|
20
|
+
# response = HTTParty.post(uri, body: data.to_json, headers: {'Content-Type' => 'application/json'} )
|
21
|
+
|
20
22
|
parsed_response = JSON.parse(response.body)
|
21
23
|
|
22
24
|
@atp_auth_token = parsed_response['accessJwt']
|
@@ -28,19 +30,17 @@ module ATProto
|
|
28
30
|
@did = parsed_response['did']
|
29
31
|
end
|
30
32
|
def getdid()
|
31
|
-
|
33
|
+
return @did
|
32
34
|
end
|
33
35
|
|
34
|
-
def resolveHandle(username)
|
35
|
-
headers = { "Authorization" => "Bearer #{@atp_auth_token}" }
|
36
|
-
|
37
|
-
|
38
|
-
response
|
39
|
-
|
40
|
-
return response
|
36
|
+
def resolveHandle(username)
|
37
|
+
headers = { "Authorization" => "Bearer #{@atp_auth_token}", "Content-Type" => "application/json" }
|
38
|
+
response = HTTParty.get("#{@atp_host}/xrpc/com.atproto.identity.resolveHandle?handle=#{username}", headers: headers)
|
39
|
+
|
40
|
+
return response.body
|
41
41
|
end
|
42
42
|
def get_skoot_by_url(url)
|
43
|
-
headers = { "Authorization" => "Bearer #{@atp_auth_token}" }
|
43
|
+
headers = { "Authorization" => "Bearer #{@atp_auth_token}", "Content-Type" => "application/json" }
|
44
44
|
|
45
45
|
username_of_person_in_link = url.split('/')[-3]
|
46
46
|
did_of_person_in_link = JSON.parse(resolveHandle(username_of_person_in_link))['did']
|
@@ -48,12 +48,49 @@ module ATProto
|
|
48
48
|
|
49
49
|
uri = "at://#{did_of_person_in_link}/app.bsky.feed.post/#{url_identifier}"
|
50
50
|
|
51
|
-
response =
|
51
|
+
response = HTTParty.get("#{@atp_host}/xrpc/app.bsky.feed.getPostThread?uri=#{uri}", headers: headers)
|
52
52
|
|
53
53
|
return response
|
54
54
|
end
|
55
55
|
|
56
|
+
def uploadBlob(blob_path, content_type)
|
57
|
+
headers = { "Authorization" => "Bearer #{@atp_auth_token}", "Content-Type" => content_type }
|
58
|
+
image_bytes = File.binread(blob_path)
|
59
|
+
|
60
|
+
uri = URI("#{@atp_host}/xrpc/com.atproto.repo.uploadBlob")
|
61
|
+
response = HTTParty.post("#{@atp_host}/xrpc/com.atproto.repo.uploadBlob", body: image_bytes, headers: headers)
|
62
|
+
|
63
|
+
return response
|
64
|
+
end
|
56
65
|
|
66
|
+
|
67
|
+
def post(postcontent)
|
68
|
+
timestamp = DateTime.now.iso8601(3)
|
69
|
+
headers = { "Authorization" => "Bearer #{@atp_auth_token}", "Content-Type" => "application/json" }
|
70
|
+
|
71
|
+
data = {
|
72
|
+
"collection" => "app.bsky.feed.post",
|
73
|
+
"$type" => "app.bsky.feed.post",
|
74
|
+
"repo" => "#{@did}",
|
75
|
+
"record" => {
|
76
|
+
"$type" => "app.bsky.feed.post",
|
77
|
+
"createdAt" => timestamp,
|
78
|
+
"text" => postcontent
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
uri = URI("#{@atp_host}/xrpc/com.atproto.repo.createRecord")
|
83
|
+
|
84
|
+
|
85
|
+
resp = HTTParty.post(
|
86
|
+
uri,
|
87
|
+
body: data.to_json,
|
88
|
+
headers: headers
|
89
|
+
)
|
90
|
+
# response = Net::HTTP.post(uri, data.to_json, headers)
|
91
|
+
return resp
|
92
|
+
end
|
93
|
+
|
57
94
|
def method_missing(method_name, *args)
|
58
95
|
message = "You called #{method_name} with #{args}. This method doesn't exist."
|
59
96
|
|
@@ -62,3 +99,5 @@ def method_missing(method_name, *args)
|
|
62
99
|
end
|
63
100
|
end
|
64
101
|
end
|
102
|
+
|
103
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bskyrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shreyan Jain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A script for interacting with bsky/atproto
|
56
70
|
email:
|
57
71
|
- shreyan.jain.9@outlook.com
|
@@ -79,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
93
|
- !ruby/object:Gem::Version
|
80
94
|
version: '0'
|
81
95
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.3.20
|
83
97
|
signing_key:
|
84
98
|
specification_version: 4
|
85
99
|
summary: Interact with bsky/atproto using Ruby
|