Compare commits

...

2 Commits

Author SHA1 Message Date
aeris ab52dcd13d Fix Mastodon registration 2018-01-07 20:42:57 +01:00
aeris 9cf70a74ba Fix registration 2018-01-07 18:21:24 +01:00
11 changed files with 247 additions and 26 deletions

2
.gitignore vendored
View File

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

122
Gemfile.lock 100644
View File

@ -0,0 +1,122 @@
GIT
remote: https://github.com/tootsuite/mastodon-api.git
revision: a3ff60a872191aa2f499a2b4c7a85045ead14e64
specs:
mastodon-api (1.1.0)
addressable (~> 2.4)
buftok
http (~> 2.0)
PATH
remote: .
specs:
cross-post (0.2.1)
launchy (~> 2.4, >= 2.4.3)
mastodon-api (~> 1.1, >= 1.1.0)
oauth (~> 0.5, >= 0.5.3)
oauth2 (~> 1.4, >= 1.4.0)
sanitize (~> 4.5, >= 4.5.0)
twitter (~> 6.1, >= 6.1.0)
twitter-text (~> 1.14, >= 1.14.7)
GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
awesome_print (1.8.0)
buftok (0.2.0)
coderay (1.1.2)
crass (1.0.3)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
equalizer (0.0.11)
faraday (0.11.0)
multipart-post (>= 1.2, < 3)
http (2.2.2)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 1.0.1)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http-form_data (1.0.3)
http_parser.rb (0.6.0)
jwt (1.5.6)
launchy (2.4.3)
addressable (~> 2.3)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
method_source (0.9.0)
mini_portile2 (2.3.0)
multi_json (1.12.2)
multi_xml (0.6.0)
multipart-post (2.0.0)
naught (1.1.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
nokogumbo (1.4.13)
nokogiri
oauth (0.5.4)
oauth2 (1.4.0)
faraday (>= 0.8, < 0.13)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.1)
rack (2.0.3)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
sanitize (4.5.0)
crass (~> 1.0.2)
nokogiri (>= 1.4.4)
nokogumbo (~> 1.4.1)
simple_oauth (0.3.1)
thread_safe (0.3.6)
twitter (6.1.0)
addressable (~> 2.5)
buftok (~> 0.2.0)
equalizer (= 0.0.11)
faraday (~> 0.11.0)
http (~> 2.1)
http_parser.rb (~> 0.6.0)
memoizable (~> 0.4.2)
naught (~> 1.1)
simple_oauth (~> 0.3.1)
twitter-text (1.14.7)
unf (~> 0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
PLATFORMS
ruby
DEPENDENCIES
awesome_print
bundler (~> 1.15, >= 1.15.4)
cross-post!
dotenv
mastodon-api (~> 1.1.0)!
pry
rspec (~> 3.6.0, >= 3.6.0)
BUNDLED WITH
1.16.1

19
bin/feed-stdout 100755
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

View File

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

View File

@ -5,30 +5,57 @@ require 'oauth2'
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
config = CrossPost::Config.new
settings = config[:settings]
client_id, client_secret = unless config['mastodon.consumer']
token = SecureRandom.hex 64
redirect_url = 'urn:ietf:wg:oauth:2.0:oob'
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
APP_NAME = 'CrossPost'
APP_URL = 'https://git.imirhil.fr/aeris/cross-post/'
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
SCOPES = 'read'
client_id, client_secret = unless settings['mastodon.consumer']
puts 'Creating new app'
token = SecureRandom.hex 64
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/'
app = client.create_app APP_NAME, REDIRECT_URI, SCOPES, APP_URL
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
url = client.auth_code.authorize_url redirect_uri: REDIRECT_URI
puts url
begin
Launchy.open url
rescue
end
print 'Token ? '
token = gets.chomp
config['mastodon.token'] = token
print 'Code? '
code = gets.chomp
config.save
token = client.auth_code.get_token code, scopes: SCOPES, redirect_uri: REDIRECT_URI
token = token.token
puts "Token: #{token}"
settings['mastodon.token'] = token
settings.save

28
bin/replay 100755
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
bin/send-test 100755
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
bin/send-twitter 100755
View File

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

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

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

View File

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