Sha256: 0f717c5773f663852b62c9137179d839b13dfda6dd16190cfa4e614ee85ddd8e

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 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.1 lib/legion/mastodon.rb