Sha256: 4603fb41913dd4b9e1bf58ca55339cca7d73a96b428e67821e9f84e9a20c28a5
Contents?: true
Size: 1.76 KB
Versions: 1
Compression:
Stored size: 1.76 KB
Contents
require 'nokogiri' require 'open-uri' require 'rmagick' class MastodonAPI def initialize(client) @client = client @timeline = Hash.new @avatar = Array.new @media_id = nil end def MediaUpload(file_path) if file_path != nil then @media_id = @client.upload_media(file_path).id else @media_id = nil end end def Toot(message, visibility, sensitive, spoiler_text) message += "\n #Legion" response = @client.create_status(message.encode("UTF-8"), :media_ids => @media_id, :visibility => visibility, :sensitive => sensitive, :spoiler_text => spoiler_text) end end class MastodonStreaming def initialize(stream) @stream = stream end def HomeTimeline(window, list) @stream.user() do |toot| message = Nokogiri::HTML.parse(toot.content, nil, nil).search('p') list.insert('0', message.text) end end def PublicTimeline(window, list) @stream.firehose() do |toot| message = Nokogiri::HTML.parse(toot.content, nil, nil).search('p') list.insert('0', message.text) end end def LocalTimeline(window, list) @stream.firehose() do |toot| if toot.uri.to_s =~ /#{ENV['MASTODON_URL'].to_s}/ then message = Nokogiri::HTML.parse(toot.content, nil, nil).search('p') list.insert('0', message.text) end end end def Timeline(timeline) case timeline[0] when 1 self.HomeTimeline(timeline[1], timeline[2]) when 2 self.LocalTimeline(timeline[1], timeline[2]) when 3 self.PublicTimeline(timeline[1], timeline[2]) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
legion_mastodon_client-0.1.0 | lib/legion/mastodon.rb |