Browse Source

Fix registration

aeris 1 year ago
parent
commit
9cf70a74ba
10 changed files with 109 additions and 18 deletions
  1. 1
    1
      .gitignore
  2. 19
    0
      bin/feed-stdout
  3. 3
    0
      bin/feed-twitter-debug
  4. 28
    9
      bin/mastodon-register
  5. 28
    0
      bin/replay
  6. 15
    0
      bin/send-test
  7. 3
    0
      bin/send-twitter
  8. 10
    6
      bin/twitter-register
  9. 1
    1
      lib/cross-post/config.rb
  10. 1
    1
      lib/cross-post/version.rb

+ 1
- 1
.gitignore View File

@@ -1 +1 @@
1
-/Gemfile.lock
1
+/vendor/bundle/

+ 19
- 0
bin/feed-stdout View File

@@ -0,0 +1,19 @@
1
+#!/usr/bin/env ruby
2
+require 'dotenv/load'
3
+require 'cross-post'
4
+require 'awesome_print'
5
+require 'securerandom'
6
+
7
+class ::Twitter::REST::Client
8
+	def upload(*args, **kargs)
9
+		ap type: :upload, args: args, kargs: kargs
10
+		SecureRandom.uuid
11
+	end
12
+
13
+	def update(*args, **kargs)
14
+		ap type: :update, args: args, kargs: kargs
15
+		SecureRandom.uuid
16
+	end
17
+end
18
+
19
+CrossPost.feed

+ 3
- 0
bin/feed-twitter-debug View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env ruby
2
+require 'cross-post'
3
+CrossPost.feed

+ 28
- 9
bin/mastodon-register View File

@@ -6,29 +6,48 @@ require 'launchy'
6 6
 require 'uri'
7 7
 
8 8
 config = CrossPost::Config.new
9
-print 'Mastodon URL ? '
10
-url                    = gets.chomp
11
-url = "https://#{url}" if URI.parse(url).class == URI::Generic
12
-config['mastodon.url'] = url
9
+settings = config[:settings]
13 10
 
14
-client_id, client_secret = unless config['mastodon.consumer']
11
+url = settings['mastodon.url']
12
+unless url
13
+	print 'Mastodon URL ? '
14
+	url                    = gets.chomp
15
+	url = "https://#{url}" if URI.parse(url).class == URI::Generic
16
+	settings['mastodon.url'] = url
17
+end
18
+
19
+user = settings['mastodon.user']
20
+unless user
21
+	print 'Mastodon username ? '
22
+	user                    = gets.chomp
23
+	settings['mastodon.user'] = user
24
+end
25
+
26
+client_id, client_secret = unless settings['mastodon.consumer']
27
+							   puts 'Creating new app'
15 28
 							   token        = SecureRandom.hex 64
16 29
 							   redirect_url = 'urn:ietf:wg:oauth:2.0:oob'
17 30
 
18 31
 							   client = Mastodon::REST::Client.new base_url: url, bearer_token: token
19 32
 							   app    = client.create_app 'CrossPost', redirect_url,
20 33
 														  'read write', 'https://git.imirhil.fr/aeris/cross-post/'
34
+							   settings['mastodon.consumer.key'] = app.client_id
35
+							   settings['mastodon.consumer.secret'] = app.client_secret
21 36
 							   [app.client_id, app.client_secret]
22 37
 						   else
23
-							   [config['mastodon.consumer.key'], config['mastodon.consumer.secret']]
38
+							   [settings['mastodon.consumer.key'], settings['mastodon.consumer.secret']]
24 39
 						   end
25 40
 
26 41
 client = OAuth2::Client.new client_id, client_secret, site: url
27 42
 url    = client.auth_code.authorize_url redirect_uri: redirect_url
28
-Launchy.open url
43
+puts url
44
+begin
45
+	Launchy.open url
46
+rescue
47
+end
29 48
 
30 49
 print 'Token ? '
31 50
 token                    = gets.chomp
32
-config['mastodon.token'] = token
51
+settings['mastodon.token'] = token
33 52
 
