| 1 | package WWW::MailboxOrg::API::Base; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Base API controller for auth and search | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use MooX::Singleton; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Params::ValidationCompiler qw(validation_for); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Types::Standard qw(Str); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | our $VERSION = '0.001'; | |||||||||
| 12 | |||||||||||
| 13 | 1 | has client => ( | |||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | required => 1, | ||||||||||
| 16 | weak_ref => 1, | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | sub _rpc { | ||||||||||
| 20 | 0 | ▶ | my ($self, $method, @params) = @_; | ||||||||
|
Subroutine
_rpc: not called CC=2 SCAR=17.9
| |||||||||||
| 21 | 0 | ▶ | my $client = $self->client or croak "No client set"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | return $client->call($method, @params); | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 1 | my %validators = ( | |||||||||
| 26 | auth => validation_for( | ||||||||||
| 27 | params => { | ||||||||||
| 28 | user => { type => Str, optional => 0 }, | ||||||||||
| 29 | pass => { type => Str, optional => 0 }, | ||||||||||
| 30 | }, | ||||||||||
| 31 | ), | ||||||||||
| 32 | search => validation_for( | ||||||||||
| 33 | params => { | ||||||||||
| 34 | query => { type => Str, optional => 0 }, | ||||||||||
| 35 | }, | ||||||||||
| 36 | ), | ||||||||||
| 37 | ); | ||||||||||
| 38 | |||||||||||
| 39 | sub auth { | ||||||||||
| 40 | 0 | ▶ | my ($self, %params) = @_; | ||||||||
|
Subroutine
auth: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 41 | 0 | my $v = $validators{'auth'}; | |||||||||
| 42 | 0 | ▶ | %params = $v->(%params) if $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | return $self->_rpc('auth', \%params); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | sub deauth { | ||||||||||
| 47 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
deauth: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | 0 | return $self->_rpc('deauth'); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | sub search { | ||||||||||
| 52 | 0 | ▶ | my ($self, %params) = @_; | ||||||||
|
Subroutine
search: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 53 | 0 | my $v = $validators{'search'}; | |||||||||
| 54 | 0 | ▶ | %params = $v->(%params) if $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | return $self->_rpc('search', \%params); | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 1 | 1; | |||||||||
| 59 | |||||||||||
| 60 | __END__ | ||||||||||
| 61 | |||||||||||
| 62 | =pod | ||||||||||
| 63 | |||||||||||
| 64 | =encoding UTF-8 | ||||||||||
| 65 | |||||||||||
| 66 | =head1 NAME | ||||||||||
| 67 | |||||||||||
| 68 | WWW::MailboxOrg::API::Base - Base API controller for auth and search | ||||||||||
| 69 | |||||||||||
| 70 | =head1 VERSION | ||||||||||
| 71 | |||||||||||
| 72 | version 0.001 | ||||||||||
| 73 | |||||||||||
| 74 | =head1 NAME | ||||||||||
| 75 | |||||||||||
| 76 | WWW::MailboxOrg::API::Base - Base API controller for auth and search | ||||||||||
| 77 | |||||||||||
| 78 | =head2 auth | ||||||||||
| 79 | |||||||||||
| 80 | $api->base->auth(user => 'user@example.com', pass => 'secret'); | ||||||||||
| 81 | |||||||||||
| 82 | Authenticate and get session token. Required: C<user>, C<pass>. | ||||||||||
| 83 | |||||||||||
| 84 | =head2 deauth | ||||||||||
| 85 | |||||||||||
| 86 | $api->base->deauth; | ||||||||||
| 87 | |||||||||||
| 88 | End the current session. | ||||||||||
| 89 | |||||||||||
| 90 | =head2 search | ||||||||||
| 91 | |||||||||||
| 92 | my $results = $api->base->search(query => 'some search terms'); | ||||||||||
| 93 | |||||||||||
| 94 | Search across the API. Required: C<query>. | ||||||||||
| 95 | |||||||||||
| 96 | =cut | ||||||||||
| 97 | |||||||||||
| 98 | =head1 SUPPORT | ||||||||||
| 99 | |||||||||||
| 100 | =head2 Issues | ||||||||||
| 101 | |||||||||||
| 102 | Please report bugs and feature requests on GitHub at | ||||||||||
| 103 | L<https://github.com/getty/p5-www-mailboxorg/issues>. | ||||||||||
| 104 | |||||||||||
| 105 | =head2 IRC | ||||||||||
| 106 | |||||||||||
| 107 | Join C<#perl-help> on C<irc.perl.org> or message Getty directly. | ||||||||||
| 108 | |||||||||||
| 109 | =head1 CONTRIBUTING | ||||||||||
| 110 | |||||||||||
| 111 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||
| 112 | |||||||||||
| 113 | =head1 AUTHOR | ||||||||||
| 114 | |||||||||||
| 115 | Torsten Raudssus <getty@cpan.org> | ||||||||||
| 116 | |||||||||||
| 117 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 118 | |||||||||||
| 119 | This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/>. | ||||||||||
| 120 | |||||||||||
| 121 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 122 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 123 | |||||||||||
| 124 | =cut | ||||||||||