flowpi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/flowpi.rb +11 -0
  3. data/lib/flowpi.rb +67 -0
  4. metadata +102 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71e2b841556a2b641e396afb43d484a6d9c416b8
4
+ data.tar.gz: af27106e8b60e08440bd013c41311830e5e2fd52
5
+ SHA512:
6
+ metadata.gz: c91fb02ea594be15b289f0d2c5b70f24deb693c1886ca7e1cc787eb2b301bc33c4b67dee45907e195abf1459a187bcd039b9d9e6732766773c908af0c3a44c8c
7
+ data.tar.gz: 4e5d5bdf448334ac2d57a8b53f91ebec3eb2d26d942cec06798c544932b80a743700e8dc9093d3f0332a017b8994c2a35497e211d38bffb53f299560aa94926e
data/bin/flowpi.rb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'flowpi'
6
+
7
+ Flowpi::Server.new(
8
+ token: ENV.fetch('FLOW_TOKEN'),
9
+ filter: ENV.fetch('FLOW_FILTER'),
10
+ message_matcher: Regexp.new(ENV.fetch('FLOW_MATCH')),
11
+ ).run
data/lib/flowpi.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'em-http'
2
+ require 'json'
3
+
4
+ module Flowpi
5
+ VERSION = '0.1.0'
6
+
7
+ class Server
8
+ def initialize(options = {})
9
+ @options = options
10
+ end
11
+
12
+ def run
13
+ http = EM::HttpRequest.new(
14
+ "https://stream.flowdock.com/flows?filter=#{@options[:filter]}",
15
+ :keepalive => true, :connect_timeout => 0, :inactivity_timeout => 0)
16
+ EventMachine.run do
17
+ s = http.get(:head => { 'Authorization' => [@options[:token], ''], 'accept' => 'application/json'})
18
+
19
+ buffer = ""
20
+ s.stream do |chunk|
21
+ buffer << chunk
22
+ while line = buffer.slice!(/.+\r\n/)
23
+ handle_line(line)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def handle_line(line)
30
+ message = Flowpi::Message.new.parse(line)
31
+ if message.has_content?
32
+ if message.content.match(@options[:message_matcher])
33
+ puts "Speaking message: #{message.content}"
34
+ %x(espeak "#{message.content}" 2>/dev/null)
35
+ else
36
+ puts "Ignoring message: #{message.content}"
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ class Message
43
+ MESSAGE_TYPES = %w(message comment)
44
+
45
+ def initialize(data = {})
46
+ @data = data
47
+ end
48
+
49
+ def has_content?
50
+ MESSAGE_TYPES.include?(@data['event'])
51
+ end
52
+
53
+ def parse(line)
54
+ @data = JSON.parse(line)
55
+ self
56
+ end
57
+
58
+ def content
59
+ if @data['content'].kind_of?(Hash)
60
+ content = @data['content']['text']
61
+ else
62
+ content = @data['content']
63
+ end
64
+ content.gsub(/[^a-z ]/i, '')
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flowpi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Olle Johansson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: em-http-request
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ description: Small script to listen to flows on Flowdock and speak them with a synthesizer.
70
+ email: Olle@Johansson.com
71
+ executables:
72
+ - flowpi.rb
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - bin/flowpi.rb
77
+ - lib/flowpi.rb
78
+ homepage: https://github.com/ollej/flowpi
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Flowdock bot to speak messages.
102
+ test_files: []