Browse Source

Fix registration

master
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 @@
/Gemfile.lock
/vendor/bundle/

+ 19
- 0
bin/feed-stdout View File

@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
require 'dotenv/load'
require 'cross-post'
require 'awesome_print'
require 'securerandom'

class ::Twitter::REST::Client
def upload(*args, **kargs)
ap type: :upload, args: args, kargs: kargs
SecureRandom.uuid
end

def update(*args, **kargs)
ap type: :update, args: args, kargs: kargs
SecureRandom.uuid
end
end

CrossPost.feed

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

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

+ 28
- 9
bin/mastodon-register View File

@@ -6,29 +6,48 @@ require 'launchy'
require 'uri'

config = CrossPost::Config.new
print 'Mastodon URL ? '
url = gets.chomp
url = "https://#{url}" if URI.parse(url).class == URI::Generic
config['mastodon.url'] = url
settings = config[:settings]

client_id, client_secret = unless config['mastodon.consumer']
url = settings['mastodon.url']
unless url
print 'Mastodon URL ? '
url = gets.chomp
url = "https://#{url}" if URI.parse(url).class == URI::Generic
settings['mastodon.url'] = url
end

user = settings['mastodon.user']
unless user
print 'Mastodon username ? '
user = gets.chomp
settings['mastodon.user'] = user
end

client_id, client_secret = unless settings['mastodon.consumer']
puts 'Creating new app'
token = SecureRandom.hex 64
redirect_url = 'urn:ietf:wg:oauth:2.0:oob'

client = Mastodon::REST::Client.new base_url: url, bearer_token: token
app = client.create_app 'CrossPost', redirect_url,
'read write', 'https://git.imirhil.fr/aeris/cross-post/'
settings['mastodon.consumer.key'] = app.client_id
settings['mastodon.consumer.secret'] = app.client_secret
[app.client_id, app.client_secret]
else
[config['mastodon.consumer.key'], config['mastodon.consumer.secret']]
[settings['mastodon.consumer.key'], settings['mastodon.consumer.secret']]
end

client = OAuth2::Client.new client_id, client_secret, site: url
url = client.auth_code.authorize_url redirect_uri: redirect_url
Launchy.open url
puts url
begin
Launchy.open url
rescue
end

print 'Token ? '
token = gets.chomp
config['mastodon.token'] = token
settings['mastodon.token'] = token

config.save
settings.save

+ 28
- 0
bin/replay View File

@@ -0,0 +1,28 @@
#!/usr/bin/env ruby
require 'cross-post'
require 'awesome_print'

class Twitter::REST::Client
def update(*args, **kargs)
ap args
ap kargs
0
end
end

config = CrossPost::Config.new
url = config['mastodon.url']
token = config['mastodon.token']
client = ::Mastodon::REST::Client.new base_url: url, bearer_token: token
status = client.status 439490
ap status

twitter = CrossPost::Twitter.new config
twitter.post_status status

# media = '/home/aeris/Images/tux-debian.png'
# media = client.upload_media media
# status = client.create_status 'Test', nil, [media.id]
# ap status
# sleep 5
# client.destroy_status status.id

+ 15
- 0
bin/send-test View File

@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
require 'cross-post'
require 'awesome_print'

config = CrossPost::Config.new
url = config['mastodon.url']
token = config['mastodon.token']
client = ::Mastodon::REST::Client.new base_url: url, bearer_token: token

media = '/home/aeris/Images/tux-debian.png'
media = client.upload_media media
status = client.create_status 'Test', nil, [media.id]
ap status
sleep 5
client.destroy_status status.id

+ 3
- 0
bin/send-twitter View File

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

+ 10
- 6
bin/twitter-register View File

@@ -6,9 +6,10 @@ require 'launchy'
require 'awesome_print'

config = CrossPost::Config.new
settings = config[:settings]

consumer_key = config['twitter.consumer.key']
consumer_secret = config['twitter.consumer.secret']
consumer_key = settings['twitter.consumer.key']
consumer_secret = settings['twitter.consumer.secret']

client = OAuth::Consumer.new consumer_key,
consumer_secret,
@@ -16,15 +17,18 @@ client = OAuth::Consumer.new consumer_key,
request_token = client.get_request_token
url = request_token.authorize_url
puts url
Launchy.open url
begin
Launchy.open url
rescue
end

print 'PIN ? '
pin = gets.chomp

access_token = request_token.get_access_token oauth_verifier: pin

config['twitter.access.token'] = access_token.token
config['twitter.access.secret'] = access_token.secret
settings['twitter.access.token'] = access_token.token
settings['twitter.access.secret'] = access_token.secret

config.save
settings.save


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

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

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

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

Loading…
Cancel
Save