Нет описания http://j1x-huginn.herokuapp.com

pushbullet_agent.rb 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. module Agents
  2. class PushbulletAgent < Agent
  3. cannot_be_scheduled!
  4. cannot_create_events!
  5. description <<-MD
  6. The Pushbullet agent sends pushes to a pushbullet device
  7. To authenticate you need to set the `api_key`, you can find yours at your account page:
  8. `https://www.pushbullet.com/account`
  9. Currently you need to get a the device identification manually:
  10. `curl -u <your api key here>: https://api.pushbullet.com/api/devices`
  11. To register a new device run the following command:
  12. `curl -u <your api key here>: -X POST https://api.pushbullet.com/v2/devices -d nickname=huginn -d type=stream`
  13. Put one of the retured `iden` strings into the `device_id` field.
  14. You can provide a `title` and a `body`.
  15. In every value of the options hash you can use the liquid templating, learn more about it at the [Wiki](https://github.com/cantino/huginn/wiki/Formatting-Events-using-Liquid).
  16. MD
  17. def default_options
  18. {
  19. 'api_key' => '',
  20. 'device_id' => '',
  21. 'title' => "Hello from Huginn!",
  22. 'body' => '{{body}}',
  23. }
  24. end
  25. def validate_options
  26. errors.add(:base, "you need to specify a pushbullet api_key") unless options['api_key'].present?
  27. errors.add(:base, "you need to specify a device_id") if options['device_id'].blank?
  28. end
  29. def working?
  30. received_event_without_error?
  31. end
  32. def receive(incoming_events)
  33. incoming_events.each do |event|
  34. response = HTTParty.post "https://api.pushbullet.com/api/pushes", query_options(event)
  35. error(response.body) if response.body.include? 'error'
  36. end
  37. end
  38. private
  39. def query_options(event)
  40. mo = interpolated(event)
  41. {
  42. :basic_auth => {:username => mo[:api_key], :password => ''},
  43. :body => {:device_iden => mo[:device_id], :title => mo[:title], :body => mo[:body], :type => 'note'}
  44. }
  45. end
  46. end
  47. end