Difference between revisions of "Ryzom API/Character"

From EncyclopAtys

Jump to: navigation, search
(page layout)
Line 1: Line 1:
 
Character
 
 
 
Access character information.
 
Access character information.
Base URL
 
 
    /character.php?apikey=key
 
    /character.php?apikey[]=key1&apikey[]=key2
 
 
URL Parameters
 
  
apikey
+
===Usage===
    Character API key starting with 'c'
+
<base URL>/character.php?apikey=key
 +
<base URL> /character.php?apikey[=key1&apikey[]=key2
  
Cache Duration
+
====URL Parameters====
 +
;apikey:
 +
:Character API key starting with 'c'
  
 +
====Cache Duration ====
 
<character> xml element has attributes *created* and *cached_until* (utc timestamp)
 
<character> xml element has attributes *created* and *cached_until* (utc timestamp)
XML structure
 
  
API is able to return information about multiple characters at once and so each <character> element is child of <ryzomapi> root element
+
==== XML structure ====
  
<ryzomapi>
+
API is able to return information about multiple characters at once and so each <character> element is child of <ryzomapi> root element:
 +
:<syntaxhighlight lang="xml"><ryzomapi>
 
   <character apikey="key1" created="1387369332" modules="C01:P01" cached_until="1387369632">
 
   <character apikey="key1" created="1387369332" modules="C01:P01" cached_until="1387369632">
 
     ....
 
     ....
Line 27: Line 22:
 
     ....
 
     ....
 
   </character>
 
   </character>
</ryzomapi>
+
</ryzomapi></syntaxhighlight>
               
+
             
 
+
Invalid key error:
Invalid key error
+
:<syntaxhighlight lang="xml"><character apikey="key1" created="1387369873">
 
 
<character apikey="key1" created="1387369873">
 
 
   <error code="404">invalid key</error>
 
   <error code="404">invalid key</error>
</character>
+
</character></syntaxhighlight>
               
+
Possible error codes are listed on [[Ryzom API#API error codes|API error codes]].
 
 
Possible error codes are listed on API error codes.
 
PHP interface
 
 
 
ryzom_character_api($apikey)
 
  
$apikey can be either string (single key) or array of strings.
+
=== PHP interface ===
  
On success, function returns associative array of SimpleXMLElement with apikey as array index.
+
ryzom_character_api($apikey)
  
On failure, function returns boolean false.
+
::$apikey can be either string (single key) or array of strings.
 +
:On success, function returns associative array of SimpleXMLElement with apikey as array index.
 +
:On failure, function returns boolean false.
  
 
<?php
 
<?php
 
require_once "ryzomapi_lite.php";
 
require_once "ryzomapi_lite.php";
  
function info($char) {
+
:<syntaxhighlight lang="php">function info($char) {
 
   if (isset($char->error)) {
 
   if (isset($char->error)) {
 
     $apikey = htmlspecialchars($char['apikey']);
 
     $apikey = htmlspecialchars($char['apikey']);
Line 61: Line 51:
 
     echo "Character name: {$name}";
 
     echo "Character name: {$name}";
 
   }
 
   }
}
+
}:</syntaxhighlight>
  
$apikey = 'cABCDEF';
+
:<syntaxhighlight lang="php">$apikey = 'cABCDEF';
 
$chars = ryzom_character_api($apikey);
 
$chars = ryzom_character_api($apikey);
 
if ($chars !== false) {
 
if ($chars !== false) {
Line 69: Line 59:
 
} else {
 
} else {
 
   echo "Character API failed";
 
   echo "Character API failed";
}
+
}</syntaxhighlight>
  
$apikeys = ['cABCDEF', 'c123456'];
+
:<syntaxhighlight lang="php">$apikeys = ['cABCDEF', 'c123456'];
 
$chars = ryzom_character_api($apikeys);
 
$chars = ryzom_character_api($apikeys);
 
if ($chars !== false) {
 
if ($chars !== false) {
Line 79: Line 69:
 
} else {
 
} else {
 
   echo "Character API failed";
 
   echo "Character API failed";
}
+
}</syntaxhighlight>
 
                  
 
                  
  
 
<noinclude>[[Category:Ryzom API|Character]]</noinclude>
 
<noinclude>[[Category:Ryzom API|Character]]</noinclude>

Revision as of 20:53, 22 July 2020

Access character information.

Usage

<base URL>/character.php?apikey=key
<base URL> /character.php?apikey[=key1&apikey[]=key2

URL Parameters

apikey
Character API key starting with 'c'

Cache Duration

<character> xml element has attributes *created* and *cached_until* (utc timestamp)

XML structure

API is able to return information about multiple characters at once and so each <character> element is child of <ryzomapi> root element:

<ryzomapi>
  <character apikey="key1" created="1387369332" modules="C01:P01" cached_until="1387369632">
    ....
  </character>
  <character apikey="key2" created="1387369332" modules="P01" cached_until="1387369632">
    ....
  </character>
</ryzomapi>

Invalid key error:

<character apikey="key1" created="1387369873">
  <error code="404">invalid key</error>
</character>

Possible error codes are listed on API error codes.

PHP interface

ryzom_character_api($apikey)
$apikey can be either string (single key) or array of strings.
On success, function returns associative array of SimpleXMLElement with apikey as array index.
On failure, function returns boolean false.

<?php require_once "ryzomapi_lite.php";

function info($char) {
  if (isset($char->error)) {
    $apikey = htmlspecialchars($char['apikey']);
    $error = htmlspecialchars($char->error);
    $code = (int)$char->error['code'];
    echo "Character API key '{$apikey}' failed: {$code}:{$error}";
  } else {
    $name = htmlspecialchars($char->name);
    echo "Character name: {$name}";
  }
}:
$apikey = 'cABCDEF';
$chars = ryzom_character_api($apikey);
if ($chars !== false) {
  info($chars[$apikey]);
} else {
  echo "Character API failed";
}
$apikeys = ['cABCDEF', 'c123456'];
$chars = ryzom_character_api($apikeys);
if ($chars !== false) {
  foreach($chars as $char) {
    info($char);
  }
} else {
  echo "Character API failed";
}