| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::PerlMonks        ; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 29970 | use 5.006                     ; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 51 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use strict                    ; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 42 |  | 
| 5 | 1 |  |  | 1 |  | 4 | use warnings FATAL => 'all'   ; | 
|  | 1 |  |  |  |  | 7 |  | 
|  | 1 |  |  |  |  | 51 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 6 | use Carp                      ; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 76 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 1 |  |  | 1 |  | 789 | use HTTP::Request             ; | 
|  | 1 |  |  |  |  | 26389 |  | 
|  | 1 |  |  |  |  | 43 |  | 
| 10 | 1 |  |  | 1 |  | 1123 | use LWP::UserAgent            ; | 
|  | 1 |  |  |  |  | 27623 |  | 
|  | 1 |  |  |  |  | 39 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 1 |  |  | 1 |  | 1213 | use XML::Smart                ; | 
|  | 1 |  |  |  |  | 35789 |  | 
|  | 1 |  |  |  |  | 2736 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 NAME | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | WWW::PerlMonks - [Alpha Release] This module provides access to PerlMonks. | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =head1 VERSION | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | Version 0.01 ** Alpha Release ** | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =cut | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | our $VERSION = '0.01'; # ** Alpha Release ** | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | This module provides access to PerlMonks. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | This is an Alpha release, there are features such as posting posts and replies that are not implemented ( See TODO section ). | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | Details on the Original API can be found at L | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | Each function returns a hash that consists of the original XML parsed through XML::Smart - The original XML | 
| 36 |  |  |  |  |  |  | can be accessed through $result->{ RAW_XML } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | Example: | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | use WWW::PerlMonks; | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | my $ob = new WWW::PerlMonks( | 
| 43 |  |  |  |  |  |  | USERNAME   =>   'username'      , # Optional - Required for functions that require authentication. | 
| 44 |  |  |  |  |  |  | PASSWORD   =>   'password'      , # Optional - Required for functions that require authentication. | 
| 45 |  |  |  |  |  |  | USER_AGENT =>   'WWW_PerlMonks' , # Optional - default 'WWW_PerlMonks' . $VERSION | 
| 46 |  |  |  |  |  |  | DEBUG      =>   0               , # Optional - default - 0 | 
| 47 |  |  |  |  |  |  | ); | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | # my $hash = $ob->get_chatterbox()                             ; | 
| 50 |  |  |  |  |  |  | # my $hash = $ob->get_private_messages()                       ; | 
| 51 |  |  |  |  |  |  | # my $hash = $ob->send_chatter()                               ;     # Unimplemented | 
| 52 |  |  |  |  |  |  | # my $hash = $ob->get_user_nodes_info()                        ; | 
| 53 |  |  |  |  |  |  | # my $hash = $ob->get_user_nodes_reputation()                  ; | 
| 54 |  |  |  |  |  |  | # my $hash = $ob->get_user_XP()                                ; | 
| 55 |  |  |  |  |  |  | # my $hash = $ob->get_online_users()                           ; | 
| 56 |  |  |  |  |  |  | # my $hash = $ob->get_newest_nodes()                           ; | 
| 57 |  |  |  |  |  |  | # my $hash = $ob->get_node_details( [ '72241', '507312' ] )    ; | 
| 58 |  |  |  |  |  |  | # my $hash = $ob->get_node_thread( '1015083' )                 ; | 
| 59 |  |  |  |  |  |  | # my $hash = $ob->get_scratch_pad()                            ;     # Unimplemented | 
| 60 |  |  |  |  |  |  | # my $hash = $ob->get_best_nodes()                             ; | 
| 61 |  |  |  |  |  |  | # my $hash = $ob->get_worst_nodes()                            ; | 
| 62 |  |  |  |  |  |  | # my $hash = $ob->get_selected_best_nodes()                    ; | 
| 63 |  |  |  |  |  |  | # my $hash = $ob->get_nav_info_for_node('72241')               ; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head1 EXPORT | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | The is an Object Oriented Modules and does not export anything. | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head1 SUBROUTINES/METHODS | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head2 new | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | Usage: | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | my $ob = new WWW::PerlMonks( | 
| 77 |  |  |  |  |  |  | USERNAME   =>   'username'      , # Optional - Required for functions that require authentication. | 
| 78 |  |  |  |  |  |  | PASSWORD   =>   'password'      , # Optional - Required for functions that require authentication. | 
| 79 |  |  |  |  |  |  | USER_AGENT =>   'WWW_PerlMonks' , # Optional - default 'WWW_PerlMonks' . $VERSION | 
| 80 |  |  |  |  |  |  | DEBUG      =>   0               , # Optional - default - 0 | 
| 81 |  |  |  |  |  |  | ); | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =cut | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | sub new { | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 0 |  |  | 0 | 1 |  | my $class           = shift  ; | 
| 88 | 0 |  |  |  |  |  | my %parameter_hash  = @_     ; | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 0 |  |  |  |  |  | my $useage_howto = " | 
| 91 |  |  |  |  |  |  | Usage: | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | my \$ob = new WWW::PerlMonks( | 
| 94 |  |  |  |  |  |  | USERNAME   =>   'username'      , # Optional - Required for functions that require authentication. | 
| 95 |  |  |  |  |  |  | PASSWORD   =>   'password'      , # Optional - Required for functions that require authentication. | 
| 96 |  |  |  |  |  |  | USER_AGENT =>   'WWW_PerlMonks' , # Optional - default 'WWW_PerlMonks' . $VERSION | 
| 97 |  |  |  |  |  |  | DEBUG      =>   0               , # Optional - default - 0 | 
| 98 |  |  |  |  |  |  | ); | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | "; | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 0 |  |  |  |  |  | my %function_to_url = %{ _get_function_to_url_hash() } ; | 
|  | 0 |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 0 | 0 | 0 |  |  |  | my $authenticated = ( $parameter_hash{ USERNAME } and $parameter_hash{ PASSWORD } )  ? 1 : 0 ; | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 0 | 0 |  |  |  |  | $parameter_hash{ USER_AGENT   } = 'WWW_PerlMonks' . $VERSION  unless( $parameter_hash{ USER_AGENT   } ) ; | 
| 108 |  |  |  |  |  |  |  | 
| 109 | 0 | 0 |  |  |  |  | $parameter_hash{ DEBUG        } = 0                           unless( $parameter_hash{ DEBUG        } ) ; | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | my $self = { | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | USERNAME                     =>   $parameter_hash{ USERNAME     }        , | 
| 114 |  |  |  |  |  |  | PASSWORD                     =>   $parameter_hash{ PASSWORD     }        , | 
| 115 |  |  |  |  |  |  | USER_AGENT                   =>   $parameter_hash{ USER_AGENT   }        , | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | AUTHENTICATED                =>   $authenticated                         , | 
| 119 |  |  |  |  |  |  | FUNC_TO_URL_HASH             =>   \%function_to_url                      , | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | DEBUG                        =>   $parameter_hash{ DEBUG        }        , | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 0 |  |  |  |  |  | }; | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | ## Private and class data here. | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | ## NONE | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  |  | 
| 131 | 0 |  |  |  |  |  | bless( $self, $class ); | 
| 132 |  |  |  |  |  |  |  | 
| 133 | 0 | 0 |  |  |  |  | if( $self->{ DEBUG } == 1 ) { | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 0 |  |  |  |  |  | return $self; | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head2 get_chatterbox | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | This function retrieves the recents comments on the PerlMonks Chatterbox. | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | Authentication: Not required. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | Parameters    : None        . | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =cut | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | sub get_chatterbox { | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 0 |  |  | 0 | 1 |  | my $self  = shift ; | 
| 154 | 0 |  |  |  |  |  | my $param = shift ; | 
| 155 |  |  |  |  |  |  |  | 
| 156 | 0 | 0 |  |  |  |  | if( $param ) { | 
| 157 | 0 |  |  |  |  |  | warn( "'get_chatterbox' does not take parameters but you seem to have passed something!\n" ) ; | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  |  | 
| 160 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_chatterbox' } ; | 
| 161 | 0 |  |  |  |  |  | my $xml        = $self->_get_from_url( $url_to_get )             ; | 
| 162 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                  ; | 
| 163 |  |  |  |  |  |  |  | 
| 164 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml ; | 
| 165 |  |  |  |  |  |  |  | 
| 166 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | } | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =head2 get_private_messages | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | This function retrieves private messages in the inbox of the authenticated user. | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | Authentication: Required . | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | Parameters    : None     . | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | =cut | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | sub get_private_messages { | 
| 181 |  |  |  |  |  |  |  | 
| 182 | 0 |  |  | 0 | 1 |  | my $self  = shift ; | 
| 183 | 0 |  |  |  |  |  | my $param = shift ; | 
| 184 |  |  |  |  |  |  |  | 
| 185 | 0 | 0 |  |  |  |  | croak( "'get_private_messages' requires authentication \n" ) unless( $self->{ AUTHENTICATED } ) ; | 
| 186 |  |  |  |  |  |  |  | 
| 187 | 0 | 0 |  |  |  |  | if( $param ) { | 
| 188 | 0 |  |  |  |  |  | warn( "'get_private_messages' does not take parameters but you seem to have passed something!\n" ) ; | 
| 189 |  |  |  |  |  |  | } | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | my $url_to_get = | 
| 192 |  |  |  |  |  |  | $self->{ FUNC_TO_URL_HASH }{ 'get_private_messages' } . | 
| 193 |  |  |  |  |  |  | '&op=login;user=' . $self->{ USERNAME } . | 
| 194 | 0 |  |  |  |  |  | ';passwd=' . $self->{ PASSWORD } . ';'                       ; | 
| 195 |  |  |  |  |  |  |  | 
| 196 | 0 |  |  |  |  |  | my $xml        = $self->_get_from_url( $url_to_get )             ; | 
| 197 |  |  |  |  |  |  |  | 
| 198 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                  ; | 
| 199 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                    ; | 
| 200 |  |  |  |  |  |  |  | 
| 201 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | } | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  |  | 
| 206 |  |  |  |  |  |  | =head2 send_chatter   [ Unimplemented ] | 
| 207 |  |  |  |  |  |  |  | 
| 208 |  |  |  |  |  |  | B - Original API seems to have a problem. | 
| 209 |  |  |  |  |  |  |  | 
| 210 |  |  |  |  |  |  | This function sends chatter to the PerlMonks chatterbox on behalf of the authenticated user. | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | Authentication: Required . | 
| 213 |  |  |  |  |  |  |  | 
| 214 |  |  |  |  |  |  | Parameters    : Chatter  . | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | =cut | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | sub send_chatter { | 
| 219 |  |  |  |  |  |  |  | 
| 220 | 0 |  |  | 0 | 1 |  | my $self    = shift ; | 
| 221 | 0 |  |  |  |  |  | my $message = shift ; | 
| 222 |  |  |  |  |  |  |  | 
| 223 | 0 |  |  |  |  |  | croak( 'Unimplemented' ) ; | 
| 224 |  |  |  |  |  |  |  | 
| 225 | 0 |  |  |  |  |  | return 0                 ; | 
| 226 |  |  |  |  |  |  |  | 
| 227 | 0 | 0 |  |  |  |  | croak( "'send_chatter' requires authentication \n" ) unless( $self->{ AUTHENTICATED } ) ; | 
| 228 | 0 | 0 |  |  |  |  | croak( "Need a message to send\n!"                 ) unless( $message                 ) ; | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | } | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  |  | 
| 233 |  |  |  |  |  |  | =head2 get_user_nodes_info | 
| 234 |  |  |  |  |  |  |  | 
| 235 |  |  |  |  |  |  | This function returns details of a user. If authenticated the user param is optional and it will default to the authenticated user. | 
| 236 |  |  |  |  |  |  | Also reputation is available only when authenticated. | 
| 237 |  |  |  |  |  |  |  | 
| 238 |  |  |  |  |  |  | Authentication: Required for 'reputation' . | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  | Parameters    : user if not authenticated, default is authenticated user. | 
| 241 |  |  |  |  |  |  |  | 
| 242 |  |  |  |  |  |  | =cut | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | sub get_user_nodes_info { | 
| 245 |  |  |  |  |  |  |  | 
| 246 | 0 |  |  | 0 | 1 |  | my $self = shift ; | 
| 247 | 0 |  |  |  |  |  | my $user = shift ; | 
| 248 |  |  |  |  |  |  |  | 
| 249 | 0 |  |  |  |  |  | $user    = $self->_find_user_to_use( $user ) ; | 
| 250 |  |  |  |  |  |  |  | 
| 251 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_user_nodes_info' } . '&foruser=' . $user ; | 
| 252 | 0 | 0 |  |  |  |  | if( $self->{ AUTHENTICATED } ) { | 
| 253 |  |  |  |  |  |  | $url_to_get .= | 
| 254 |  |  |  |  |  |  | '&op=login;user=' . $self->{ USERNAME } . | 
| 255 | 0 |  |  |  |  |  | ';passwd=' . $self->{ PASSWORD } . ';'     ; | 
| 256 |  |  |  |  |  |  | } | 
| 257 |  |  |  |  |  |  |  | 
| 258 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get ) ; | 
| 259 |  |  |  |  |  |  |  | 
| 260 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                  ; | 
| 261 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                    ; | 
| 262 |  |  |  |  |  |  |  | 
| 263 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 264 |  |  |  |  |  |  |  | 
| 265 |  |  |  |  |  |  | } | 
| 266 |  |  |  |  |  |  |  | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  | =head2 get_user_nodes_reputation | 
| 269 |  |  |  |  |  |  |  | 
| 270 |  |  |  |  |  |  | Returns reputation information about recently voted on nodes owned by the logged in user. Returns those nodes voted on since | 
| 271 |  |  |  |  |  |  | the last fetch or the past 24 hours whichever is shorter. Will return an error code if called sooner than | 
| 272 |  |  |  |  |  |  | 10 minutes after the last fetch. | 
| 273 |  |  |  |  |  |  |  | 
| 274 |  |  |  |  |  |  | B Required min time between hits is 10 min. | 
| 275 |  |  |  |  |  |  |  | 
| 276 |  |  |  |  |  |  | Authentication: Required . | 
| 277 |  |  |  |  |  |  |  | 
| 278 |  |  |  |  |  |  | Parameters    : None     . | 
| 279 |  |  |  |  |  |  |  | 
| 280 |  |  |  |  |  |  | =cut | 
| 281 |  |  |  |  |  |  |  | 
| 282 |  |  |  |  |  |  | sub get_user_nodes_reputation { | 
| 283 |  |  |  |  |  |  |  | 
| 284 | 0 |  |  | 0 | 1 |  | my $self = shift ; | 
| 285 |  |  |  |  |  |  |  | 
| 286 | 0 | 0 |  |  |  |  | croak( "'get_private_messages' requires authentication \n" ) unless( $self->{ AUTHENTICATED } ) ; | 
| 287 |  |  |  |  |  |  |  | 
| 288 |  |  |  |  |  |  | my $url_to_get = | 
| 289 |  |  |  |  |  |  | $self->{ FUNC_TO_URL_HASH }{ 'get_user_nodes_reputation' } . | 
| 290 |  |  |  |  |  |  | '&op=login;user=' . $self->{ USERNAME } . | 
| 291 | 0 |  |  |  |  |  | ';passwd=' . $self->{ PASSWORD } . ';'                       ; | 
| 292 |  |  |  |  |  |  |  | 
| 293 |  |  |  |  |  |  |  | 
| 294 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get ) ; | 
| 295 |  |  |  |  |  |  |  | 
| 296 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                  ; | 
| 297 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                    ; | 
| 298 |  |  |  |  |  |  |  | 
| 299 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 300 |  |  |  |  |  |  |  | 
| 301 |  |  |  |  |  |  | } | 
| 302 |  |  |  |  |  |  |  | 
| 303 |  |  |  |  |  |  | =head2 get_user_XP | 
| 304 |  |  |  |  |  |  |  | 
| 305 |  |  |  |  |  |  | This function returns the XP and other basic details of a user. If authenticated the user param is optional and it will default to the | 
| 306 |  |  |  |  |  |  | authenticated user. Also 'votesleft' is available only when authenticated. | 
| 307 |  |  |  |  |  |  |  | 
| 308 |  |  |  |  |  |  | Authentication: Required for 'votesleft' . | 
| 309 |  |  |  |  |  |  |  | 
| 310 |  |  |  |  |  |  | Parameters    : user if not authenticated, default is authenticated user. | 
| 311 |  |  |  |  |  |  |  | 
| 312 |  |  |  |  |  |  | =cut | 
| 313 |  |  |  |  |  |  |  | 
| 314 |  |  |  |  |  |  | sub get_user_XP { | 
| 315 |  |  |  |  |  |  |  | 
| 316 | 0 |  |  | 0 | 1 |  | my $self = shift ; | 
| 317 | 0 |  |  |  |  |  | my $user = shift ; | 
| 318 |  |  |  |  |  |  |  | 
| 319 | 0 |  |  |  |  |  | $user    = $self->_find_user_to_use( $user ) ; | 
| 320 |  |  |  |  |  |  |  | 
| 321 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_user_XP' } . '&for_user=' . $user ; | 
| 322 | 0 | 0 |  |  |  |  | if( $self->{ AUTHENTICATED } ) { | 
| 323 |  |  |  |  |  |  | $url_to_get .= | 
| 324 |  |  |  |  |  |  | '&op=login;user=' . $self->{ USERNAME } . | 
| 325 | 0 |  |  |  |  |  | ';passwd=' . $self->{ PASSWORD } . ';'     ; | 
| 326 |  |  |  |  |  |  | } | 
| 327 |  |  |  |  |  |  |  | 
| 328 |  |  |  |  |  |  |  | 
| 329 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get ) ; | 
| 330 |  |  |  |  |  |  |  | 
| 331 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                  ; | 
| 332 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                    ; | 
| 333 |  |  |  |  |  |  |  | 
| 334 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 335 |  |  |  |  |  |  |  | 
| 336 |  |  |  |  |  |  | } | 
| 337 |  |  |  |  |  |  |  | 
| 338 |  |  |  |  |  |  | =head2 get_online_users | 
| 339 |  |  |  |  |  |  |  | 
| 340 |  |  |  |  |  |  | This function returns a list of currently online users. | 
| 341 |  |  |  |  |  |  |  | 
| 342 |  |  |  |  |  |  | Authentication: Not Required. | 
| 343 |  |  |  |  |  |  |  | 
| 344 |  |  |  |  |  |  | Parameters    : None. | 
| 345 |  |  |  |  |  |  |  | 
| 346 |  |  |  |  |  |  | =cut | 
| 347 |  |  |  |  |  |  |  | 
| 348 |  |  |  |  |  |  | sub get_online_users { | 
| 349 |  |  |  |  |  |  |  | 
| 350 | 0 |  |  | 0 | 1 |  | my $self  = shift ; | 
| 351 | 0 |  |  |  |  |  | my $param = shift ; | 
| 352 |  |  |  |  |  |  |  | 
| 353 | 0 | 0 |  |  |  |  | if( $param ) { | 
| 354 | 0 |  |  |  |  |  | warn( "'get_online_users' does not take parameters but you seem to have passed something!\n" ) ; | 
| 355 |  |  |  |  |  |  | } | 
| 356 |  |  |  |  |  |  |  | 
| 357 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_online_users' } ; | 
| 358 |  |  |  |  |  |  |  | 
| 359 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                      ; | 
| 360 |  |  |  |  |  |  |  | 
| 361 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                    ; | 
| 362 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                      ; | 
| 363 |  |  |  |  |  |  |  | 
| 364 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 365 |  |  |  |  |  |  |  | 
| 366 |  |  |  |  |  |  | } | 
| 367 |  |  |  |  |  |  |  | 
| 368 |  |  |  |  |  |  | =head2 get_newest_nodes | 
| 369 |  |  |  |  |  |  |  | 
| 370 |  |  |  |  |  |  | This function returns a list of new nodes. | 
| 371 |  |  |  |  |  |  |  | 
| 372 |  |  |  |  |  |  | Authentication: Not Required. | 
| 373 |  |  |  |  |  |  |  | 
| 374 |  |  |  |  |  |  | Parameters    : Optional - 'unix timestamp' of earliest message ( cannot be more than 8 days - 691200 sec - ago ) | 
| 375 |  |  |  |  |  |  |  | 
| 376 |  |  |  |  |  |  | =cut | 
| 377 |  |  |  |  |  |  |  | 
| 378 |  |  |  |  |  |  | sub get_newest_nodes { | 
| 379 |  |  |  |  |  |  |  | 
| 380 | 0 |  |  | 0 | 1 |  | my $self          = shift ; | 
| 381 | 0 |  |  |  |  |  | my $since_seconds = shift ; | 
| 382 |  |  |  |  |  |  |  | 
| 383 | 0 | 0 | 0 |  |  |  | if( defined( $since_seconds ) and $since_seconds > 691200 ) { # Magic number comes from restriction in API. | 
| 384 | 0 |  |  |  |  |  | warn( 'Requested earliest time is way too far out in the past, limiting to 8 days ( 691200 sec )' ) ; | 
| 385 | 0 |  |  |  |  |  | $since_seconds = 691200 ; | 
| 386 |  |  |  |  |  |  | } | 
| 387 |  |  |  |  |  |  |  | 
| 388 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_newest_nodes' } ; | 
| 389 | 0 | 0 |  |  |  |  | if( $since_seconds ) { | 
| 390 | 0 |  |  |  |  |  | $url_to_get .= '&sinceunixtime=' . $since_seconds ; | 
| 391 |  |  |  |  |  |  | } | 
| 392 |  |  |  |  |  |  |  | 
| 393 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                      ; | 
| 394 |  |  |  |  |  |  |  | 
| 395 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                    ; | 
| 396 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                      ; | 
| 397 |  |  |  |  |  |  |  | 
| 398 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 399 |  |  |  |  |  |  |  | 
| 400 |  |  |  |  |  |  |  | 
| 401 |  |  |  |  |  |  | } | 
| 402 |  |  |  |  |  |  |  | 
| 403 |  |  |  |  |  |  | =head2 get_node_details | 
| 404 |  |  |  |  |  |  |  | 
| 405 |  |  |  |  |  |  | This function returns information about specific nodes. | 
| 406 |  |  |  |  |  |  |  | 
| 407 |  |  |  |  |  |  | Authentication: Not Required. | 
| 408 |  |  |  |  |  |  |  | 
| 409 |  |  |  |  |  |  | Parameters    : Required: reference to array containing node ids. | 
| 410 |  |  |  |  |  |  |  | 
| 411 |  |  |  |  |  |  | =cut | 
| 412 |  |  |  |  |  |  |  | 
| 413 |  |  |  |  |  |  | sub get_node_details { | 
| 414 |  |  |  |  |  |  |  | 
| 415 | 0 |  |  | 0 | 1 |  | my $self  = shift ; | 
| 416 | 0 |  |  |  |  |  | my $nodes = shift ; | 
| 417 |  |  |  |  |  |  |  | 
| 418 | 0 |  |  |  |  |  | my @nodes = @{ $nodes } ; | 
|  | 0 |  |  |  |  |  |  | 
| 419 |  |  |  |  |  |  |  | 
| 420 | 0 |  |  |  |  |  | eval { | 
| 421 | 0 |  |  |  |  |  | @nodes = map( int, @nodes ) ; | 
| 422 | 0 | 0 |  |  |  |  | } ; if( $@ ) { | 
| 423 | 0 |  |  |  |  |  | croak( 'Something wrong with the format in which you gave me nodes!' ) ; | 
| 424 |  |  |  |  |  |  | } | 
| 425 |  |  |  |  |  |  |  | 
| 426 | 0 |  |  |  |  |  | my $number_of_nodes = @nodes ; | 
| 427 |  |  |  |  |  |  |  | 
| 428 | 0 | 0 |  |  |  |  | unless( $number_of_nodes ) { | 
| 429 | 0 | 0 |  |  |  |  | croak( 'Give me at least one node to get information for' ) unless ( $nodes ) ; | 
| 430 |  |  |  |  |  |  | } | 
| 431 |  |  |  |  |  |  |  | 
| 432 | 0 |  |  |  |  |  | my $node_string = join( ',', @nodes ) ; | 
| 433 |  |  |  |  |  |  |  | 
| 434 |  |  |  |  |  |  |  | 
| 435 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_node_details' } . '&nodes=' . $node_string ; | 
| 436 |  |  |  |  |  |  |  | 
| 437 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                      ; | 
| 438 |  |  |  |  |  |  |  | 
| 439 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                    ; | 
| 440 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                      ; | 
| 441 |  |  |  |  |  |  |  | 
| 442 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 443 |  |  |  |  |  |  |  | 
| 444 |  |  |  |  |  |  | } | 
| 445 |  |  |  |  |  |  |  | 
| 446 |  |  |  |  |  |  |  | 
| 447 |  |  |  |  |  |  | =head2 get_node_thread | 
| 448 |  |  |  |  |  |  |  | 
| 449 |  |  |  |  |  |  | This function returns the node IDs of a thread, properly nested. | 
| 450 |  |  |  |  |  |  |  | 
| 451 |  |  |  |  |  |  | Authentication: Not Required. | 
| 452 |  |  |  |  |  |  |  | 
| 453 |  |  |  |  |  |  | Parameters    : Required: nodeID of node to get thread of. | 
| 454 |  |  |  |  |  |  |  | 
| 455 |  |  |  |  |  |  | =cut | 
| 456 |  |  |  |  |  |  |  | 
| 457 |  |  |  |  |  |  | sub get_node_thread { | 
| 458 |  |  |  |  |  |  |  | 
| 459 | 0 |  |  | 0 | 1 |  | my $self = shift ; | 
| 460 | 0 |  |  |  |  |  | my $node = shift ; | 
| 461 |  |  |  |  |  |  |  | 
| 462 | 0 | 0 |  |  |  |  | unless( $node ) { | 
| 463 | 0 |  |  |  |  |  | croak( 'NodeID to get thread for missing!' ) ; | 
| 464 |  |  |  |  |  |  | } | 
| 465 |  |  |  |  |  |  |  | 
| 466 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_node_thread' } . '&id=' . $node ; | 
| 467 |  |  |  |  |  |  |  | 
| 468 |  |  |  |  |  |  |  | 
| 469 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                      ; | 
| 470 |  |  |  |  |  |  |  | 
| 471 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                    ; | 
| 472 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                      ; | 
| 473 |  |  |  |  |  |  |  | 
| 474 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 475 |  |  |  |  |  |  |  | 
| 476 |  |  |  |  |  |  | } | 
| 477 |  |  |  |  |  |  |  | 
| 478 |  |  |  |  |  |  | =head2 get_scratch_pad  [ Unimplemented ] | 
| 479 |  |  |  |  |  |  |  | 
| 480 |  |  |  |  |  |  | B! There seems to be a problem with the original API. | 
| 481 |  |  |  |  |  |  |  | 
| 482 |  |  |  |  |  |  | =cut | 
| 483 |  |  |  |  |  |  |  | 
| 484 |  |  |  |  |  |  | sub get_scratch_pad { | 
| 485 |  |  |  |  |  |  |  | 
| 486 | 0 |  |  | 0 | 1 |  | my $self = shift ; | 
| 487 |  |  |  |  |  |  |  | 
| 488 | 0 |  |  |  |  |  | croak( 'Unimplemented - API seems to have problems.' ) ; | 
| 489 |  |  |  |  |  |  |  | 
| 490 | 0 |  |  |  |  |  | return 0 ; | 
| 491 |  |  |  |  |  |  |  | 
| 492 |  |  |  |  |  |  | } | 
| 493 |  |  |  |  |  |  |  | 
| 494 |  |  |  |  |  |  | =head2 get_best_nodes | 
| 495 |  |  |  |  |  |  |  | 
| 496 |  |  |  |  |  |  | This function returns a list of the best nodes. | 
| 497 |  |  |  |  |  |  |  | 
| 498 |  |  |  |  |  |  | Authentication: Not Required. | 
| 499 |  |  |  |  |  |  |  | 
| 500 |  |  |  |  |  |  | Parameters    : None        . | 
| 501 |  |  |  |  |  |  |  | 
| 502 |  |  |  |  |  |  | =cut | 
| 503 |  |  |  |  |  |  |  | 
| 504 |  |  |  |  |  |  | sub get_best_nodes { | 
| 505 |  |  |  |  |  |  |  | 
| 506 | 0 |  |  | 0 | 1 |  | my $self  = shift ; | 
| 507 | 0 |  |  |  |  |  | my $param = shift ; | 
| 508 |  |  |  |  |  |  |  | 
| 509 | 0 | 0 |  |  |  |  | if( $param ) { | 
| 510 | 0 |  |  |  |  |  | warn( "'get_best_nodes' does not take parameters but you seem to have passed something!\n" ) ; | 
| 511 |  |  |  |  |  |  | } | 
| 512 |  |  |  |  |  |  |  | 
| 513 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_best_nodes' }   ; | 
| 514 |  |  |  |  |  |  |  | 
| 515 |  |  |  |  |  |  |  | 
| 516 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                      ; | 
| 517 |  |  |  |  |  |  |  | 
| 518 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                    ; | 
| 519 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                      ; | 
| 520 |  |  |  |  |  |  |  | 
| 521 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 522 |  |  |  |  |  |  |  | 
| 523 |  |  |  |  |  |  | } | 
| 524 |  |  |  |  |  |  |  | 
| 525 |  |  |  |  |  |  |  | 
| 526 |  |  |  |  |  |  | =head2 get_worst_nodes | 
| 527 |  |  |  |  |  |  |  | 
| 528 |  |  |  |  |  |  | This function returns a list of the worst nodes. | 
| 529 |  |  |  |  |  |  |  | 
| 530 |  |  |  |  |  |  | Authentication: Required. | 
| 531 |  |  |  |  |  |  |  | 
| 532 |  |  |  |  |  |  | Parameters    : None    . | 
| 533 |  |  |  |  |  |  |  | 
| 534 |  |  |  |  |  |  | =cut | 
| 535 |  |  |  |  |  |  |  | 
| 536 |  |  |  |  |  |  | sub get_worst_nodes { | 
| 537 |  |  |  |  |  |  |  | 
| 538 | 0 |  |  | 0 | 1 |  | my $self  = shift ; | 
| 539 | 0 |  |  |  |  |  | my $param = shift ; | 
| 540 |  |  |  |  |  |  |  | 
| 541 | 0 | 0 |  |  |  |  | if( $param ) { | 
| 542 | 0 |  |  |  |  |  | warn( "'get_worst_nodes' does not take parameters but you seem to have passed something!\n" ) ; | 
| 543 |  |  |  |  |  |  | } | 
| 544 |  |  |  |  |  |  |  | 
| 545 | 0 | 0 |  |  |  |  | unless( $self->{ AUTHENTICATED } ) { | 
| 546 | 0 |  |  |  |  |  | croak( "'get_worst_nodes' requires authentication." ) ; | 
| 547 |  |  |  |  |  |  | } | 
| 548 |  |  |  |  |  |  |  | 
| 549 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_worst_nodes' }  ; | 
| 550 |  |  |  |  |  |  | $url_to_get .= | 
| 551 |  |  |  |  |  |  | '&op=login;user=' . $self->{ USERNAME } . | 
| 552 | 0 |  |  |  |  |  | ';passwd=' . $self->{ PASSWORD } . ';'                         ; | 
| 553 |  |  |  |  |  |  |  | 
| 554 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                      ; | 
| 555 |  |  |  |  |  |  |  | 
| 556 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                    ; | 
| 557 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                      ; | 
| 558 |  |  |  |  |  |  |  | 
| 559 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 560 |  |  |  |  |  |  |  | 
| 561 |  |  |  |  |  |  | } | 
| 562 |  |  |  |  |  |  |  | 
| 563 |  |  |  |  |  |  |  | 
| 564 |  |  |  |  |  |  | =head2 get_selected_best_nodes | 
| 565 |  |  |  |  |  |  |  | 
| 566 |  |  |  |  |  |  | This function returns a list of the all time best nodes. | 
| 567 |  |  |  |  |  |  |  | 
| 568 |  |  |  |  |  |  | Authentication: Not Required . | 
| 569 |  |  |  |  |  |  |  | 
| 570 |  |  |  |  |  |  | Parameters    : None         . | 
| 571 |  |  |  |  |  |  |  | 
| 572 |  |  |  |  |  |  | =cut | 
| 573 |  |  |  |  |  |  |  | 
| 574 |  |  |  |  |  |  | sub get_selected_best_nodes { | 
| 575 |  |  |  |  |  |  |  | 
| 576 | 0 |  |  | 0 | 1 |  | my $self  = shift ; | 
| 577 | 0 |  |  |  |  |  | my $param = shift ; | 
| 578 |  |  |  |  |  |  |  | 
| 579 | 0 | 0 |  |  |  |  | if( $param ) { | 
| 580 | 0 |  |  |  |  |  | warn( "'get_selected_best_nodes' does not take parameters but you seem to have passed something!\n" ) ; | 
| 581 |  |  |  |  |  |  | } | 
| 582 |  |  |  |  |  |  |  | 
| 583 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_selected_best_nodes' }   ; | 
| 584 |  |  |  |  |  |  |  | 
| 585 |  |  |  |  |  |  |  | 
| 586 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                               ; | 
| 587 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                             ; | 
| 588 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                               ; | 
| 589 |  |  |  |  |  |  |  | 
| 590 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 591 |  |  |  |  |  |  |  | 
| 592 |  |  |  |  |  |  | } | 
| 593 |  |  |  |  |  |  |  | 
| 594 |  |  |  |  |  |  | =head2 get_nav_info_for_node | 
| 595 |  |  |  |  |  |  |  | 
| 596 |  |  |  |  |  |  | This function provides an interface to the Navigational Nodelet - Description from Original API Follows: | 
| 597 |  |  |  |  |  |  |  | 
| 598 |  |  |  |  |  |  | PerlMonks automation clients can use this to spider the site in various ways. Its concept of operation is just like that of the | 
| 599 |  |  |  |  |  |  | Node Navigator nodelet: given a node (by ID), it reports the previous and next node, the previous and next of the same node | 
| 600 |  |  |  |  |  |  | type (e.g. Meditation), and the previous and next by the same author. Optionally, it lets you request the previous/next node, | 
| 601 |  |  |  |  |  |  | relative to the given node, of a different type or by a different author. | 
| 602 |  |  |  |  |  |  |  | 
| 603 |  |  |  |  |  |  | Information on the search, including the search parameters and any error conditions, is reported in the  "header" | 
| 604 |  |  |  |  |  |  | element of the result. | 
| 605 |  |  |  |  |  |  |  | 
| 606 |  |  |  |  |  |  | Authentication: Not Required . | 
| 607 |  |  |  |  |  |  |  | 
| 608 |  |  |  |  |  |  | Parameters    : | 
| 609 |  |  |  |  |  |  |  | 
| 610 |  |  |  |  |  |  | nodeID   - of the reference node ( Required ) | 
| 611 |  |  |  |  |  |  | nodetype - id of the desired node type (optional) | 
| 612 |  |  |  |  |  |  | author   - id of the desired author (that is, their homenode id) (optional) | 
| 613 |  |  |  |  |  |  |  | 
| 614 |  |  |  |  |  |  | =cut | 
| 615 |  |  |  |  |  |  |  | 
| 616 |  |  |  |  |  |  | sub get_nav_info_for_node { | 
| 617 |  |  |  |  |  |  |  | 
| 618 | 0 |  |  | 0 | 1 |  | my $self     = shift ; | 
| 619 | 0 |  |  |  |  |  | my $node     = shift ; | 
| 620 | 0 |  |  |  |  |  | my $nodetype = shift ; | 
| 621 | 0 |  |  |  |  |  | my $author   = shift ; | 
| 622 |  |  |  |  |  |  |  | 
| 623 | 0 | 0 |  |  |  |  | unless( $node ) { | 
| 624 | 0 |  |  |  |  |  | croak( 'NodeID to get nav info for missing!' ) ; | 
| 625 |  |  |  |  |  |  | } | 
| 626 |  |  |  |  |  |  |  | 
| 627 | 0 |  |  |  |  |  | my $url_to_get = $self->{ FUNC_TO_URL_HASH }{ 'get_nav_info_for_node' } . '&id=' . $node ; | 
| 628 | 0 | 0 |  |  |  |  | if( $nodetype ) { | 
| 629 | 0 |  |  |  |  |  | $url_to_get .= '&nodetype=' . $nodetype ; | 
| 630 |  |  |  |  |  |  | } | 
| 631 | 0 | 0 |  |  |  |  | if( $author   ) { | 
| 632 | 0 |  |  |  |  |  | $url_to_get .= '&author='   . $author   ; | 
| 633 |  |  |  |  |  |  | } | 
| 634 |  |  |  |  |  |  |  | 
| 635 | 0 |  |  |  |  |  | my $xml = $self->_get_from_url( $url_to_get )                      ; | 
| 636 | 0 |  |  |  |  |  | my $xml_hash   = new XML::Smart( $xml )->tree()                    ; | 
| 637 | 0 |  |  |  |  |  | $xml_hash->{ RAW_XML } = $xml                                      ; | 
| 638 |  |  |  |  |  |  |  | 
| 639 | 0 |  |  |  |  |  | return $xml_hash ; | 
| 640 |  |  |  |  |  |  |  | 
| 641 |  |  |  |  |  |  | } | 
| 642 |  |  |  |  |  |  |  | 
| 643 |  |  |  |  |  |  |  | 
| 644 |  |  |  |  |  |  | =head1 INTERNAL SUBROUTINES/METHODS | 
| 645 |  |  |  |  |  |  |  | 
| 646 |  |  |  |  |  |  | These functions are used by the module. They are not meant to be called directly using the Net::XMPP::Client::GTalk object although | 
| 647 |  |  |  |  |  |  | there is nothing stoping you from doing that. | 
| 648 |  |  |  |  |  |  |  | 
| 649 |  |  |  |  |  |  | =head2 _get_from_url | 
| 650 |  |  |  |  |  |  |  | 
| 651 |  |  |  |  |  |  | This function retrieves the contents of a web url. | 
| 652 |  |  |  |  |  |  |  | 
| 653 |  |  |  |  |  |  | =cut | 
| 654 |  |  |  |  |  |  |  | 
| 655 |  |  |  |  |  |  | sub _get_from_url { | 
| 656 |  |  |  |  |  |  |  | 
| 657 | 0 |  |  | 0 |  |  | my $self       = shift ; | 
| 658 | 0 |  |  |  |  |  | my $url        = shift ; | 
| 659 |  |  |  |  |  |  |  | 
| 660 | 0 |  |  |  |  |  | my $user_agent = $self->{ USER_AGENT } ; | 
| 661 |  |  |  |  |  |  |  | 
| 662 | 0 | 0 |  |  |  |  | croak( "User Agent undefined!\n" ) unless( $user_agent ) ; | 
| 663 |  |  |  |  |  |  |  | 
| 664 | 0 |  |  |  |  |  | my $contents               ; | 
| 665 |  |  |  |  |  |  | my $response               ; | 
| 666 | 0 |  |  |  |  |  | my $attempts           = 0 ; | 
| 667 | 0 |  |  |  |  |  | my $successful_url_get = 0 ; | 
| 668 | 0 |  | 0 |  |  |  | while( ( $attempts < 1 ) and ( !($successful_url_get ) ) ) { | 
| 669 | 0 |  |  |  |  |  | my $request = HTTP::Request->new( | 
| 670 |  |  |  |  |  |  | GET => $url , | 
| 671 |  |  |  |  |  |  | ); | 
| 672 |  |  |  |  |  |  |  | 
| 673 | 0 |  |  |  |  |  | my $ua = LWP::UserAgent->new          ; | 
| 674 | 0 |  |  |  |  |  | $ua->timeout(60)                      ; | 
| 675 | 0 |  |  |  |  |  | $ua->env_proxy                        ; | 
| 676 | 0 |  |  |  |  |  | $ua->agent( $user_agent )             ; | 
| 677 |  |  |  |  |  |  |  | 
| 678 | 0 |  |  |  |  |  | $response = $ua->request( $request )  ; | 
| 679 | 0 | 0 |  |  |  |  | if ($response->is_success) { | 
| 680 | 0 | 0 |  |  |  |  | $contents = $response->content or $response->decoded_content ; | 
| 681 | 0 |  |  |  |  |  | $successful_url_get = 1                                      ; | 
| 682 |  |  |  |  |  |  | }  else { | 
| 683 | 0 |  |  |  |  |  | $attempts++                                                  ; | 
| 684 | 0 |  |  |  |  |  | sleep( ( $attempts * 2 ) )                                   ; | 
| 685 |  |  |  |  |  |  | } | 
| 686 |  |  |  |  |  |  |  | 
| 687 |  |  |  |  |  |  | } | 
| 688 |  |  |  |  |  |  |  | 
| 689 | 0 | 0 |  |  |  |  | unless( $successful_url_get ) { | 
| 690 | 0 |  |  |  |  |  | croak(  "Failed access to $url : ".$response->status_line."\n"  ) ; | 
| 691 |  |  |  |  |  |  | } | 
| 692 |  |  |  |  |  |  |  | 
| 693 | 0 |  |  |  |  |  | $contents =~ s/\s+$//g ; | 
| 694 |  |  |  |  |  |  |  | 
| 695 | 0 | 0 | 0 |  |  |  | if( $contents eq '' and $self->{ AUTHENTICATED } ) { | 
| 696 | 0 |  |  |  |  |  | warn( 'WARNING: Did not get data - possible authentication failure!' . "\n" ) ; | 
| 697 |  |  |  |  |  |  | } | 
| 698 |  |  |  |  |  |  |  | 
| 699 |  |  |  |  |  |  |  | 
| 700 | 0 |  |  |  |  |  | return $contents   ; | 
| 701 |  |  |  |  |  |  |  | 
| 702 |  |  |  |  |  |  | } | 
| 703 |  |  |  |  |  |  |  | 
| 704 |  |  |  |  |  |  | =head2 _get_function_to_url_hash | 
| 705 |  |  |  |  |  |  |  | 
| 706 |  |  |  |  |  |  | This function provides the mapping from functions used within this module and the PerlMonks API. | 
| 707 |  |  |  |  |  |  |  | 
| 708 |  |  |  |  |  |  | =cut | 
| 709 |  |  |  |  |  |  |  | 
| 710 |  |  |  |  |  |  | sub _get_function_to_url_hash { | 
| 711 |  |  |  |  |  |  |  | 
| 712 | 0 |  |  | 0 |  |  | my %relations = ( | 
| 713 |  |  |  |  |  |  |  | 
| 714 |  |  |  |  |  |  | 'get_chatterbox'                 =>    'http://www.perlmonks.org/?node_id=207304'                   , | 
| 715 |  |  |  |  |  |  | 'get_private_messages'           =>    'http://www.perlmonks.org/?node_id=15848'                    , | 
| 716 |  |  |  |  |  |  | 'send_chatter'                   =>    'http://www.perlmonks.org/?node_id=227820'                   , | 
| 717 |  |  |  |  |  |  |  | 
| 718 |  |  |  |  |  |  | 'get_user_nodes_info'            =>    'http://www.perlmonks.org/?node_id=32704'                    , | 
| 719 |  |  |  |  |  |  | 'get_user_nodes_reputation'      =>    'http://www.perlmonks.org/?node_id=507310'                   , | 
| 720 |  |  |  |  |  |  |  | 
| 721 |  |  |  |  |  |  | 'get_user_XP'                    =>    'http://www.perlmonks.org/?node_id=16046&showall=1'          , | 
| 722 |  |  |  |  |  |  | 'get_online_users'               =>    'http://www.perlmonks.org/?node_id=15851'                    , | 
| 723 |  |  |  |  |  |  | 'get_newest_nodes'               =>    'http://www.perlmonks.org/?node_id=30175'                    , | 
| 724 |  |  |  |  |  |  | 'get_node_details'               =>    'http://www.perlmonks.org/?node_id=37150'                    , | 
| 725 |  |  |  |  |  |  | 'get_node_thread'                =>    'http://www.perlmonks.org/?node_id=180684'                   , | 
| 726 |  |  |  |  |  |  |  | 
| 727 |  |  |  |  |  |  | 'get_scratch_pad'                =>    ''                                                           , | 
| 728 |  |  |  |  |  |  | 'get_best_nodes'                 =>    'http://www.perlmonks.org/?node_id=9066&displaytype=xml'     , | 
| 729 |  |  |  |  |  |  | 'get_worst_nodes'                =>    'http://www.perlmonks.org/?node_id=9488&displaytype=xml'     , | 
| 730 |  |  |  |  |  |  | 'get_selected_best_nodes'        =>    'http://www.perlmonks.org/?node_id=328478&displaytype=xml'   , | 
| 731 |  |  |  |  |  |  |  | 
| 732 |  |  |  |  |  |  | 'get_nav_info_for_node'          =>    'http://www.perlmonks.org/?node_id=693598'                   , | 
| 733 |  |  |  |  |  |  |  | 
| 734 |  |  |  |  |  |  | ) ; | 
| 735 |  |  |  |  |  |  |  | 
| 736 | 0 |  |  |  |  |  | return \%relations ; | 
| 737 |  |  |  |  |  |  |  | 
| 738 |  |  |  |  |  |  | } | 
| 739 |  |  |  |  |  |  |  | 
| 740 |  |  |  |  |  |  | =head2 _find_user_to_use | 
| 741 |  |  |  |  |  |  |  | 
| 742 |  |  |  |  |  |  | This function picks the user to use based on context, user passed and ( if exists ) authenticated user. | 
| 743 |  |  |  |  |  |  |  | 
| 744 |  |  |  |  |  |  | =cut | 
| 745 |  |  |  |  |  |  |  | 
| 746 |  |  |  |  |  |  | sub _find_user_to_use { | 
| 747 |  |  |  |  |  |  |  | 
| 748 | 0 |  |  | 0 |  |  | my $self = shift ; | 
| 749 | 0 |  |  |  |  |  | my $user = shift ; | 
| 750 |  |  |  |  |  |  |  | 
| 751 |  |  |  |  |  |  |  | 
| 752 | 0 | 0 |  |  |  |  | unless( $user ) { | 
| 753 | 0 | 0 |  |  |  |  | if( $self->{ AUTHENTICATED } ) { | 
| 754 | 0 |  |  |  |  |  | $user = $self->{ USERNAME } ; | 
| 755 |  |  |  |  |  |  | } else { | 
| 756 | 0 |  |  |  |  |  | croak( "Who do you want to get info for?\n" ) ; | 
| 757 |  |  |  |  |  |  | } | 
| 758 |  |  |  |  |  |  | } | 
| 759 |  |  |  |  |  |  |  | 
| 760 | 0 |  |  |  |  |  | return $user ; | 
| 761 |  |  |  |  |  |  |  | 
| 762 |  |  |  |  |  |  | } | 
| 763 |  |  |  |  |  |  |  | 
| 764 |  |  |  |  |  |  | =head1 AUTHOR | 
| 765 |  |  |  |  |  |  |  | 
| 766 |  |  |  |  |  |  | Harish Madabushi, C<<  >> | 
| 767 |  |  |  |  |  |  |  | 
| 768 |  |  |  |  |  |  | =head1 BUGS | 
| 769 |  |  |  |  |  |  |  | 
| 770 |  |  |  |  |  |  | Please report any bugs or feature requests to C, or through | 
| 771 |  |  |  |  |  |  | the web interface at L.  I will be notified, and then you'll | 
| 772 |  |  |  |  |  |  | automatically be notified of progress on your bug as I make changes. | 
| 773 |  |  |  |  |  |  |  | 
| 774 |  |  |  |  |  |  | =head1 SUPPORT | 
| 775 |  |  |  |  |  |  |  | 
| 776 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 777 |  |  |  |  |  |  |  | 
| 778 |  |  |  |  |  |  | perldoc WWW::PerlMonks | 
| 779 |  |  |  |  |  |  |  | 
| 780 |  |  |  |  |  |  | You can also look for information at: | 
| 781 |  |  |  |  |  |  |  | 
| 782 |  |  |  |  |  |  | =over 5 | 
| 783 |  |  |  |  |  |  |  | 
| 784 |  |  |  |  |  |  | =item * RT: CPAN's request tracker (report bugs here) | 
| 785 |  |  |  |  |  |  |  | 
| 786 |  |  |  |  |  |  | L | 
| 787 |  |  |  |  |  |  |  | 
| 788 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 789 |  |  |  |  |  |  |  | 
| 790 |  |  |  |  |  |  | L | 
| 791 |  |  |  |  |  |  |  | 
| 792 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 793 |  |  |  |  |  |  |  | 
| 794 |  |  |  |  |  |  | L | 
| 795 |  |  |  |  |  |  |  | 
| 796 |  |  |  |  |  |  | =item * Search CPAN | 
| 797 |  |  |  |  |  |  |  | 
| 798 |  |  |  |  |  |  | L | 
| 799 |  |  |  |  |  |  |  | 
| 800 |  |  |  |  |  |  | =item * GitHub | 
| 801 |  |  |  |  |  |  |  | 
| 802 |  |  |  |  |  |  | L | 
| 803 |  |  |  |  |  |  |  | 
| 804 |  |  |  |  |  |  | =back | 
| 805 |  |  |  |  |  |  |  | 
| 806 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 807 |  |  |  |  |  |  |  | 
| 808 |  |  |  |  |  |  | Copyright 2013 Harish Madabushi. | 
| 809 |  |  |  |  |  |  |  | 
| 810 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 811 |  |  |  |  |  |  | under the terms of the the Artistic License (2.0). You may obtain a | 
| 812 |  |  |  |  |  |  | copy of the full license at: | 
| 813 |  |  |  |  |  |  |  | 
| 814 |  |  |  |  |  |  | L | 
| 815 |  |  |  |  |  |  |  | 
| 816 |  |  |  |  |  |  | Any use, modification, and distribution of the Standard or Modified | 
| 817 |  |  |  |  |  |  | Versions is governed by this Artistic License. By using, modifying or | 
| 818 |  |  |  |  |  |  | distributing the Package, you accept this license. Do not use, modify, | 
| 819 |  |  |  |  |  |  | or distribute the Package, if you do not accept this license. | 
| 820 |  |  |  |  |  |  |  | 
| 821 |  |  |  |  |  |  | If your Modified Version has been derived from a Modified Version made | 
| 822 |  |  |  |  |  |  | by someone other than you, you are nevertheless required to ensure that | 
| 823 |  |  |  |  |  |  | your Modified Version complies with the requirements of this license. | 
| 824 |  |  |  |  |  |  |  | 
| 825 |  |  |  |  |  |  | This license does not grant you the right to use any trademark, service | 
| 826 |  |  |  |  |  |  | mark, tradename, or logo of the Copyright Holder. | 
| 827 |  |  |  |  |  |  |  | 
| 828 |  |  |  |  |  |  | This license includes the non-exclusive, worldwide, free-of-charge | 
| 829 |  |  |  |  |  |  | patent license to make, have made, use, offer to sell, sell, import and | 
| 830 |  |  |  |  |  |  | otherwise transfer the Package with respect to any patent claims | 
| 831 |  |  |  |  |  |  | licensable by the Copyright Holder that are necessarily infringed by the | 
| 832 |  |  |  |  |  |  | Package. If you institute patent litigation (including a cross-claim or | 
| 833 |  |  |  |  |  |  | counterclaim) against any party alleging that the Package constitutes | 
| 834 |  |  |  |  |  |  | direct or contributory patent infringement, then this Artistic License | 
| 835 |  |  |  |  |  |  | to you shall terminate on the date that such litigation is filed. | 
| 836 |  |  |  |  |  |  |  | 
| 837 |  |  |  |  |  |  | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | 
| 838 |  |  |  |  |  |  | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | 
| 839 |  |  |  |  |  |  | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | 
| 840 |  |  |  |  |  |  | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | 
| 841 |  |  |  |  |  |  | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | 
| 842 |  |  |  |  |  |  | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | 
| 843 |  |  |  |  |  |  | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | 
| 844 |  |  |  |  |  |  | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 845 |  |  |  |  |  |  |  | 
| 846 |  |  |  |  |  |  |  | 
| 847 |  |  |  |  |  |  | =cut | 
| 848 |  |  |  |  |  |  |  | 
| 849 |  |  |  |  |  |  | 1; # End of WWW::PerlMonks |