| 1 | package Prosody::Mod::Data::Access; | ||||||||||||
| 2 | 1 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | $Prosody::Mod::Data::Access::AUTHORITY = 'cpan:GETTY'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | { | ||||||||||||
| 6 | 1 | $Prosody::Mod::Data::Access::VERSION = '0.007'; | |||||||||||
| 7 | } | ||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use LWP::UserAgent; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 1 | ▶ | use JSON; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use Encode; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use HTTP::Request; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 1 | ▶ | our $VERSION ||= '0.0development'; | ||||||||||
|
Condition50%1/2
our $VERSION ||= "0.0development"
MC/DC0%0/1
our $VERSION ||= "0.0development"
our $VERSION
Truth table50%1/2
A
A= our $VERSION
| |||||||||||||
| 16 | |||||||||||||
| 17 | 1 | has hostname => ( | |||||||||||
| 18 | is => 'ro', | ||||||||||||
| 19 | isa => 'Str', | ||||||||||||
| 20 | lazy_build => 1, | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | 0 | ▶ | sub _build_hostname { 'localhost' } | ||||||||||
|
Subroutine
_build_hostname: not called CC=1 SCAR=6.9
| |||||||||||||
| 24 | |||||||||||||
| 25 | 1 | has port => ( | |||||||||||
| 26 | is => 'ro', | ||||||||||||
| 27 | isa => 'Int', | ||||||||||||
| 28 | lazy_build => 1, | ||||||||||||
| 29 | ); | ||||||||||||
| 30 | |||||||||||||
| 31 | 0 | ▶ | sub _build_port { '5280' } | ||||||||||
|
Subroutine
_build_port: not called CC=1 SCAR=6.9
| |||||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | sub first_path_part { 'data' } | ||||||||||
|
Subroutine
first_path_part: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 34 | |||||||||||||
| 35 | 1 | has jid => ( | |||||||||||
| 36 | is => 'ro', | ||||||||||||
| 37 | isa => 'Str', | ||||||||||||
| 38 | required => 1, | ||||||||||||
| 39 | ); | ||||||||||||
| 40 | |||||||||||||
| 41 | 1 | has password => ( | |||||||||||
| 42 | is => 'ro', | ||||||||||||
| 43 | isa => 'Str', | ||||||||||||
| 44 | required => 1, | ||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | 0 | ▶ | sub http_agent { __PACKAGE__.'/'.$VERSION } | ||||||||||
|
Subroutine
http_agent: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 48 | |||||||||||||
| 49 | 1 | has _useragent => ( | |||||||||||
| 50 | is => 'ro', | ||||||||||||
| 51 | isa => 'LWP::UserAgent', | ||||||||||||
| 52 | lazy_build => 1, | ||||||||||||
| 53 | ); | ||||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | sub _build__useragent { | ||||||||||
|
Subroutine
_build__useragent: not called CC=1 SCAR=6.9
| |||||||||||||
| 56 | 0 | my ( $self ) = @_; | |||||||||||
| 57 | 0 | my $ua = LWP::UserAgent->new; | |||||||||||
| 58 | 0 | $ua->agent($self->http_agent); | |||||||||||
| 59 | 0 | return $ua; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 1 | has base_path => ( | |||||||||||
| 63 | is => 'ro', | ||||||||||||
| 64 | isa => 'Str', | ||||||||||||
| 65 | lazy_build => 1, | ||||||||||||
| 66 | ); | ||||||||||||
| 67 | |||||||||||||
| 68 | 0 | ▶ | sub _build_base_path { | ||||||||||
|
Subroutine
_build_base_path: not called CC=1 SCAR=6.9
| |||||||||||||
| 69 | 0 | my ( $self ) = @_; | |||||||||||
| 70 | 0 | my @jid_parts = split('@',$self->jid); | |||||||||||
| 71 | 0 | return 'http://'.$self->hostname.':'.$self->port.'/'.$self->first_path_part.'/'.$jid_parts[1].'/'; | |||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | 0 | ▶ | sub get { | ||||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 75 | 0 | my ( $self, $user, $store ) = @_; | |||||||||||
| 76 | 0 | ▶ | $store = 'accounts' if !$store; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 0 | my $url = $self->base_path.$user.'/'.$store.'/json'; | |||||||||||
| 78 | 0 | my $req = HTTP::Request->new('GET',$url); | |||||||||||
| 79 | 0 | $req->authorization_basic($self->jid,$self->password); | |||||||||||
| 80 | 0 | my $res = $self->_useragent->request($req); | |||||||||||
| 81 | 0 | ▶ | if ($res->is_success) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | return decode_json(encode('utf8', $res->content)); | |||||||||||
| 83 | } else { | ||||||||||||
| 84 | 0 | die __PACKAGE__." error on HTTP request: ".$res->status_line; | |||||||||||
| 85 | } | ||||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | 0 | ▶ | sub put { | ||||||||||
|
Subroutine
put: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 89 | 0 | my ( $self, $user, $store, $data ) = @_; | |||||||||||
| 90 | 0 | ▶ | $store = 'accounts' if !$store; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | 0 | my @jid_parts = split('@',$self->jid); | |||||||||||
| 92 | 0 | my $url = $self->base_path.$user.'/'.$store.'/lua'; | |||||||||||
| 93 | 0 | my $req = HTTP::Request->new('PUT',$url); | |||||||||||
| 94 | 0 | $req->content(encode_json($data)); | |||||||||||
| 95 | 0 | $req->header('Content-Type' => 'application/json'); | |||||||||||
| 96 | 0 | $req->authorization_basic($self->jid,$self->password); | |||||||||||
| 97 | 0 | my $res = $self->_useragent->request($req); | |||||||||||
| 98 | 0 | ▶ | if ($res->is_success) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 99 | 0 | return 1; | |||||||||||
| 100 | } else { | ||||||||||||
| 101 | 0 | die __PACKAGE__." error on HTTP request: ".$res->status_line; | |||||||||||
| 102 | } | ||||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 1 | 1; | |||||||||||
| 106 | __END__ | ||||||||||||