lib/legion/mastodon.rb in legion_mastodon_client-0.1.1 vs lib/legion/mastodon.rb in legion_mastodon_client-0.1.2

- old
+ new

@@ -5,53 +5,65 @@ class MastodonAPI def initialize(client) @client = client @timeline = Hash.new - @avatar = Array.new - @media_id = nil + @media_id = Array.new end def MediaUpload(file_path) if file_path != nil then - @media_id = @client.upload_media(file_path).id + for i in 0...@client.count do + @media_id[i] = @client[i].upload_media(file_path).id + end else - @media_id = nil + @media_id.clear end end - def Toot(message, visibility, sensitive, spoiler_text) + def Toot(message, options) message += "\n #Legion" - response = @client.create_status(message.encode("UTF-8"), :media_ids => @media_id, :visibility => visibility, :sensitive => sensitive, :spoiler_text => spoiler_text) + + for i in 0...@client.count do + response = @client[i].create_status(message.encode("UTF-8"), :media_ids => @media_id[i], + :visibility => options[:visibility], :sensitive => options[:sensitive], + :spoiler_text => options[:spoiler_text]) + end + + @media_id.clear end end class MastodonStreaming + attr_accessor :stream, :num - def initialize(stream) + def initialize(stream, url) @stream = stream + @url = url + @num = 0 end def HomeTimeline(window, list) - @stream.user() do |toot| + @stream[@num].user() do |toot| message = Nokogiri::HTML.parse(toot.content, nil, nil).search('p') - list.insert('0', message.text) + list.insert('0', "#{toot.account.display_name} さん : #{message.text}") end end def PublicTimeline(window, list) - @stream.firehose() do |toot| + @stream[@num].firehose() do |toot| message = Nokogiri::HTML.parse(toot.content, nil, nil).search('p') - list.insert('0', message.text) + list.insert('0', "#{toot.account.display_name} さん : #{message.text}") end end def LocalTimeline(window, list) - @stream.firehose() do |toot| - if toot.uri.to_s =~ /#{ENV['MASTODON_URL'].to_s}/ then + @stream[@num].firehose() do |toot| + puts @url[@num] + if toot.uri.to_s =~ /#{@url[@num]}/ then message = Nokogiri::HTML.parse(toot.content, nil, nil).search('p') - list.insert('0', message.text) + list.insert('0', "#{toot.account.display_name} さん : #{message.text}") end end end def Timeline(timeline) \ No newline at end of file