| 1 | package Net::OpenSocial::Client::HTTPRequestBuilder::OAuth; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | with 'Net::OpenSocial::Client::HTTPRequestBuilder'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use OAuth::Lite::Consumer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use OAuth::Lite::AuthMethod qw(URL_QUERY); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use OAuth::Lite::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use bytes (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | has 'consumer_secret' => ( | |||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||
| 15 | isa => 'Str', | ||||||||||||||||||||||||||||
| 16 | required => 1, | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | has 'consumer_key' => ( | |||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||
| 21 | isa => 'Str', | ||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | has 'token' => ( | |||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||
| 27 | isa => 'OAuth::Lite::Token', | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | has 'requestor' => ( | |||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||
| 32 | isa => 'Str', | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub build_request { | ||||||||||||||||||||||||||
|
Subroutine
build_request: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $method = $args{method}; | |||||||||||||||||||||||||||
| 39 | 0 | my $url = $args{url}; | |||||||||||||||||||||||||||
| 40 | 0 | my $params = $args{params}; | |||||||||||||||||||||||||||
| 41 | 0 | my $content_type = $args{content_type}; | |||||||||||||||||||||||||||
| 42 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 43 | 0 | my $container = $args{container}; | |||||||||||||||||||||||||||
| 44 | 0 | my $token = $self->token; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $params ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$params ||= {}
MC/DC0%0/1
$params ||= {}
$params
Truth table0%0/2
A
A= $params
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $params->{xoauth_requestor_id} = $self->requestor | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | if $self->requestor; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $use_request_body_hash = $container->use_request_body_hash ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # now OAuth::Lite 1.16 supports Request Body Hash | ||||||||||||||||||||||||||||
| 53 | 0 | my $consumer = OAuth::Lite::Consumer->new( | |||||||||||||||||||||||||||
| 54 | consumer_key => $self->consumer_key, | ||||||||||||||||||||||||||||
| 55 | consumer_secret => $self->consumer_secret, | ||||||||||||||||||||||||||||
| 56 | auth_method => URL_QUERY, | ||||||||||||||||||||||||||||
| 57 | use_request_body_hash => $use_request_body_hash, | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my %oauth_args = ( | |||||||||||||||||||||||||||
| 61 | method => $method, | ||||||||||||||||||||||||||||
| 62 | url => $url, | ||||||||||||||||||||||||||||
| 63 | params => $params, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $oauth_args{token} = $token if $token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( $method eq 'POST' || $method eq 'PUT' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$method eq "POST" or $method eq "PUT"
MC/DC0%0/2
$method eq "POST" or $method eq "PUT"
$method eq "POST"
$method eq "PUT"
Truth table0%0/3
A or B
A= $method eq "POST"B= $method eq "PUT"
| |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | $oauth_args{content} = $content if $content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | $oauth_args{headers} = [ 'Content-Type' => $content_type ]; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 0 | my $http_req = $consumer->gen_oauth_request(%oauth_args); | |||||||||||||||||||||||||||
| 71 | 0 | return $http_req; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | no Any::Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 NAME | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Net::OpenSocial::Client::HTTPRequestBuilder::OAuth - OAuth request builder | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # 3legged | ||||||||||||||||||||||||||||
| 85 | # get access token beforehand. | ||||||||||||||||||||||||||||
| 86 | my $builder = Net::OpenSocial::Client::HTTPRequestBuilder::OAuth->new( | ||||||||||||||||||||||||||||
| 87 | consumer_key => $consumer_key, | ||||||||||||||||||||||||||||
| 88 | consumer_secret => $consumer_secret, | ||||||||||||||||||||||||||||
| 89 | token => $access_token, | ||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # or 2legged | ||||||||||||||||||||||||||||
| 93 | my $builder = Net::OpenSocial::Client::HTTPRequestBuilder::OAuth->new( | ||||||||||||||||||||||||||||
| 94 | consumer_key => $consumer_key, | ||||||||||||||||||||||||||||
| 95 | consumer_secret => $consumer_secret, | ||||||||||||||||||||||||||||
| 96 | requestor => $xoauth_requestor_id, | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | my $http_request = $builder->build_request(); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 METHODS | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head2 build_request | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | Lyo Kato, E<lt>lyo.kato@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | Copyright (C) 2009 by Lyo Kato | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 116 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 117 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||