-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
1
GEM
12
2
remote: https://rubygems.org/
13
3
specs:
14
-
addressable (2.8.7)
15
-
public_suffix (>= 2.0.2, < 7.0)
16
4
base64 (0.2.0)
17
-
bigdecimal (3.1.9)
18
-
buftok (0.3.0)
19
5
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
6
io-console (0.7.2)
39
7
json (2.10.2)
40
8
minisky (0.5.0)
41
9
base64 (~> 0.1)
42
10
net-http (0.4.1)
43
11
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
12
uri (0.13.2)
51
13
yaml (0.3.0)
52
14
···
60
22
didkit (~> 0.2)
61
23
io-console (~> 0.5)
62
24
json (~> 2.5)
63
-
mastodon-api!
64
25
minisky (~> 0.5)
65
26
net-http (~> 0.2)
66
27
uri (~> 0.13)
+6
-8
app/mastodon_account.rb
+6
-8
app/mastodon_account.rb
···
1
-
require 'mastodon'
2
1
require 'yaml'
3
-
4
2
require_relative 'mastodon_api'
5
3
6
4
class MastodonAccount
···
22
20
23
21
def oauth_login(handle)
24
22
instance = handle.split('@').last
25
-
app_response = register_oauth_app(instance, OAUTH_SCOPES)
23
+
app_response = register_oauth_app(instance)
26
24
27
25
api = MastodonAPI.new(instance)
28
26
29
-
login_url = api.generate_oauth_login_url(app_response.client_id, OAUTH_SCOPES)
27
+
login_url = api.generate_oauth_login_url(app_response['client_id'], OAUTH_SCOPES)
30
28
31
29
puts "Open this URL in your web browser and authorize the app:"
32
30
puts
···
38
36
print ">> "
39
37
code = STDIN.gets.chomp
40
38
41
-
json = api.complete_oauth_login(app_response.client_id, app_response.client_secret, code)
39
+
json = api.complete_oauth_login(app_response['client_id'], app_response['client_secret'], code)
42
40
43
41
api.access_token = json['access_token']
44
42
info = api.account_info
···
49
47
save_config
50
48
end
51
49
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)
50
+
def register_oauth_app(instance)
51
+
api = MastodonAPI.new(instance)
52
+
api.register_oauth_app(APP_NAME, OAUTH_SCOPES)
55
53
end
56
54
57
55
def post_status(text, media_ids = nil, parent_id = nil)
+10
app/mastodon_api.rb
+10
app/mastodon_api.rb
···
34
34
@access_token = access_token
35
35
end
36
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
+
37
47
def generate_oauth_login_url(client_id, scopes)
38
48
login_url = URI("https://#{@host}/oauth/authorize")
39
49