Nenhuma Descrição http://j1x-huginn.herokuapp.com

google_calendar_publish_agent.rb 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module Agents
  2. class GoogleCalendarPublishAgent < Agent
  3. include LiquidInterpolatable
  4. cannot_be_scheduled!
  5. description <<-MD
  6. The GoogleCalendarPublishAgent creates events on your google calendar.
  7. Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
  8. MD
  9. def validate_options
  10. errors.add(:base, "expected_update_period_in_days is required") unless options['expected_update_period_in_days'].present?
  11. end
  12. def working?
  13. event_created_within?(options['expected_update_period_in_days']) && most_recent_event && most_recent_event.payload['success'] == true && !recent_error_logs?
  14. end
  15. def default_options
  16. {
  17. 'expected_update_period_in_days' => "10",
  18. 'calendar_id' => '?',
  19. 'message' => "{{text}}"
  20. }
  21. end
  22. def receive(incoming_events)
  23. incoming_events.each do |event|
  24. text = interpolate_string(options['message'], event.payload)
  25. calendar_event = publish text
  26. create_event :payload => {
  27. 'success' => true,
  28. 'published_calendar_event' => text,
  29. 'tweet_id' => calendar_event.id,
  30. 'agent_id' => event.agent_id,
  31. 'event_id' => event.id
  32. }
  33. end
  34. end
  35. def publish(text)
  36. calendar = GoogleCalendar.new(options, Rails.logger)
  37. calender.publish_as(options['calendar_id'], text)
  38. end
  39. end
  40. end