Commits

Shlomi Fish committed 76ea2d6

Add Notifier_app and the notifier program.

This is for use in the command line.

Comments (0)

Files changed (2)

App-Notifier-Client/lib/App/Notifier/Client/Notifier_App.pm

+package App::Notifier::Client::Notifier_App;
+
+use strict;
+use warnings;
+
+use Getopt::Long qw(GetOptionsFromArray);
+use Pod::Usage;
+
+use App::Notifier::Client;
+
+=head1 NAME
+
+App::Notifier::Client::Notifier_App - implements the notifier command-line
+app.
+
+=head1 SYNOPSIS
+
+    use strict;
+    use warnings;
+
+    use App::Notifier::Client::Notifier_App;
+
+    App::Notifier::Client::Notifier_App->new({argv => [@ARGV],})->run();
+
+=head1 FUNCTIONS
+
+=head2 new({argv => [@ARGV]})
+
+The constructor - call it with the command-line options.
+
+=cut
+
+sub new
+{
+    my $class = shift;
+    my $self = bless {}, $class;
+    $self->_init(@_);
+    return $self;
+}
+
+sub _argv
+{
+    my $self = shift;
+
+    if (@_) {
+        $self->{_argv} = shift;
+    }
+
+    return $self->{_argv};
+}
+
+
+sub _init
+{
+    my ($self, $args) = @_;
+
+    $self->_argv([ @{$args->{argv}} ]);
+
+    return;
+}
+
+=head2 run
+
+Actually run the command line application.
+
+=cut
+
+sub run
+{
+    my ($self) = @_;
+
+    my $argv = $self->_argv();
+
+    my $op = shift(@$argv);
+
+    if (!defined($op))
+    {
+        die "You did not specify any arguments - see --help";
+    }
+
+    if (($op eq "-h") || ($op eq "--help"))
+    {
+        pod2usage(1);
+    }
+    elsif ($op eq "--man")
+    {
+        pod2usage(-verbose => 2);
+    }
+
+    if ($op ne 'notify')
+    {
+        die "Unknown operation - '$op'!";
+    }
+
+    my $help = 0;
+    my $man = 0;
+    my ($to, $url, $cmd_id);
+    if (! (my $ret = GetOptionsFromArray(
+        $argv,
+        'help|h' => \$help,
+        man => \$man,
+        'to=s' => \$to,
+        'url=s' => \$url,
+        'cmd=s' => \$cmd_id,
+    )))
+    {
+        die "GetOptions failed!";
+    }
+
+    if ($help)
+    {
+        pod2usage(1);
+    }
+
+    if ($man)
+    {
+        pod2usage(-verbose => 2);
+    }
+
+    if (!defined($url))
+    {
+        if (!defined($to))
+        {
+            $to = 'default';
+        }
+
+        my $config_fn = ($ENV{'NOTIFIER_CONFIG'}
+            || File::Spec->catfile($ENV{HOME}, '.app_notifier.yml'));
+
+        my $config = LoadFile($config_fn);
+
+        my $host_config = $config->{client}->{targets}->{$to};
+
+        if (!defined($host_config))
+        {
+            die "Cannot find host config '$to' in $config_fn.";
+        }
+
+        $url = $host_config->{url};
+    }
+
+    if (!defined( $url ))
+    {
+        die "No URL specified - please specify one.";
+    }
+
+    App::Notifier::Client->notify(
+        {
+            base_url => $url,
+            ( defined($cmd_id) ? (cmd_id => $cmd_id) : () ),
+        }
+    );
+
+    return;
+}
+
+=head1 AUTHOR
+
+Shlomi Fish, L<http://www.shlomifish.org/>
+
+=head1 SEE ALSO
+
+L<App::Notifier::Client>, L<App::Notifier::Service> .
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2010 Shlomi Fish.
+
+This program is distributed under the MIT (X11) License:
+L<http://www.opensource.org/licenses/mit-license.php>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+
+=cut
+
+1; # End of Module::Format::PerlMF_App

App-Notifier-Client/script/notifier

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use App::Notifier::Client::Notifier_App;
+
+App::Notifier::Client::Notifier_App->new({argv => [@ARGV] })->run();
+
+exit(0);
+
+=head1 NAME
+
+notifier -- A command line client for the HTTP L<App::Notifier::Service>.
+
+=head1 USAGE
+
+    notifier notify --to=myhost
+    notifier notify # Same as --to=default
+    notifier notify --url=http://myhost.mydomain.tld:6300/mypath
+    notifier notify --cmd=shine
+
+=head1 OPTIONS
+
+    --to=$HOST - the identifier of the target URL in the configuration file.
+    --url=$URL - the URL (overrides -to)
+    --cmd=$CMD - the command ID to notify about (see App::Notifier::Service)
+
+=head1 DESCRIPTION
+
+This command line application sends an event to the notifier service.
+
+=head1 AUTHOR
+
+Shlomi Fish, L<http://www.shlomifish.org/> .
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-module-format at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module-Format>.  I will be notified, and then you'll
+automatically be notified of progress on your bug as I make changes.
+
+=head1 SEE ALSO
+
+L<App::Notifier::Client::Notifier_App> , L<App::Notifier::Service> ,
+L<App::Notifier::Client> .
+
+=head1 ACKNOWLEDGEMENTS
+
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2010 Shlomi Fish.
+
+This program is distributed under the MIT (X11) License:
+L<http://www.opensource.org/licenses/mit-license.php>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+=cut
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.