| 1 | package Net::OneTimeSecret; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION = "0.04"; | |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use common::sense; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Encode qw( encode_utf8 decode_utf8 ); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | my $_USER_AGENT = LWP::UserAgent->new(); | |||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my $_API_VERSION = "v1"; | |||||||||||||||||||||||||||||||||||||||
| 13 | 1 | my $_BASE_URL = 'https://%s:%s@onetimesecret.com/api/'.$_API_VERSION; | |||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $_SECRET_TTL = 3600; | |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub __url_for { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__url_for: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my ($self, $action, $user, $password) = @_; | |||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | $user ||= $self->customerId(); | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$user ||= $self->customerId
MC/DC0%0/2
$user ||= $self->customerId
$user
$self->customerId
Truth table33%1/3
A ||= B
A= $userB= $self->customerId
| |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | $password ||= $self->apiKey(); | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$password ||= $self->apiKey
MC/DC0%0/2
$password ||= $self->apiKey
$password
$self->apiKey
Truth table33%1/3
A ||= B
A= $passwordB= $self->apiKey
| |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | return sprintf( | |||||||||||||||||||||||||||||||||||||||
| 22 | $_BASE_URL, | ||||||||||||||||||||||||||||||||||||||||
| 23 | uri_escape( $user ), | ||||||||||||||||||||||||||||||||||||||||
| 24 | uri_escape( $password ) | ||||||||||||||||||||||||||||||||||||||||
| 25 | ) . $action; | ||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||
| 30 | 1 | my $customerId = shift; | |||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $apiKey = shift; | |||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my %options = ( @_ ); | |||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||
| 35 | _customerId => $customerId, | ||||||||||||||||||||||||||||||||||||||||
| 36 | _apiKey => $apiKey, | ||||||||||||||||||||||||||||||||||||||||
| 37 | }, $class; | ||||||||||||||||||||||||||||||||||||||||
| 38 | # process other options... | ||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub _post { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_post: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my ($self, $url, $data) = @_; | |||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | $data ||= {}; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$data ||= {}
MC/DC0%0/1
$data ||= {}
$data
Truth table50%1/2
A
A= $data
| |||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | foreach my $key (keys %$data) { | |||||||||||||||||||||||||||||||||||||||
| 46 | 4 | ▶ | delete $data->{$key} unless defined $data->{$key}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | my $response = $_USER_AGENT->post( $url, 'Content' => $data ); | |||||||||||||||||||||||||||||||||||||||
| 49 | 1 | return from_json( decode_utf8( $response->decoded_content ) ); | |||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub _get { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my ($self, $url) = @_; | |||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $response = $_USER_AGENT->get( $url ); | |||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return from_json( $response->decoded_content ); | |||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return $self->_get( $self->__url_for( "/status" ) ); | |||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub shareSecret { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
shareSecret: called CC=4 SCAR=15.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my $secret = shift; | |||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my $options = { @_ }; | |||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||
| 68 | return $self->_post( $self->__url_for( "/share" ), { | ||||||||||||||||||||||||||||||||||||||||
| 69 | secret => $secret, | ||||||||||||||||||||||||||||||||||||||||
| 70 | ttl => $options->{ttl} || $_SECRET_TTL, | ||||||||||||||||||||||||||||||||||||||||
| 71 | recipient => $options->{recipient} || undef, | ||||||||||||||||||||||||||||||||||||||||
| 72 | passphrase => $options->{passphrase} || undef, | ||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | }); | ||||||||||||||||||||||||||||||||||||||
|
Condition42%3/7
$options->{'ttl'} || $_SECRET_TTL
$options->{'recipient'} || undef
$options->{'passphrase'} || undef
MC/DC0%0/2
$options->{'ttl'} || $_SECRET_TTL
$options->{'ttl'}
$_SECRET_TTL
MC/DC0%0/1
$options->{'recipient'} || undef
$options->{'recipient'}
MC/DC0%0/1
$options->{'passphrase'} || undef
$options->{'passphrase'}
Truth table33%1/3
A || B
A= $options->{'ttl'}B= $_SECRET_TTL
Truth table50%1/2
A
A= $options->{'recipient'}
Truth table50%1/2
A
A= $options->{'passphrase'}
| |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub generateSecret { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
generateSecret: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $options = { @_ }; | |||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return $self->_post( $self->__url_for( "/generate" )); | |||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub retrieveSecret { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
retrieveSecret: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $options = { @_ }; | |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return $self->_post( $self->__url_for( sprintf("/secret/%s", $key) ), $options ); | |||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub retrieveMetadata { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
retrieveMetadata: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $self->_post( $self->__url_for( sprintf("/private/%s", $key) ) ); | |||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | sub customerId { return $_[0]->{_customerId} }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
customerId: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub setCustomerId { $_[0]->{_customerId} = shift }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
setCustomerId: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | sub apiKey { return $_[0]->{_apiKey} }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
apiKey: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub setApiKey { $_[0]->{_apiKey} = shift }; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
setApiKey: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||
| 101 | __END__ | ||||||||||||||||||||||||||||||||||||||||