-1
Gemfile
-1
Gemfile
-39
Gemfile.lock
-39
Gemfile.lock
···
1
-
GIT
2
-
remote: https://github.com/mastodon/mastodon-api.git
3
-
revision: 60b0ed09c3b979cbeb833db0a320b30e1b022a1e
4
-
specs:
5
-
mastodon-api (2.0.0)
6
-
addressable (~> 2.6)
7
-
buftok (~> 0)
8
-
http (~> 4.0)
9
-
oj (~> 3.7)
10
-
11
GEM
12
remote: https://rubygems.org/
13
specs:
14
-
addressable (2.8.7)
15
-
public_suffix (>= 2.0.2, < 7.0)
16
base64 (0.2.0)
17
-
bigdecimal (3.1.9)
18
-
buftok (0.3.0)
19
didkit (0.2.3)
20
-
domain_name (0.6.20240107)
21
-
ffi (1.17.1)
22
-
ffi (1.17.1-aarch64-linux-gnu)
23
-
ffi (1.17.1-arm64-darwin)
24
-
ffi (1.17.1-x86_64-linux-gnu)
25
-
ffi-compiler (1.3.2)
26
-
ffi (>= 1.15.5)
27
-
rake
28
-
http (4.4.1)
29
-
addressable (~> 2.3)
30
-
http-cookie (~> 1.0)
31
-
http-form_data (~> 2.2)
32
-
http-parser (~> 1.2.0)
33
-
http-cookie (1.0.5)
34
-
domain_name (~> 0.5)
35
-
http-form_data (2.3.0)
36
-
http-parser (1.2.3)
37
-
ffi-compiler (>= 1.0, < 2.0)
38
io-console (0.7.2)
39
json (2.10.2)
40
minisky (0.5.0)
41
base64 (~> 0.1)
42
net-http (0.4.1)
43
uri
44
-
oj (3.16.9)
45
-
bigdecimal (>= 3.0)
46
-
ostruct (>= 0.2)
47
-
ostruct (0.6.1)
48
-
public_suffix (6.0.1)
49
-
rake (13.2.1)
50
uri (0.13.2)
51
yaml (0.3.0)
52
···
60
didkit (~> 0.2)
61
io-console (~> 0.5)
62
json (~> 2.5)
63
-
mastodon-api!
64
minisky (~> 0.5)
65
net-http (~> 0.2)
66
uri (~> 0.13)
···
1
GEM
2
remote: https://rubygems.org/
3
specs:
4
base64 (0.2.0)
5
didkit (0.2.3)
6
io-console (0.7.2)
7
json (2.10.2)
8
minisky (0.5.0)
9
base64 (~> 0.1)
10
net-http (0.4.1)
11
uri
12
uri (0.13.2)
13
yaml (0.3.0)
14
···
22
didkit (~> 0.2)
23
io-console (~> 0.5)
24
json (~> 2.5)
25
minisky (~> 0.5)
26
net-http (~> 0.2)
27
uri (~> 0.13)
+6
-8
app/mastodon_account.rb
+6
-8
app/mastodon_account.rb
···
1
-
require 'mastodon'
2
require 'yaml'
3
-
4
require_relative 'mastodon_api'
5
6
class MastodonAccount
···
22
23
def oauth_login(handle)
24
instance = handle.split('@').last
25
-
app_response = register_oauth_app(instance, OAUTH_SCOPES)
26
27
api = MastodonAPI.new(instance)
28
29
-
login_url = api.generate_oauth_login_url(app_response.client_id, OAUTH_SCOPES)
30
31
puts "Open this URL in your web browser and authorize the app:"
32
puts
···
38
print ">> "
39
code = STDIN.gets.chomp
40
41
-
json = api.complete_oauth_login(app_response.client_id, app_response.client_secret, code)
42
43
api.access_token = json['access_token']
44
info = api.account_info
···
49
save_config
50
end
51
52
-
def register_oauth_app(instance, scopes)
53
-
client = Mastodon::REST::Client.new(base_url: "https://#{instance}")
54
-
client.create_app(APP_NAME, MastodonAPI::CODE_REDIRECT_URI, scopes)
55
end
56
57
def post_status(text, media_ids = nil, parent_id = nil)
···
1
require 'yaml'
2
require_relative 'mastodon_api'
3
4
class MastodonAccount
···
20
21
def oauth_login(handle)
22
instance = handle.split('@').last
23
+
app_response = register_oauth_app(instance)
24
25
api = MastodonAPI.new(instance)
26
27
+
login_url = api.generate_oauth_login_url(app_response['client_id'], OAUTH_SCOPES)
28
29
puts "Open this URL in your web browser and authorize the app:"
30
puts
···
36
print ">> "
37
code = STDIN.gets.chomp
38
39
+
json = api.complete_oauth_login(app_response['client_id'], app_response['client_secret'], code)
40
41
api.access_token = json['access_token']
42
info = api.account_info
···
47
save_config
48
end
49
50
+
def register_oauth_app(instance)
51
+
api = MastodonAPI.new(instance)
52
+
api.register_oauth_app(APP_NAME, OAUTH_SCOPES)
53
end
54
55
def post_status(text, media_ids = nil, parent_id = nil)
+10
app/mastodon_api.rb
+10
app/mastodon_api.rb
···
34
@access_token = access_token
35
end
36
37
+
def register_oauth_app(app_name, scopes)
38
+
params = {
39
+
client_name: app_name,
40
+
redirect_uris: CODE_REDIRECT_URI,
41
+
scopes: scopes
42
+
}
43
+
44
+
post_json("https://#{@host}/api/v1/apps", params)
45
+
end
46
+
47
def generate_oauth_login_url(client_id, scopes)
48
login_url = URI("https://#{@host}/oauth/authorize")
49