blib/lib/PEF/Front/Oauth/Yandex.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 76 CC 2 SCAR 9.8
CC
2
Cov
0%
_parse_user_info
6.0
_authorization_server
2.0
_token_request
2.0
CRAP 2.7
1 package PEF::Front::Oauth::Yandex;
2  
3 use strict;
4 use warnings;
5 use base 'PEF::Front::Oauth';
6 use HTTP::Request::Common;
7 use feature 'state';
8 use PEF::Front::Config;
9  
10 sub _authorization_server {
11 'https://oauth.yandex.ru/authorize';
12 }
13  
14 sub _token_request {
15 my ($self, $code) = @_;
16 POST 'https://oauth.yandex.ru/token', [
17 grant_type => 'authorization_code',
18 code => $code,
19 client_id => cfg_oauth_client_id($self->{service}),
20 client_secret => cfg_oauth_client_secret($self->{service})
21 ];
22 }
23  
24 sub _get_user_info_request {
25 my ($self) = @_;
26 my $req = GET 'https://login.yandex.ru/info';
27 $req->uri->query_form(
28 format => 'json',
29 oauth_token => $self->{session}->data->{oauth_access_token}{$self->{service}}
30 );
31 $req;
32 }
33  
34 sub _parse_user_info {
35 my ($self) = @_;
36 state $sizes = [
37 'islands-small' => 28,
38 'islands-34' => 34,
39 'islands-middle' => 42,
40 'islands-50' => 50,
41 'islands-retina-small' => 56,
42 'islands-68' => 68,
43 'islands-75' => 75,
44 'islands-retina-middle' => 84,
45 'islands-retina-50' => 100,
46 'islands-200' => 200
47 ];
48 my $info = $self->{session}->data->{oauth_info_raw}{$self->{service}};
49 my @avatar;
50 if ($info->{default_avatar_id}) {
51 for (my $i = 0 ; $i < @$sizes ; $i += 2) {
52 my $sn = $sizes->[$i];
53 my $size = $sizes->[$i + 1];
54 push @avatar,
55 { url => "https://avatars.yandex.net/get-yapic/$info->{default_avatar_id}/$sn",
56 size => $size
57 };
58 }
59 }
60 my $name = $info->{real_name} || $info->{display_name} || '';
61 return {
62 name => $name,
63 email => $info->{default_email} || $info->{login} || '',
64 login => $info->{login} || '',
65 avatar => \@avatar,
66 };
67 }
68  
69 sub new {
70 my ($class, $self) = @_;
71 bless $self, $class;
72 }
73  
74 1;