class FBomb::Flowdock::Flow
Public Instance Methods
cache()
click to toggle source
# File lib/fbomb/flowdock.rb, line 245 def cache Cache end
debug_stream(&block)
click to toggle source
# File lib/fbomb/flowdock.rb, line 201 def debug_stream(&block) require "readline" while buf = Readline.readline("#{ organization }/#{ flow } > ", true) if buf.strip.downcase == 'exit' exit end flow = { :event => 'message', :content => buf, :tags => [], :persist => false, :id => rand(99999), :uuid => FBomb.uuid, :sent => Time.now.to_i, :app => 'fbomb', :attachments => [], :user => rand(99999), } block.call(Map.for(flow)) if block end end
escape(string)
click to toggle source
# File lib/fbomb/flowdock.rb, line 70 def escape(string) string.to_s.gsub('+', '%2B') end
history()
click to toggle source
# File lib/fbomb/flowdock.rb, line 226 def history @history ||= [] end
leave()
click to toggle source
# File lib/fbomb/flowdock.rb, line 132 def leave #say 'bai' end
paste(*args, &block)
click to toggle source
# File lib/fbomb/flowdock.rb, line 97 def paste(*args, &block) options = Map.options_for!(args) tags = tags_for(options[:tags], options[:tag]) content = case when args.size == 1 if args.first.is_a?(String) args.first else Coerce.array(args.first).join("\n") end else Coerce.list_of_strings(args).join("\n") end msg = {:content => Util.indent(escape(content), 4), :tags => tags} if FBomb.debug puts("PASTE\n") puts(msg.to_yaml) puts else client.push_to_chat(msg) end end
speak(*args, &block)
click to toggle source
# File lib/fbomb/flowdock.rb, line 78 def speak(*args, &block) options = Map.options_for!(args) tags = tags_for(options[:tags], options[:tag]) content = escape(Coerce.list_of_strings(args).join(' ')) msg = {:content => content, :tags => tags} if FBomb.debug puts("SPEAK\n") puts(msg.to_yaml) puts else client.push_to_chat(msg) end end
Also aliased as: say
stream(&block)
click to toggle source
{“event”=>“activity.user”,
"tags"=>[], "uuid"=>nil, "persist"=>false, "id"=>194342, "flow"=>"c6dbc029-2173-4fb6-a423-32293c373106", "content"=>{"last_activity"=>1399656686378}, "sent"=>1399657205286, "app"=>nil, "attachments"=>[], "user"=>"76002"} {:flow=>{"event"=>"message", "tags"=>[], "uuid"=>"Ry2GHegX445OAxV_", "id"=>2427, "flow"=>"affcb403-0c5f-4a2c-89a6-a809a887e281", "content"=>".peeps", "sent"=>1399838702954, "app"=>"chat", "attachments"=>[], "user"=>"77414"} }
# File lib/fbomb/flowdock.rb, line 162 def stream(&block) return debug_stream(&block) if FBomb.debug http = EM::HttpRequest.new( "https://stream.flowdock.com/flows/#{ organization }/#{ flow }", :keepalive => true, :connect_timeout => 0, :inactivity_timeout => 0) EventMachine.run do s = http.get(:head => { 'Authorization' => [token, ''], 'accept' => 'application/json'}) buffer = "" s.stream do |chunk| buffer << chunk while line = buffer.slice!(/.+\r\n/) begin flow = JSON.parse(line) unless flow['event'] == 'activity.user' history.push(flow) while history.size > 1024 history.shift end end if flow['external_user_name'] == client.external_user_name next end block.call(Map.for(flow)) if block rescue Object => e warn("#{ e.message }(#{ e.class })#{ Array(e.backtrace).join(10.chr) }") # FIXME end end end end end
upload(*args, &block)
click to toggle source
# File lib/fbomb/flowdock.rb, line 124 def upload(*args, &block) raise NotImplementedError end
user_for(id)
click to toggle source
# File lib/fbomb/flowdock.rb, line 241 def user_for(id) users.detect{|user| user.id.to_s == id.to_s || user.email.to_s == id.to_s} end
users(*args, &block)
click to toggle source
# File lib/fbomb/flowdock.rb, line 128 def users(*args, &block) [] end
yell(*args)
click to toggle source
# File lib/fbomb/flowdock.rb, line 64 def yell(*args) string = args.join(' ') prefix = ["FUCKING", "OH YEAH!?", "SRSLY"].sort_by{ rand }.first paste([prefix, string].join(' ')) end