Skip to content

Commit cb62045

Browse files
author
Matt Oakes
committed
Added method and example for user.shout
1 parent a76e231 commit cb62045

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
+ event.getShouts
88
+ event.shout
99
+ user.getShouts
10+
+ user.shout
1011
* Fixed badly formed XML errors appearing. Will return error 95 when it happens. It is up to the application to
1112
decide how to handle the error. Thank you to her035 for the advice on how to fix it and the nice example
1213
that was made for me (http://her035.de/lastfm/test/xml.php). Much appreciated!

examples/user.shout/index.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
// Include the API
4+
require '../../lastfmapi/lastfmapi.php';
5+
6+
// Get the session auth data
7+
$file = fopen('../auth.txt', 'r');
8+
// Put the auth data into an array
9+
$authVars = array(
10+
'apiKey' => trim(fgets($file)),
11+
'secret' => trim(fgets($file)),
12+
'username' => trim(fgets($file)),
13+
'sessionKey' => trim(fgets($file)),
14+
'subscriber' => trim(fgets($file))
15+
);
16+
$config = array(
17+
'enabled' => true,
18+
'path' => '../../lastfmapi/',
19+
'cache_length' => 1800
20+
);
21+
// Pass the array to the auth class to eturn a valid auth
22+
$auth = new lastfmApiAuth('setsession', $authVars);
23+
24+
$apiClass = new lastfmApi();
25+
$userClass = $apiClass->getPackage($auth, 'user', $config);
26+
27+
// Setup the variables
28+
$methodVars = array(
29+
'user' => 'lotrgamemast',
30+
'message' => 'Looks like someone just ran the user.shout example'
31+
);
32+
33+
if ( $userClass->shout($methodVars) ) {
34+
echo '<b>Done</b>';
35+
}
36+
else {
37+
die('<b>Error '.$userClass->error['code'].' - </b><i>'.$userClass->error['desc'].'</i>');
38+
}
39+
40+
?>

lastfmapi/api/user.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,41 @@ public function getWeeklyTrackChart($methodVars) {
917917
return FALSE;
918918
}
919919
}
920+
921+
public function shout($methodVars) {
922+
// Only allow full authed calls
923+
if ( $this->fullAuth == TRUE ) {
924+
// Check for required variables
925+
if ( !empty($methodVars['user']) && !empty($methodVars['message']) ) {
926+
$vars = array(
927+
'method' => 'user.shout',
928+
'api_key' => $this->auth->apiKey,
929+
'user' => $methodVars['user'],
930+
'message' => $methodVars['message'],
931+
'sk' => $this->auth->sessionKey
932+
);
933+
$sig = $this->apiSig($this->auth->secret, $vars);
934+
$vars['api_sig'] = $sig;
935+
936+
if ( $call = $this->apiPostCall($vars) ) {
937+
return TRUE;
938+
}
939+
else {
940+
return FALSE;
941+
}
942+
}
943+
else {
944+
// Give a 91 error if incorrect variables are used
945+
$this->handleError(91, 'You must include user and message variables in the call for this method');
946+
return FALSE;
947+
}
948+
}
949+
else {
950+
// Give a 92 error if not fully authed
951+
$this->handleError(92, 'Method requires full auth. Call auth.getSession using lastfmApiAuth class');
952+
return FALSE;
953+
}
954+
}
920955
}
921956

922957
?>

0 commit comments

Comments
 (0)