| 1 | package WebService::Mattermost::Role::UserAgent; | ||
| 2 | |||
| 3 | # ABSTRACT: Internal user agent role. | ||
| 4 | |||
| 5 | 13 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 13 | ▶ | use Types::Standard 'InstanceOf'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 13 | ▶ | use WebService::Mattermost::Util::UserAgent; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 13 | ▶ | use WebService::Mattermost::Helper::Alias 'util'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | ################################################################################ | ||
| 12 | |||
| 13 | 13 | has ua => (is => 'ro', isa => InstanceOf['Mojo::UserAgent'], lazy => 1, builder => 1); | |
| 14 | |||
| 15 | ################################################################################ | ||
| 16 | |||
| 17 | sub mmauthtoken { | ||
| 18 | 1 | ▶ | my $self = shift; |
|
Subroutine
mmauthtoken: called CC=1 SCAR=0.0
Pod
documented
| |||
| 19 | 1 | my $token = shift; | |
| 20 | |||
| 21 | 1 | return sprintf 'MMAUTHTOKEN=%s', $token; | |
| 22 | } | ||
| 23 | |||
| 24 | sub bearer { | ||
| 25 | 17 | ▶ | my $self = shift; |
|
Subroutine
bearer: called CC=1 SCAR=0.0
Pod
documented
| |||
| 26 | 17 | my $token = shift; | |
| 27 | |||
| 28 | 17 | return sprintf 'Bearer %s', $token; | |
| 29 | } | ||
| 30 | |||
| 31 | ################################################################################ | ||
| 32 | |||
| 33 | sub _build_ua { | ||
| 34 | 20 | ▶ | return util('UserAgent')->new->ua; |
|
Subroutine
_build_ua: called CC=1 SCAR=0.0
| |||
| 35 | } | ||
| 36 | |||
| 37 | ################################################################################ | ||
| 38 | |||
| 39 | 13 | 1; | |
| 40 | |||
| 41 | __END__ | ||
| 42 | |||
| 43 | =pod | ||
| 44 | |||
| 45 | =encoding UTF-8 | ||
| 46 | |||
| 47 | =head1 NAME | ||
| 48 | |||
| 49 | WebService::Mattermost::Role::UserAgent - Internal user agent role. | ||
| 50 | |||
| 51 | =head1 VERSION | ||
| 52 | |||
| 53 | version 0.28 | ||
| 54 | |||
| 55 | =head1 DESCRIPTION | ||
| 56 | |||
| 57 | Bundles C<Mojo::UserAgent> and required parameters for HTTP headers. | ||
| 58 | |||
| 59 | =head2 USAGE | ||
| 60 | |||
| 61 | use Moo; | ||
| 62 | |||
| 63 | with 'WebService::Mattermost::Role::UserAgent'; | ||
| 64 | |||
| 65 | sub something { | ||
| 66 | my $self = shift; | ||
| 67 | |||
| 68 | my $bearer_header = $self->bearer; | ||
| 69 | my $mmauthtoken = $self->mmauthtoken; | ||
| 70 | |||
| 71 | # Methods from Mojo::UserAgent | ||
| 72 | $self->ua->post( | ||
| 73 | # ... | ||
| 74 | ); | ||
| 75 | } | ||
| 76 | |||
| 77 | =head2 ATTRIBUTES | ||
| 78 | |||
| 79 | =over 4 | ||
| 80 | |||
| 81 | =item C<ua> | ||
| 82 | |||
| 83 | A C<Mojo::UserAgent> object. | ||
| 84 | |||
| 85 | =back | ||
| 86 | |||
| 87 | =head2 METHODS | ||
| 88 | |||
| 89 | =over 4 | ||
| 90 | |||
| 91 | =item C<mmauthtoken()> | ||
| 92 | |||
| 93 | Formats the C<MMAUTHTOKEN> header. | ||
| 94 | |||
| 95 | =item C<bearer> | ||
| 96 | |||
| 97 | Formats the C<Bearer> header. | ||
| 98 | |||
| 99 | =back | ||
| 100 | |||
| 101 | =head1 AUTHOR | ||
| 102 | |||
| 103 | Mike Jones <mike@netsplit.org.uk> | ||
| 104 | |||
| 105 | =head1 COPYRIGHT AND LICENSE | ||
| 106 | |||
| 107 | This software is Copyright (c) 2020 by Mike Jones. | ||
| 108 | |||
| 109 | This is free software, licensed under: | ||
| 110 | |||
| 111 | The MIT (X11) License | ||
| 112 | |||
| 113 | =cut | ||