Compare commits
15 Commits
Author | SHA1 | Date |
---|---|---|
|
ab52dcd13d | 5 years ago |
|
9cf70a74ba | 5 years ago |
|
663a05be75 | 5 years ago |
|
aaf143e5b5 | 5 years ago |
|
72ce72fa2c | 5 years ago |
|
91be33ac99 | 6 years ago |
|
6881206ca1 | 6 years ago |
|
50b8b57065 | 6 years ago |
|
51904f3808 | 6 years ago |
|
011d0c16b8 | 6 years ago |
|
d51c885fec | 6 years ago |
|
40ed5f4414 | 6 years ago |
|
966b7554a2 | 6 years ago |
|
99ac0f1be4 | 6 years ago |
|
35b7477bac | 6 years ago |
@ -1 +1 @@ |
||||
/Gemfile.lock |
||||
/vendor/bundle/ |
||||
|
@ -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 |
@ -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 |
@ -1,3 +1,3 @@ |
||||
#!/usr/bin/env ruby |
||||
require 'cross-post' |
||||
CrossPost.feed |
||||
loop { CrossPost.feed rescue nil } |
||||
|
@ -0,0 +1,3 @@ |
||||
#!/usr/bin/env ruby |
||||
require 'cross-post' |
||||
CrossPost.feed |
@ -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 |
@ -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 |
@ -0,0 +1,3 @@ |
||||
#!/usr/bin/env ruby |
||||
require 'cross-post' |
||||
CrossPost.new.twitter.post File.read ARGV[0] |
@ -1,40 +1,120 @@ |
||||
require 'yaml' |
||||
require 'fileutils' |
||||
|
||||
class CrossPost |
||||
class Config |
||||
def initialize |
||||
@file = ENV.fetch 'CROSS_POST_CONFIG', File.join(Dir.home, '.cross-post.yml') |
||||
File.open(@file) { |f| @config = YAML.safe_load f } |
||||
end |
||||
DEFAULT_CONFIG_FOLDER = File.join Dir.home, '.config/cross-post' |
||||
DEFAULT_CONFIG_FILE = 'config.yml' |
||||
|
||||
def [](key) |
||||
current = @config |
||||
key.split(/\./).each do |k| |
||||
current = current[k] |
||||
return nil if current.nil? |
||||
class SubConfig |
||||
def initialize(config = {}) |
||||
@config = config |
||||
end |
||||
|
||||
def each(&block) |
||||
@config.each &block |
||||
end |
||||
|
||||
def [](key) |
||||
case key |
||||
when String |
||||
current = @config |
||||
key.split(/\./).each do |k| |
||||
current = current[k] |
||||
return nil if current.nil? |
||||
end |
||||
current |
||||
else |
||||
@config[key] |
||||
end |
||||
end |
||||
|
||||
def fetch(key, default = nil) |
||||
self[key] || default |
||||
end |
||||
current |
||||
end |
||||
|
||||
def []=(key, value) |
||||
*key, last = key.split(/\./) |
||||
current = @config |
||||
key.each do |k| |
||||
next_ = current[k] |
||||
case next_ |
||||
when nil |
||||
next_ = current[k] = {} |
||||
when Hash |
||||
def []=(key, value) |
||||
case key |
||||
when String |
||||
*key, last = key.to_s.split(/\./) |
||||
current = @config |
||||
key.each do |k| |
||||
next_ = current[k] |
||||
case next_ |
||||
when nil |
||||
next_ = current[k] = {} |
||||
when Hash |
||||
else |
||||
raise "Invalid entry, Hash expected, had #{next_.class} (#{next_})" |
||||
end |
||||
current = next_ |
||||
end |
||||
current[last] = value |
||||
else |
||||
raise "Invalid entry, Hash expected, had #{next_.class} (#{next_})" |
||||
@config[key] = value |
||||
end |
||||
current = next_ |
||||
end |
||||
current[last] = value |
||||
end |
||||
|
||||
def save |
||||
File.write @file, YAML.dump(@config) |
||||
class FifoSubConfig < SubConfig |
||||
def initialize(size = 100) |
||||
@size = size |
||||
@keys = [] |
||||
super({}) |
||||
end |
||||
|
||||
def []=(key, value) |
||||
@keys.delete key |
||||
value = super key, value |
||||
@keys << key |
||||
while @keys.size > @size |
||||
key = @keys.delete_at 0 |
||||
@config.delete key |
||||
end |
||||
value |
||||
end |
||||
end |
||||
|
||||
class FileSubConfig < SubConfig |
||||
def initialize(file) |
||||
@file = file |
||||
super YAML.load_file @file |
||||
end |
||||
|
||||
def put(key, value, save: false) |
||||
self[key] = value |
||||
self.save if save |
||||
end |
||||
|
||||
def save |
||||
LOGGER.debug "Saving #{@file}" |
||||
yaml = YAML.dump @config |
||||
File.write @file, yaml |
||||
end |
||||
end |
||||
|
||||
def initialize |
||||
@configs = {} |
||||
@dir = ENV.fetch 'CONFIG_FOLDER', DEFAULT_CONFIG_FOLDER |
||||
file = ENV.fetch 'CONFIG_FILE', DEFAULT_CONFIG_FILE |
||||
self.load :settings, file |
||||
self.load :users |
||||
self[:posts] = FifoSubConfig.new |
||||
end |
||||
|
||||
def [](name) |
||||
@configs[name] |
||||
end |
||||
|
||||
def []=(name, value) |
||||
@configs[name] = value |
||||
end |
||||
|
||||
def load(name, file = nil) |
||||
file ||= "#{name}.yml" |
||||
file = File.join @dir, file |
||||
File.write(file, YAML.dump({})) unless File.exist? file |
||||
self[name] = FileSubConfig.new file |
||||
end |
||||
end |
||||
end |
||||
|
@ -1,3 +1,3 @@ |
||||
class CrossPost |
||||
VERSION = '0.1.1'.freeze |
||||
VERSION = '0.2.1'.freeze |
||||
end |
||||
|
@ -0,0 +1,19 @@ |
||||
require 'cross-post' |
||||
|
||||
RSpec.describe CrossPost::Config::FifoSubConfig do |
||||
it 'must remove first value in case of overflow' do |
||||
config = CrossPost::Config::FifoSubConfig.new 2 |
||||
config[:foo] = :foo |
||||
config[:bar] = :bar |
||||
|
||||
expect(config[:foo]).to be :foo |
||||
expect(config[:bar]).to be :bar |
||||
expect(config[:baz]).to be_nil |
||||
|
||||
config[:baz] = :baz |
||||
|
||||
expect(config[:foo]).to be_nil |
||||
expect(config[:bar]).to be :bar |
||||
expect(config[:baz]).to be :baz |
||||
end |
||||
end |
Loading…
Reference in new issue