micro_fire 1.0.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.
- data/CHANGELOG.rdoc +5 -0
- data/Manifest.txt +5 -0
- data/README.rdoc +67 -0
- data/Rakefile +13 -0
- data/lib/micro_fire.rb +109 -0
- data/pkg/micro_fire-1.0.0/CHANGELOG.rdoc +5 -0
- data/pkg/micro_fire-1.0.0/README.rdoc +67 -0
- metadata +113 -0
data/CHANGELOG.rdoc
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= micro_fire
|
2
|
+
|
3
|
+
http://rubygems.org/gems/micro_fire
|
4
|
+
{Project}[http://rubygems.org/gems/micro_fire]
|
5
|
+
{Documentation}[http://libraggi.rubyforge.org/micro_fire/README_rdoc.html]
|
6
|
+
{Wiki}[http://wiki.github.com/raggi/micro_fire/]
|
7
|
+
{Source Code}[http://github.com/raggi/micro_fire/]
|
8
|
+
{Issues}[http://github.com/raggi/micro_fire/issues]
|
9
|
+
{Rubyforge}[http://rubyforge.org/projects/libraggi]
|
10
|
+
|
11
|
+
== DESCRIPTION:
|
12
|
+
|
13
|
+
A micro single room Campfire interface that only depends on
|
14
|
+
Net::HTTP::Persistent and a JSON library. On 1.9, it will use Psych by
|
15
|
+
default, on other rubies it will try for yajl, then for json.
|
16
|
+
|
17
|
+
== FEATURES/PROBLEMS:
|
18
|
+
|
19
|
+
* Simples
|
20
|
+
|
21
|
+
== SYNOPSIS:
|
22
|
+
|
23
|
+
BEGIN { require 'rubygems' }
|
24
|
+
require 'osx_keychain' # optional part of example
|
25
|
+
keychain = OSXKeychain.new # optional part of example
|
26
|
+
token = keychain['campfire', ENV['USER']] # optional part of example
|
27
|
+
|
28
|
+
room = MicroFire.new 'raggi', token, 'ragville'
|
29
|
+
room.join
|
30
|
+
room.speak 'OHAI THERE'
|
31
|
+
room.watch do |event|
|
32
|
+
p event
|
33
|
+
end
|
34
|
+
|
35
|
+
== REQUIREMENTS:
|
36
|
+
|
37
|
+
* gem install net-http-persistent
|
38
|
+
* a json library: yajl-ruby, or json, or psych
|
39
|
+
|
40
|
+
== INSTALL:
|
41
|
+
|
42
|
+
* gem install micro_fire
|
43
|
+
|
44
|
+
== LICENSE:
|
45
|
+
|
46
|
+
(The MIT License)
|
47
|
+
|
48
|
+
Copyright (c) 2011 raggi
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
51
|
+
a copy of this software and associated documentation files (the
|
52
|
+
'Software'), to deal in the Software without restriction, including
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
56
|
+
the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
64
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
65
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
66
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
67
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'hoe'
|
4
|
+
Hoe.plugin :gemspec2
|
5
|
+
|
6
|
+
Hoe.spec 'micro_fire' do
|
7
|
+
developer 'raggi', 'raggi@rubyforge.org'
|
8
|
+
extra_dev_deps << %w(hoe-gemspec2 >=1.0.0)
|
9
|
+
|
10
|
+
self.extra_rdoc_files = FileList["**/*.rdoc"]
|
11
|
+
self.history_file = "CHANGELOG.rdoc"
|
12
|
+
self.readme_file = "README.rdoc"
|
13
|
+
end
|
data/lib/micro_fire.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# This may have been stolen from the Pink Warrior (tenderlove). Since then
|
2
|
+
# it's seen some flashing lights, the bottom of a bucket, and other intense
|
3
|
+
# torture.
|
4
|
+
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http/persistent'
|
7
|
+
|
8
|
+
class MicroFire
|
9
|
+
VERSION = '1.0.0'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :stream, :json
|
13
|
+
end
|
14
|
+
self.stream = URI.parse('https://streaming.campfirenow.com')
|
15
|
+
|
16
|
+
json_libs = [
|
17
|
+
lambda { require 'psych'; Psych },
|
18
|
+
lambda { require 'yajl' ; Yajl },
|
19
|
+
lambda { require 'json' ; JSON },
|
20
|
+
lambda { raise 'No suitable JSON lib could be found' }
|
21
|
+
]
|
22
|
+
|
23
|
+
self.json = json_libs.each do |loader|
|
24
|
+
begin; break loader.call; rescue LoadError; nil; end
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :http, :uri, :token, :room
|
28
|
+
attr_accessor :stream, :json, :pass
|
29
|
+
|
30
|
+
def initialize uri, token, room
|
31
|
+
@stream = self.class.stream
|
32
|
+
@json = self.class.json
|
33
|
+
@token = token
|
34
|
+
@http = Net::HTTP::Persistent.new
|
35
|
+
# Don't do anything if not supported by net/http/persistent version or
|
36
|
+
# socket.so. Helps when they deploy.
|
37
|
+
if @http.respond_to? :socket_options
|
38
|
+
@http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
|
39
|
+
end
|
40
|
+
@pass = 'x'
|
41
|
+
@uri = find_uri uri
|
42
|
+
@room = find_room room
|
43
|
+
end
|
44
|
+
|
45
|
+
def join &block
|
46
|
+
req action('join'), &block
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def speak message, &block
|
51
|
+
req action('speak'), :message => { :body => message }, &block
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def watch &block
|
56
|
+
req action('live'), {}, :Get, stream, &block
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def find_room room
|
62
|
+
return room if room =~ /^\d+$/
|
63
|
+
res = req('/rooms.json', {}, :Get)
|
64
|
+
res = res["rooms"].find { |rm| rm["name"] == room }
|
65
|
+
res ? res["id"].to_i : raise("Could not find room by #{room}")
|
66
|
+
end
|
67
|
+
|
68
|
+
def find_uri uri
|
69
|
+
if uri =~ %r{https?://.*\..*}
|
70
|
+
URI.parse uri
|
71
|
+
else
|
72
|
+
URI.parse "https://#{uri}.campfirenow.com"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def action action
|
77
|
+
"/room/#{room}/#{action}.json"
|
78
|
+
end
|
79
|
+
|
80
|
+
def req path, body = {}, type = :Post, uri = uri, &block
|
81
|
+
req = Net::HTTP.const_get(type).new(path)
|
82
|
+
req.basic_auth token, pass
|
83
|
+
if type == :Post
|
84
|
+
req.content_type = 'application/json'
|
85
|
+
req.body = json.dump(body)
|
86
|
+
end
|
87
|
+
http.request(uri, req) { |response| return res response, &block }
|
88
|
+
rescue Errno::ETIMEDOUT, Net::HTTP::Persistent::Error => e
|
89
|
+
backoff && retry
|
90
|
+
warn "IO Lost: #{e.class} #{e.message}"
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
|
94
|
+
def res http_response
|
95
|
+
return json.load http_response.body unless block_given?
|
96
|
+
# Yield a stream of json events if a block is given
|
97
|
+
http_response.read_body do |chunk|
|
98
|
+
chunk.split("\r").each do |message|
|
99
|
+
yield json.load(message)
|
100
|
+
end unless chunk.strip.empty?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def backoff
|
105
|
+
@backoff ||= 1
|
106
|
+
sleep(@backoff = @backoff * 2 % 16) != 0
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
= micro_fire
|
2
|
+
|
3
|
+
http://rubygems.org/gems/micro_fire
|
4
|
+
{Project}[http://rubygems.org/gems/micro_fire]
|
5
|
+
{Documentation}[http://libraggi.rubyforge.org/micro_fire/README_rdoc.html]
|
6
|
+
{Wiki}[http://wiki.github.com/raggi/micro_fire/]
|
7
|
+
{Source Code}[http://github.com/raggi/micro_fire/]
|
8
|
+
{Issues}[http://github.com/raggi/micro_fire/issues]
|
9
|
+
{Rubyforge}[http://rubyforge.org/projects/libraggi]
|
10
|
+
|
11
|
+
== DESCRIPTION:
|
12
|
+
|
13
|
+
A micro single room Campfire interface that only depends on
|
14
|
+
Net::HTTP::Persistent and a JSON library. On 1.9, it will use Psych by
|
15
|
+
default, on other rubies it will try for yajl, then for json.
|
16
|
+
|
17
|
+
== FEATURES/PROBLEMS:
|
18
|
+
|
19
|
+
* Simples
|
20
|
+
|
21
|
+
== SYNOPSIS:
|
22
|
+
|
23
|
+
BEGIN { require 'rubygems' }
|
24
|
+
require 'osx_keychain' # optional part of example
|
25
|
+
keychain = OSXKeychain.new # optional part of example
|
26
|
+
token = keychain['campfire', ENV['USER']] # optional part of example
|
27
|
+
|
28
|
+
room = MicroFire.new 'raggi', token, 'ragville'
|
29
|
+
room.join
|
30
|
+
room.speak 'OHAI THERE'
|
31
|
+
room.watch do |event|
|
32
|
+
p event
|
33
|
+
end
|
34
|
+
|
35
|
+
== REQUIREMENTS:
|
36
|
+
|
37
|
+
* gem install net-http-persistent
|
38
|
+
* a json library: yajl-ruby, or json, or psych
|
39
|
+
|
40
|
+
== INSTALL:
|
41
|
+
|
42
|
+
* gem install micro_fire
|
43
|
+
|
44
|
+
== LICENSE:
|
45
|
+
|
46
|
+
(The MIT License)
|
47
|
+
|
48
|
+
Copyright (c) 2011 raggi
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
51
|
+
a copy of this software and associated documentation files (the
|
52
|
+
'Software'), to deal in the Software without restriction, including
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
56
|
+
the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
64
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
65
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
66
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
67
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: micro_fire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- raggi
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-05-23 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: hoe-gemspec2
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 1.0.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hoe
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 35
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 9
|
49
|
+
- 4
|
50
|
+
version: 2.9.4
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: |-
|
54
|
+
A micro single room Campfire interface that only depends on
|
55
|
+
Net::HTTP::Persistent and a JSON library. On 1.9, it will use Psych by
|
56
|
+
default, on other rubies it will try for yajl, then for json.
|
57
|
+
email:
|
58
|
+
- raggi@rubyforge.org
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
62
|
+
|
63
|
+
extra_rdoc_files:
|
64
|
+
- Manifest.txt
|
65
|
+
- CHANGELOG.rdoc
|
66
|
+
- pkg/micro_fire-1.0.0/CHANGELOG.rdoc
|
67
|
+
- pkg/micro_fire-1.0.0/README.rdoc
|
68
|
+
- README.rdoc
|
69
|
+
files:
|
70
|
+
- CHANGELOG.rdoc
|
71
|
+
- Manifest.txt
|
72
|
+
- README.rdoc
|
73
|
+
- Rakefile
|
74
|
+
- lib/micro_fire.rb
|
75
|
+
- pkg/micro_fire-1.0.0/CHANGELOG.rdoc
|
76
|
+
- pkg/micro_fire-1.0.0/README.rdoc
|
77
|
+
has_rdoc: true
|
78
|
+
homepage: http://rubygems.org/gems/micro_fire
|
79
|
+
licenses: []
|
80
|
+
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --main
|
84
|
+
- README.rdoc
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project: micro_fire
|
108
|
+
rubygems_version: 1.5.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: A micro single room Campfire interface that only depends on Net::HTTP::Persistent and a JSON library
|
112
|
+
test_files: []
|
113
|
+
|