Guest User

Untitled

a guest
May 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require '/Users/mattb/Work/Dopplr/code/dopplr/config/environment'
  3. require 'fire_hydrant'
  4. config = YAML.load(File.read("fire_hydrant.yml"))
  5.  
  6. hydrant = FireHydrant.new(config, false)
  7. hydrant.jack!(OAuthPubSubJack)
  8.  
  9. hydrant.on_startup do
  10. defer :subscribed do
  11. begin
  12. Identity.find(:all, :conditions => ["service = 'fireeagle' and identifier is not null"]).map { |i|
  13. puts i.identifier
  14. @config[:oauth_token] = i.identifier
  15. @config[:oauth_token_secret] = i.extra[:secret]
  16. [i, pubsub.subscribe_to("/api/0.1/user/#{@oauth_token.token}", @oauth_consumer, @oauth_token)]
  17. }
  18. rescue Jabber::ServerError => e
  19. puts e
  20. end
  21. end
  22.  
  23. # define here or as hydrant.subscriptions_received
  24. def subscribed(subs)
  25. if !subs.is_a? Array
  26. subs = [subs]
  27. end
  28. subs.each { |identity, subscription|
  29. if subscription.subscription == :subscribed
  30. puts "#{identity.traveller.name}: Subscribe successful."
  31. else
  32. puts "#{identity.traveller.name}: Subscribe failed!"
  33. end
  34. }
  35. end
  36. end
  37.  
  38. hydrant.run!
Add Comment
Please, Sign In to add comment