34
-config.save
53
+settings.save

+ 28
- 0
bin/replay View File

@@ -0,0 +1,28 @@
1
+#!/usr/bin/env ruby
2
+require 'cross-post'
3
+require 'awesome_print'
4
+
5
+class Twitter::REST::Client
6
+	def update(*args, **kargs)
7
+		ap args
8
+		ap kargs
9
+		0
10
+	end
11
+end
12
+
13
+config = CrossPost::Config.new
14
+url       = config['mastodon.url']
15
+token     = config['mastodon.token']
16
+client   = ::Mastodon::REST::Client.new base_url: url, bearer_token: token
17
+status = client.status 439490
18
+ap status
19
+
20
+twitter = CrossPost::Twitter.new config
21
+twitter.post_status status
22
+
23
+# media = '/home/aeris/Images/tux-debian.png'
24
+# media = client.upload_media media
25
+# status = client.create_status 'Test', nil, [media.id]
26
+# ap status
27
+# sleep 5
28
+# client.destroy_status status.id

+ 15
- 0
bin/send-test View File

@@ -0,0 +1,15 @@
1
+#!/usr/bin/env ruby
2
+require 'cross-post'
3
+require 'awesome_print'
4
+
5
+config = CrossPost::Config.new
6
+url       = config['mastodon.url']
7
+token     = config['mastodon.token']
8
+client   = ::Mastodon::REST::Client.new base_url: url, bearer_token: token
9
+
10
+media = '/home/aeris/Images/tux-debian.png'
11
+media = client.upload_media media
12
+status = client.create_status 'Test', nil, [media.id]
13
+ap status
14
+sleep 5
15
+client.destroy_status status.id

+ 3
- 0
bin/send-twitter View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env ruby
2
+require 'cross-post'
3
+CrossPost.new.twitter.post File.read ARGV[0]

+ 10
- 6
bin/twitter-register View File

@@ -6,9 +6,10 @@ require 'launchy'
6 6
 require 'awesome_print'
7 7
 
8 8
 config = CrossPost::Config.new
9
+settings = config[:settings]
9 10
 
10
-consumer_key    = config['twitter.consumer.key']
11
-consumer_secret = config['twitter.consumer.secret']
11
+consumer_key    = settings['twitter.consumer.key']
12
+consumer_secret = settings['twitter.consumer.secret']
12 13
 
13 14
 client        = OAuth::Consumer.new consumer_key,
14 15
 									consumer_secret,
@@ -16,15 +17,18 @@ client        = OAuth::Consumer.new consumer_key,
16 17
 request_token = client.get_request_token
17 18
 url           = request_token.authorize_url
18 19
 puts url
19
-Launchy.open url
20
+begin
21
+	Launchy.open url
22
+rescue
23
+end
20 24
 
21 25
 print 'PIN ? '
22 26
 pin = gets.chomp
23 27
 
24 28
 access_token = request_token.get_access_token oauth_verifier: pin
25 29
 
26
-config['twitter.access.token']  = access_token.token
27
-config['twitter.access.secret'] = access_token.secret
30
+settings['twitter.access.token']  = access_token.token
31
+settings['twitter.access.secret'] = access_token.secret
28 32
 
29
-config.save
33
+settings.save
30 34
 

+ 1
- 1
lib/cross-post/config.rb View File

@@ -113,7 +113,7 @@ class CrossPost
113 113
 		def load(name, file = nil)
114 114
 			file ||= "#{name}.yml"
115 115
 			file = File.join @dir, file
116
-			FileUtils.touch file unless File.exist? file
116
+			File.write(file, YAML.dump({})) unless File.exist? file
117 117
 			self[name] = FileSubConfig.new file
118 118
 		end
119 119
 	end

+ 1
- 1
lib/cross-post/version.rb View File

@@ -1,3 +1,3 @@
1 1
 class CrossPost
2
-	VERSION = '0.2.0'.freeze
2
+	VERSION = '0.2.1'.freeze
3 3
 end

Loading…
Cancel
Save