mattb (owner)

Forks

Revisions

gist: 22223 Download_button fork
public
Public Clone URL: git://gist.github.com/22223.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env ruby
require '/Users/mattb/Work/Dopplr/code/dopplr/config/environment'
require 'fire_hydrant'
config = YAML.load(File.read("fire_hydrant.yml"))
 
hydrant = FireHydrant.new(config, false)
hydrant.jack!(OAuthPubSubJack)
 
hydrant.on_startup do
    defer :subscribed do
        begin
            Identity.find(:all, :conditions => ["service = 'fireeagle' and identifier is not null"]).map { |i|
                puts i.identifier
                @config[:oauth_token] = i.identifier
                @config[:oauth_token_secret] = i.extra[:secret]
                [i, pubsub.subscribe_to("/api/0.1/user/#{@oauth_token.token}", @oauth_consumer, @oauth_token)]
            }
        rescue Jabber::ServerError => e
            puts e
        end
    end
 
    # define here or as hydrant.subscriptions_received
    def subscribed(subs)
        subs.each { |identity, subscription|
            if subscription.subscription == :subscribed
                puts "#{identity.traveller.name}: Subscribe successful."
            else
                puts "#{identity.traveller.name}: Subscribe failed!"
            end
        }
    end
end
 
hydrant.run!