mojodna-fire-hydrant 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +82 -0
- data/examples/authorize.rb +38 -0
- data/examples/fire_eagle_consumer.rb +13 -0
- data/examples/fire_eagle_visualizer.rb +29 -0
- data/fire-hydrant.gemspec +14 -0
- data/fire_hydrant.yml.sample +7 -0
- data/lib/fire_hydrant/fire_hydrant.rb +19 -0
- data/lib/fire_hydrant/jacks/fire_eagle_jack.rb +20 -0
- data/lib/fire_hydrant/jacks.rb +1 -0
- data/lib/fire_hydrant.rb +2 -0
- metadata +87 -0
data/README.markdown
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Fire Hydrant
|
2
|
+
|
3
|
+
Fire Hydrant is a set of tools for consuming [Fire
|
4
|
+
Eagle](http://fireeagle.yahoo.net/ "Fire Eagle")'s XMPP
|
5
|
+
[PubSub](http://xmpp.org/extensions/xep-0060.html "XEP-0060: Publish-Subscribe") feed.
|
6
|
+
|
7
|
+
## Getting Started
|
8
|
+
|
9
|
+
Install it:
|
10
|
+
|
11
|
+
$ sudo gem install mojodna-fire-hydrant-s http://gems.github.com
|
12
|
+
|
13
|
+
Configure it:
|
14
|
+
|
15
|
+
$ cp fire_hydrant.yml.sample fire_hydrant.yml
|
16
|
+
$ vi fire_hydrant.yml
|
17
|
+
|
18
|
+
_Switchboard settings are not presently used._
|
19
|
+
|
20
|
+
Configure switchboard:
|
21
|
+
|
22
|
+
$ switchboard config jid jid@example.com
|
23
|
+
$ switchboard config password pa55word
|
24
|
+
$ switchboard config oauth.consumer_key asdf
|
25
|
+
$ switchboard config oauth.consumer_secret qwerty
|
26
|
+
$ switchboard config oauth.token asdf
|
27
|
+
$ switchboard config oauth.token_secret qwerty
|
28
|
+
$ switchboard config oauth.general_token asdf
|
29
|
+
$ switchboard config oauth.general_token_secret qwerty
|
30
|
+
$ switchboard config pubsub.server fireeagle.com
|
31
|
+
|
32
|
+
Subscribe to location updates corresponding to the configured token:
|
33
|
+
|
34
|
+
$ switchboard pubsub subscribe
|
35
|
+
|
36
|
+
Check subscriptions:
|
37
|
+
|
38
|
+
$ switchboard pubsub subscriptions
|
39
|
+
|
40
|
+
Run it:
|
41
|
+
|
42
|
+
$ examples/fire_eagle_consumer.rb
|
43
|
+
|
44
|
+
If you'd like to unsubscribe:
|
45
|
+
|
46
|
+
$ switchboard pubsub unsubscribe
|
47
|
+
|
48
|
+
## Notes and Gotchas
|
49
|
+
|
50
|
+
Subscribing to / unsubscribing from nodes is an awkward process at the moment,
|
51
|
+
as switchboard must be re-configured with each OAuth token/secret pair that
|
52
|
+
you wish to subscribe to.
|
53
|
+
|
54
|
+
If you need to authorize your application to receive updates, you can add your
|
55
|
+
OAuth consumer key to _fire\_hydrant.yml_ and run:
|
56
|
+
|
57
|
+
$ examples/authorize.rb
|
58
|
+
|
59
|
+
You can then add the token and secret to your switchboard configuration in
|
60
|
+
order to subscribe.
|
61
|
+
|
62
|
+
Google Talk accounts do not appear to work, but Jabber.org accounts seem to
|
63
|
+
work fine. (If you plan to use this in production, you should be running your
|
64
|
+
own XMPP server and should **not** use Jabber.org.)
|
65
|
+
|
66
|
+
## Getting Help
|
67
|
+
|
68
|
+
Your best bet for help is to post a message to the Fire Eagle Yahoo! Group:
|
69
|
+
[http://tech.groups.yahoo.com/group/fireeagle/](http://tech.groups.yahoo.com/group/fireeagle/ "Fire Eagle Yahoo! Group")
|
70
|
+
|
71
|
+
## Google Earth Integration
|
72
|
+
|
73
|
+
If you're on a Mac, install [Google Earth](http://earth.google.com/ "Google Earth") and
|
74
|
+
[rb-appscript](http://appscript.sourceforge.net/rb-appscript/index.html "Ruby Appscript"):
|
75
|
+
|
76
|
+
$ sudo gem install rb-appscript
|
77
|
+
|
78
|
+
Start Google Earth and run:
|
79
|
+
|
80
|
+
$ examples/fire_eagle_visualizer.rb
|
81
|
+
|
82
|
+
To see your users' locations in real-time as they change.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'rubygems'
|
5
|
+
# work-around for a bug in oauth 0.2.4
|
6
|
+
require 'oauth/helper'
|
7
|
+
require 'fireeagle'
|
8
|
+
|
9
|
+
# read the configuration
|
10
|
+
config = YAML.load(open("fire_hydrant.yml").read)
|
11
|
+
|
12
|
+
if config.has_key?("oauth.token") && config.has_key?("oauth.token_secret")
|
13
|
+
puts "Application has already been authorized."
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
# initialize a Fire Eagle client
|
18
|
+
client = FireEagle::Client.new \
|
19
|
+
:consumer_key => config["oauth.consumer_key"],
|
20
|
+
:consumer_secret => config["oauth.consumer_secret"]
|
21
|
+
|
22
|
+
## Step 1 - Get a request token
|
23
|
+
|
24
|
+
client.get_request_token
|
25
|
+
|
26
|
+
## Step 2 - Ask the user to authorize the application, using that request token
|
27
|
+
|
28
|
+
puts "Please authorize this application:"
|
29
|
+
puts " #{client.authorization_url}"
|
30
|
+
print "<waiting>"
|
31
|
+
gets
|
32
|
+
|
33
|
+
## Step 3 - Convert the request token into an access token
|
34
|
+
|
35
|
+
client.convert_to_access_token
|
36
|
+
|
37
|
+
puts "Your OAuth token is: #{client.access_token.token}"
|
38
|
+
puts "Your OAuth token secret is: #{client.access_token.secret}"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fire_hydrant'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
hydrant = FireHydrant.new(YAML.load(File.read("fire_hydrant.yml")))
|
6
|
+
|
7
|
+
hydrant.on_location_update do |user|
|
8
|
+
# for some reason the Fire Eagle gem doesn't work when I access #name directly
|
9
|
+
name = user.locations[0].instance_eval { @doc.at("//name").innerText }
|
10
|
+
puts "#{user.token} has moved to #{name}."
|
11
|
+
end
|
12
|
+
|
13
|
+
hydrant.run!
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'appscript'
|
5
|
+
rescue LoadError => e
|
6
|
+
gem = e.message.split("--").last.strip
|
7
|
+
puts "The #{gem} gem is required."
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'fire_hydrant'
|
11
|
+
|
12
|
+
earth = Appscript.app("Google Earth")
|
13
|
+
|
14
|
+
# override the resource as "visualizer"
|
15
|
+
hydrant = FireHydrant.new(YAML.load(File.read("fire_hydrant.yml")).merge("resource" => "visualizer"), true)
|
16
|
+
|
17
|
+
hydrant.on_location_update do |user|
|
18
|
+
# for some reason the Fire Eagle gem doesn't work when I access #name directly
|
19
|
+
name = user.locations[0].instance_eval { @doc.at("//name").innerText }
|
20
|
+
puts "#{user.token} has moved to #{name}."
|
21
|
+
|
22
|
+
geom = user.locations[0].geom
|
23
|
+
begin
|
24
|
+
pt = geom.is_a?(GeoRuby::SimpleFeatures::Envelope) ? geom.center : geom
|
25
|
+
earth.SetViewInfo({:latitude => pt.y, :longitude => pt.x, :distance => (rand * 25000) + 5000, :azimuth => rand * 360, :tilt => (rand * 75)}, {:speed => 1})
|
26
|
+
rescue # rescue from Appscript errrors
|
27
|
+
end
|
28
|
+
|
29
|
+
hydrant.run!
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "fire-hydrant"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.summary = "Fire Eagle XMPP PubSub tools"
|
5
|
+
s.description = "Tools for consuming Fire Eagle's XMPP PubSub feed."
|
6
|
+
s.authors = ["Seth Fitzsimmons"]
|
7
|
+
s.email = ["seth@mojodna.net"]
|
8
|
+
|
9
|
+
s.files = ["examples", "examples/authorize.rb", "examples/fire_eagle_consumer.rb", "examples/fire_eagle_visualizer.rb", "fire-hydrant.gemspec", "fire_hydrant.yml", "fire_hydrant.yml.development", "fire_hydrant.yml.production", "fire_hydrant.yml.sample", "lib", "lib/fire_hydrant", "lib/fire_hydrant/fire_hydrant.rb", "lib/fire_hydrant/jacks", "lib/fire_hydrant/jacks/fire_eagle_jack.rb", "lib/fire_hydrant/jacks.rb", "lib/fire_hydrant.rb", "README.markdown"]
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
|
12
|
+
s.add_dependency("fireeagle")
|
13
|
+
s.add_dependency("mojodna-switchboard")
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'fireeagle'
|
4
|
+
require 'switchboard'
|
5
|
+
rescue LoadError => e
|
6
|
+
gem = e.message.split("--").last.strip
|
7
|
+
puts "The #{gem} gem is required."
|
8
|
+
end
|
9
|
+
|
10
|
+
class FireHydrant < Switchboard::Core
|
11
|
+
DEFAULTS = {
|
12
|
+
"resource" => "fire_hydrant"
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(settings = {})
|
16
|
+
super(DEFAULTS.merge(settings), true)
|
17
|
+
plug!(FireEagleJack)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class FireEagleJack
|
2
|
+
def self.connect(switchboard, settings)
|
3
|
+
switchboard.plug!(AutoAcceptJack, NotifyJack, PubSubJack)
|
4
|
+
|
5
|
+
switchboard.on_pubsub_event do |event|
|
6
|
+
event.payload.each do |payload|
|
7
|
+
payload.elements.each do |item|
|
8
|
+
rsp = item.first_element("rsp")
|
9
|
+
response = FireEagle::Response.new(rsp.to_s)
|
10
|
+
user = response.users[0]
|
11
|
+
on(:location_update, user)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def switchboard.on_location_update(&block)
|
17
|
+
register_hook(:location_update, &block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'fire_hydrant/jacks/fire_eagle_jack'
|
data/lib/fire_hydrant.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mojodna-fire-hydrant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seth Fitzsimmons
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-27 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fireeagle
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: mojodna-switchboard
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
description: Tools for consuming Fire Eagle's XMPP PubSub feed.
|
34
|
+
email:
|
35
|
+
- seth@mojodna.net
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- examples
|
44
|
+
- examples/authorize.rb
|
45
|
+
- examples/fire_eagle_consumer.rb
|
46
|
+
- examples/fire_eagle_visualizer.rb
|
47
|
+
- fire-hydrant.gemspec
|
48
|
+
- fire_hydrant.yml
|
49
|
+
- fire_hydrant.yml.development
|
50
|
+
- fire_hydrant.yml.production
|
51
|
+
- fire_hydrant.yml.sample
|
52
|
+
- lib
|
53
|
+
- lib/fire_hydrant
|
54
|
+
- lib/fire_hydrant/fire_hydrant.rb
|
55
|
+
- lib/fire_hydrant/jacks
|
56
|
+
- lib/fire_hydrant/jacks/fire_eagle_jack.rb
|
57
|
+
- lib/fire_hydrant/jacks.rb
|
58
|
+
- lib/fire_hydrant.rb
|
59
|
+
- README.markdown
|
60
|
+
has_rdoc: false
|
61
|
+
homepage:
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 2
|
85
|
+
summary: Fire Eagle XMPP PubSub tools
|
86
|
+
test_files: []
|
87
|
+
|