growlfire 0.0.1
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.
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +20 -0
- data/Rakefile +2 -0
- data/bin/growlfire +7 -0
- data/growlfire.gemspec +21 -0
- data/lib/growlfire.rb +111 -0
- data/lib/growlfire/logo-cf.png +0 -0
- data/lib/growlfire/version.rb +3 -0
- metadata +90 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3-p0@growlfire --create
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Scott Holden
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Growlfire
|
2
|
+
|
3
|
+
Growlfire provides growl notifications via Campfire's steaming api.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Growlfire can be installed via RubyGems:
|
8
|
+
|
9
|
+
$ gem install growlfire
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Growlfire needs a Campfire api token, your campfire subdomain, and the name of the room you wish to join.
|
14
|
+
The api token can be set via an env variable CAMPFIRE_TOKEN or as a single line in ~/.campfire
|
15
|
+
|
16
|
+
To start growlfire, simply use the command:
|
17
|
+
|
18
|
+
$ growlfire mydomain myroom
|
19
|
+
|
20
|
+
If you run into problems, you can turn on debug logging to STDOUT with GROWLFIRE_DEBUG=true env var.
|
data/Rakefile
ADDED
data/bin/growlfire
ADDED
data/growlfire.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/growlfire/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Scott Holden"]
|
6
|
+
gem.email = ["scott@sshconnection.com"]
|
7
|
+
gem.description = %q{Growlfire provides growl notifications via Campfire's steaming API}
|
8
|
+
gem.summary = %q{Growlfire provides growl notifications via Campfire's steaming API}
|
9
|
+
gem.homepage = "http://github.com/sholden/growlfire"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "growlfire"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Growlfire::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'yajl-ruby', '~>1.1'
|
19
|
+
gem.add_dependency 'ruby-growl', '~>4.0'
|
20
|
+
gem.add_dependency 'em-http-request', '~>1.0'
|
21
|
+
end
|
data/lib/growlfire.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require "growlfire/version"
|
2
|
+
require 'yajl'
|
3
|
+
require 'ruby-growl'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
require 'em-http-request'
|
7
|
+
require 'logger'
|
8
|
+
|
9
|
+
module Growlfire
|
10
|
+
class Client
|
11
|
+
attr_reader :host, :token, :room_name
|
12
|
+
|
13
|
+
def initialize(host, token, room_name, options = {})
|
14
|
+
@host, @token, @room_name = host, token, room_name
|
15
|
+
@growl = Growl.new(options.fetch(:host) { 'localhost' }, 'Growlfire')
|
16
|
+
@growl.add_notification('growlfire', 'Growlfire', Growlfire.icon)
|
17
|
+
@log = options.fetch(:log) { Logger.new(STDOUT) }
|
18
|
+
@log.level = Growlfire.debug? ? Logger::DEBUG : Logger::FATAL
|
19
|
+
@user_names = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
parser = Yajl::Parser.new
|
24
|
+
parser.on_parse_complete = Proc.new {|message| handle_message(message)}
|
25
|
+
|
26
|
+
EventMachine.run do
|
27
|
+
opts = {inactivity_timeout: 0, connection_timeout: 0, keepalive: true}
|
28
|
+
http = EventMachine::HttpRequest.new(room_uri).get(opts)
|
29
|
+
http.stream {|chunk| parser << chunk }
|
30
|
+
http.errback { stop! }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle_message(message)
|
35
|
+
@log.debug "Stream: #{message.inspect}"
|
36
|
+
if message['type'] == 'TextMessage'
|
37
|
+
growl user_name(message['user_id']), message['body']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def growl(title, body)
|
42
|
+
@growl.notify 'growlfire', title, body
|
43
|
+
end
|
44
|
+
|
45
|
+
def stop!
|
46
|
+
EventMachine.stop
|
47
|
+
growl 'Growlfire stopped', 'Growlfire shutting down.'
|
48
|
+
@log.fatal 'Growlfire stopped.'
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
def room_id
|
53
|
+
@room_id ||= begin
|
54
|
+
rooms = Yajl.load request room_list_uri
|
55
|
+
@log.debug "Rooms: #{rooms.inspect}"
|
56
|
+
room = rooms['rooms'].find{|r| r['name'] =~ /^#{room_name}$/i}
|
57
|
+
raise 'Could not find room!' unless room
|
58
|
+
room['id']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def user_name(user_id)
|
63
|
+
@user_names[user_id] ||= begin
|
64
|
+
user = Yajl.load request user_uri user_id
|
65
|
+
@log.debug "User: #{user.inspect}"
|
66
|
+
user['user']['name']
|
67
|
+
rescue
|
68
|
+
user_id.to_s
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def user_uri(user_id)
|
73
|
+
URI.parse("https://#{token}:x@#{host}.campfirenow.com/users/#{user_id}.json")
|
74
|
+
end
|
75
|
+
|
76
|
+
def room_uri
|
77
|
+
URI.parse("https://#{token}:x@streaming.campfirenow.com/room/#{room_id}/live.json")
|
78
|
+
end
|
79
|
+
|
80
|
+
def room_list_uri
|
81
|
+
URI.parse("https://#{token}:x@#{host}.campfirenow.com/rooms.json")
|
82
|
+
end
|
83
|
+
|
84
|
+
def request(uri)
|
85
|
+
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
|
86
|
+
request = Net::HTTP::Get.new uri.request_uri
|
87
|
+
request.basic_auth uri.user, uri.password
|
88
|
+
response = http.request request
|
89
|
+
response.body
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.run(host, room)
|
95
|
+
Client.new(host, token, room).run
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.token
|
99
|
+
ENV['CAMPFIRE_TOKEN'] || File.read(File.join(ENV['HOME'], '.campfire')).lines.first.strip
|
100
|
+
rescue
|
101
|
+
raise 'Token not found!'
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.icon
|
105
|
+
File.open(File.join(File.dirname(__FILE__), 'growlfire', 'logo-cf.png'), 'rb').read
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.debug?
|
109
|
+
ENV['GROWLFIRE_DEBUG'] = 'true'
|
110
|
+
end
|
111
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: growlfire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scott Holden
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: &70214699372020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70214699372020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ruby-growl
|
27
|
+
requirement: &70214699371520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70214699371520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: em-http-request
|
38
|
+
requirement: &70214699371060 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70214699371060
|
47
|
+
description: Growlfire provides growl notifications via Campfire's steaming API
|
48
|
+
email:
|
49
|
+
- scott@sshconnection.com
|
50
|
+
executables:
|
51
|
+
- growlfire
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- bin/growlfire
|
62
|
+
- growlfire.gemspec
|
63
|
+
- lib/growlfire.rb
|
64
|
+
- lib/growlfire/logo-cf.png
|
65
|
+
- lib/growlfire/version.rb
|
66
|
+
homepage: http://github.com/sholden/growlfire
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.10
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Growlfire provides growl notifications via Campfire's steaming API
|
90
|
+
test_files: []
|