Skip to content

Receive a notification when Kennedy Space Center schedules an upcoming launch πŸš€

Notifications You must be signed in to change notification settings

kevinmirc/space-launch-notifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Space Launch Notifier πŸš€

Receive a notification when Kennedy Space Center schedules an upcoming launch.

Usage Examples

You can use this service by requiring the main module and extending a specific notification:

  • Receive an email notification of the next launch.

    require_relative './domain/space_launch_notifier' 
    require_relative './notifications/email_notification'
    
    SpaceLaunchNotifier.extend(EmailNotification)
    SpaceLaunchNotifier.broadcast!(:next)
  • Receive a MacOS notification of the next launch happening within three days from now.

    require_relative './domain/space_launch_notifier' 
    require_relative './notifications/macbook_notification'
    
    SpaceLaunchNotifier.extend(MacbookNotification)
    SpaceLaunchNotifier.broadcast!(:next) do |upcoming_events|
      three_days_from_now = DateTime.now + 3
      upcoming_events.filter { |event| event.start < three_days_from_now }
    end

Adding a Notification Provider

Create a custom Notification module by creating a class.

Requirements

Your custom notification class should accept these massages:

  • .from_event(event)
    • Accepts an argument of an instance of KennedySpaceCenter::Event
    • Returns an initialized instance of self.
  • #fire!
    • Accepts no arguments.
    • Return anything (for now).

Example

module TwilioNotification
  class Notification
    attr_accessor :title, :desciption, :date

    class << self
      # Returns an instance initialized from an event.
      #
      # @param event [KennedySpaceCenter::Event] a Kennedy Space Center event.
      # @return [MacbookNotification::Notification] a new instance of this class.
      def from_event(event)
        new(
          title: 'Space Launch Imminent!',
          desciption: event.short_summary,
          date: event.start_display
        )
      end
    end

    def initialize(title:, desciption:, date:)
      # ... Configure the settings for this notification.
    end

    # Triggers the delivery of this notification synchronously.
    # Raises any error that causes a failure in the delivery.
    #
    def fire!
      # ... Send text message.
    end
  end
end

SpaceLaunchNotifier.extend(TwilioNotification)
SpaceLaunchNotifier.broadcast!(:next)

More Examples

See ./bin for more examples.

About

Receive a notification when Kennedy Space Center schedules an upcoming launch πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages