|
|
|
@ -2,11 +2,15 @@ require 'twitter' |
|
|
|
|
require 'twitter-text' |
|
|
|
|
require 'sanitize' |
|
|
|
|
require 'cgi' |
|
|
|
|
require 'ostruct' |
|
|
|
|
|
|
|
|
|
::Twitter::Validation::MAX_LENGTH = 280 |
|
|
|
|
|
|
|
|
|
class CrossPost |
|
|
|
|
class Twitter |
|
|
|
|
def initialize(config) |
|
|
|
|
settings = config[:settings] |
|
|
|
|
@posts = config[:posts] |
|
|
|
|
|
|
|
|
|
config = { |
|
|
|
|
consumer_key: settings['twitter.consumer.key'], |
|
|
|
@ -18,17 +22,19 @@ class CrossPost |
|
|
|
|
@stream = ::Twitter::Streaming::Client.new config |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def post(content, media = []) |
|
|
|
|
media = media.collect { |f| @client.upload f } |
|
|
|
|
def post(content, media = [], id:, reply_to:) |
|
|
|
|
reply_to = OpenStruct.new id: reply_to unless reply_to.respond_to? :id |
|
|
|
|
|
|
|
|
|
media = media.collect { |f| @client.upload f } |
|
|
|
|
parts = split content |
|
|
|
|
last = nil |
|
|
|
|
|
|
|
|
|
unless media.empty? |
|
|
|
|
first, *parts = parts |
|
|
|
|
last = @client.update first, media_ids: media.join(',') |
|
|
|
|
reply_to = @client.update first, media_ids: media.join(','), in_reply_to_status: reply_to |
|
|
|
|
end |
|
|
|
|
parts.each { |p| last = @client.update p, in_reply_to_status: last } |
|
|
|
|
parts.each { |p| reply_to = @client.update p, in_reply_to_status: reply_to } |
|
|
|
|
|
|
|
|
|
reply_to = reply_to.id if reply_to.respond_to? :id |
|
|
|
|
@posts.put id, reply_to, save: true |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
WHITESPACE_TAGS = { |
|
|
|
@ -47,7 +53,9 @@ class CrossPost |
|
|
|
|
LOGGER.debug { " Content: #{content}" } |
|
|
|
|
LOGGER.debug { " Attachments: #{media.size}" } |
|
|
|
|
|
|
|
|
|
self.post content, media |
|
|
|
|
reply = status.in_reply_to_id |
|
|
|
|
reply_to = reply ? @posts[reply] : nil |
|
|
|
|
self.post content, media, id: status.id, reply_to: reply_to |
|
|
|
|
|
|
|
|
|
media.each do |f| |
|
|
|
|
f.close |
|
|
|
|