| 1 | package WWW::Ohloh::API::Kudo; | ||||||||||
| 2 | |||||||||||
| 3 | 15 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 15 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 15 | ▶ | use Object::InsideOut; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 15 | ▶ | use XML::LibXML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 15 | ▶ | use WWW::Ohloh::API::KudoScore; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 15 | our $VERSION = '0.3.2'; | |||||||||
| 12 | |||||||||||
| 13 | 15 | my @api_fields = qw/ | |||||||||
| 14 | created_at | ||||||||||
| 15 | sender_account_id | ||||||||||
| 16 | sender_account_name | ||||||||||
| 17 | receiver_account_name | ||||||||||
| 18 | receiver_account_id | ||||||||||
| 19 | project_id | ||||||||||
| 20 | project_name | ||||||||||
| 21 | contributor_id | ||||||||||
| 22 | contributor_name | ||||||||||
| 23 | /; | ||||||||||
| 24 | |||||||||||
| 25 | 15 | my @created_at_of : Field : Set(_set_created_at) : Get(created_at); | |||||||||
| 26 | 15 | my @sender_account_id_of : Field : Set(_set_sender_account_id) : | |||||||||
| 27 | Get(sender_account_id); | ||||||||||
| 28 | 15 | my @sender_account_name_of : Field : Set(_set_sender_account_name) : | |||||||||
| 29 | Get(sender_account_name); | ||||||||||
| 30 | 15 | my @receiver_account_name_of : Field : Set(_set_receiver_account_name) : | |||||||||
| 31 | Get(receiver_account_name); | ||||||||||
| 32 | 15 | my @receiver_account_id_of : Field : Set(_set_receiver_account_id) : | |||||||||
| 33 | Get(receiver_account_id); | ||||||||||
| 34 | 15 | my @project_id_of : Field : Set(_set_project_id) : Get(project_id); | |||||||||
| 35 | 15 | my @project_name_of : Field : Set(_set_project_name) : Get(project_name); | |||||||||
| 36 | 15 | my @contributor_id_of : Field : Set(_set_contributor_id) : | |||||||||
| 37 | Get(contributor_id); | ||||||||||
| 38 | 15 | my @contributor_name_of : Field : Set(_set_contributor_name) : | |||||||||
| 39 | Get(contributor_name); | ||||||||||
| 40 | |||||||||||
| 41 | 15 | my @request_url_of : Field : Arg(request_url) : Get( request_url ); | |||||||||
| 42 | 15 | my @xml_of : Field : Arg(xml); | |||||||||
| 43 | 15 | my @ohloh_of : Field : Arg(ohloh) : Get(_ohloh); | |||||||||
| 44 | |||||||||||
| 45 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 46 | |||||||||||
| 47 | sub _init : Init { | ||||||||||
| 48 | 70 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||
| 49 | |||||||||||
| 50 | 70 | ▶ | my $dom = $xml_of[$$self] or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 70 | $self->_set_created_at( $dom->findvalue("created_at/text()") ); | |||||||||
| 53 | 70 | $self->_set_sender_account_id( | |||||||||
| 54 | $dom->findvalue("sender_account_id/text()") ); | ||||||||||
| 55 | 70 | $self->_set_sender_account_name( | |||||||||
| 56 | $dom->findvalue("sender_account_name/text()") ); | ||||||||||
| 57 | 70 | $self->_set_receiver_account_name( | |||||||||
| 58 | $dom->findvalue("receiver_account_name/text()") ); | ||||||||||
| 59 | 70 | $self->_set_receiver_account_id( | |||||||||
| 60 | $dom->findvalue("receiver_account_id/text()") ); | ||||||||||
| 61 | 70 | $self->_set_project_id( $dom->findvalue("project_id/text()") ); | |||||||||
| 62 | 70 | $self->_set_project_name( $dom->findvalue("project_name/text()") ); | |||||||||
| 63 | 70 | $self->_set_contributor_id( $dom->findvalue("contributor_id/text()") ); | |||||||||
| 64 | 70 | $self->_set_contributor_name( | |||||||||
| 65 | $dom->findvalue("contributor_name/text()") ); | ||||||||||
| 66 | 15 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 67 | |||||||||||
| 68 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 69 | |||||||||||
| 70 | sub recipient_type { | ||||||||||
| 71 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
recipient_type: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | return $self->receiver_account_id ? 'account' : 'contributor'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 77 | |||||||||||
| 78 | sub sender { | ||||||||||
| 79 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
sender: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 80 | |||||||||||
| 81 | 1 | return $self->_ohloh->get_account( id => $self->sender_account_id ); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 85 | |||||||||||
| 86 | sub receiver { | ||||||||||
| 87 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
receiver: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||
| 88 | |||||||||||
| 89 | 1 | ▶ | if ( my $id = $self->receiver_account_id ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 1 | return $self->_ohloh->get_account( id => $id ); | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 0 | return; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||
| 97 | |||||||||||
| 98 | sub as_xml { | ||||||||||
| 99 | 36 | ▶ | my $self = shift; | ||||||||
|
Subroutine
as_xml: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 100 | 36 | my $xml; | |||||||||
| 101 | 36 | my $w = XML::Writer->new( OUTPUT => \$xml ); | |||||||||
| 102 | |||||||||||
| 103 | 36 | $w->startTag('kudo'); | |||||||||
| 104 | 36 | for my $e (@api_fields) { | |||||||||
| 105 | 324 | ▶ | $w->dataElement( $e => $self->$e ) if $self->$e; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 36 | $w->endTag; | |||||||||
| 109 | |||||||||||
| 110 | 36 | return $xml; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 15 | 'end of WWW::Ohloh::API::Kudo'; | |||||||||
| 114 | __END__ | ||||||||||
| 115 | |||||||||||
| 116 | =head1 NAME | ||||||||||
| 117 | |||||||||||
| 118 | WWW::Ohloh::API::Kudo - an Ohloh kudo | ||||||||||
| 119 | |||||||||||
| 120 | =head1 SYNOPSIS | ||||||||||
| 121 | |||||||||||
| 122 | use WWW::Ohloh::API; | ||||||||||
| 123 | |||||||||||
| 124 | my $ohloh = WWW::Ohloh::API->new( api_key => $my_api_key ); | ||||||||||
| 125 | my $account = $ohloh->get_account( id => 12933 ); | ||||||||||
| 126 | my @received = $account->received_kudos; | ||||||||||
| 127 | |||||||||||
| 128 | # or, from $ohloh directly | ||||||||||
| 129 | my @sent = $ohloh->get_kudos( id => 12933 )->sent; | ||||||||||
| 130 | |||||||||||
| 131 | =head1 DESCRIPTION | ||||||||||
| 132 | |||||||||||
| 133 | W::O::A::Kudo contains the information associated with an Ohloh | ||||||||||
| 134 | kudo as defined at http://www.ohloh.net/api/reference/kudo. | ||||||||||
| 135 | To be properly populated, it must be created via | ||||||||||
| 136 | the C<get_kudos> method of a L<WWW::Ohloh::API> object, | ||||||||||
| 137 | or via the C<received_kudos>/C<sent_kudos> methods of a | ||||||||||
| 138 | L<WWW::Ohloh::API::Account> object. | ||||||||||
| 139 | |||||||||||
| 140 | =head1 METHODS | ||||||||||
| 141 | |||||||||||
| 142 | =head2 API Data Accessors | ||||||||||
| 143 | |||||||||||
| 144 | =head3 created_at | ||||||||||
| 145 | |||||||||||
| 146 | Return the kudo's creation time. | ||||||||||
| 147 | |||||||||||
| 148 | =head3 sender_account_id, sender_account_name | ||||||||||
| 149 | |||||||||||
| 150 | Return the id/name of the account sending the kudo. | ||||||||||
| 151 | |||||||||||
| 152 | =head3 receiver_account_id, receiver_account_name | ||||||||||
| 153 | |||||||||||
| 154 | Return the id/name associated with the account that received | ||||||||||
| 155 | the kudo, or an empty string if the kudo couldn't be linked | ||||||||||
| 156 | to an account. | ||||||||||
| 157 | |||||||||||
| 158 | =head3 project_id, project_name | ||||||||||
| 159 | |||||||||||
| 160 | Return the project id/name if the kudo was sent to a project | ||||||||||
| 161 | contributor instead than an account, or an empty string otherwise. | ||||||||||
| 162 | |||||||||||
| 163 | =head3 contributor_id, contributor_name | ||||||||||
| 164 | |||||||||||
| 165 | Return the cotnributor's id/name if the kudo was sent to a project | ||||||||||
| 166 | contributor instead than an account, or an empty string otherwise. | ||||||||||
| 167 | |||||||||||
| 168 | =head2 Other Methods | ||||||||||
| 169 | |||||||||||
| 170 | =head3 as_xml | ||||||||||
| 171 | |||||||||||
| 172 | Return the kudo information | ||||||||||
| 173 | as an XML string. Note that this is not the exact xml document as returned | ||||||||||
| 174 | by the Ohloh server. | ||||||||||
| 175 | |||||||||||
| 176 | =head1 SEE ALSO | ||||||||||
| 177 | |||||||||||
| 178 | =over | ||||||||||
| 179 | |||||||||||
| 180 | =item * | ||||||||||
| 181 | |||||||||||
| 182 | L<WWW::Ohloh::API>, | ||||||||||
| 183 | L<WWW::Ohloh::API::Kudos>, | ||||||||||
| 184 | L<WWW::Ohloh::API::KudoScore>. | ||||||||||
| 185 | |||||||||||
| 186 | =item * | ||||||||||
| 187 | |||||||||||
| 188 | Ohloh API reference: http://www.ohloh.net/api/getting_started | ||||||||||
| 189 | |||||||||||
| 190 | =item * | ||||||||||
| 191 | |||||||||||
| 192 | Ohloh Account API reference: http://www.ohloh.net/api/reference/kudo | ||||||||||
| 193 | |||||||||||
| 194 | =back | ||||||||||
| 195 | |||||||||||
| 196 | =head1 VERSION | ||||||||||
| 197 | |||||||||||
| 198 | This document describes WWW::Ohloh::API version 0.3.2 | ||||||||||
| 199 | |||||||||||
| 200 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 201 | |||||||||||
| 202 | WWW::Ohloh::API is very extremely alpha quality. It'll improve, | ||||||||||
| 203 | but till then: I<Caveat emptor>. | ||||||||||
| 204 | |||||||||||
| 205 | The C<as_xml()> method returns a re-encoding of the account data, which | ||||||||||
| 206 | can differ of the original xml document sent by the Ohloh server. | ||||||||||
| 207 | |||||||||||
| 208 | Please report any bugs or feature requests to | ||||||||||
| 209 | C<bug-www-ohloh-api@rt.cpan.org>, or through the web interface at | ||||||||||
| 210 | L<http://rt.cpan.org>. | ||||||||||
| 211 | |||||||||||
| 212 | |||||||||||
| 213 | =head1 AUTHOR | ||||||||||
| 214 | |||||||||||
| 215 | Yanick Champoux C<< <yanick@cpan.org> >> | ||||||||||
| 216 | |||||||||||
| 217 | =head1 LICENCE AND COPYRIGHT | ||||||||||
| 218 | |||||||||||
| 219 | Copyright (c) 2008, Yanick Champoux C<< <yanick@cpan.org> >>. All rights reserved. | ||||||||||
| 220 | |||||||||||
| 221 | This module is free software; you can redistribute it and/or | ||||||||||
| 222 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||
| 223 | |||||||||||