API Documentation RunningExamples server.get possible server items PHP
Aus EUserv Wiki
(Unterschied zwischen Versionen)
Root (Diskussion | Beiträge) |
Root (Diskussion | Beiträge) |
||
Zeile 3: | Zeile 3: | ||
<nowiki> | <nowiki> | ||
<?php | <?php | ||
+ | |||
//includes the class library | //includes the class library | ||
include_once("lib/xmlrpc.inc"); | include_once("lib/xmlrpc.inc"); | ||
$xmlrpc_internalencoding = 'UTF-8'; | $xmlrpc_internalencoding = 'UTF-8'; | ||
+ | |||
$host="api.test.euserv.net"; | $host="api.test.euserv.net"; | ||
$port=443; | $port=443; | ||
Zeile 11: | Zeile 13: | ||
$password="<API_USER_PASSWORD>"; | $password="<API_USER_PASSWORD>"; | ||
$api_path="/"; | $api_path="/"; | ||
+ | |||
//defines the function | //defines the function | ||
function server_get_possible_server_items($host,$port,$username,$password,$api_path) | function server_get_possible_server_items($host,$port,$username,$password,$api_path) | ||
{ | { | ||
- | //creates the serverurl | + | |
- | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; | + | //creates the serverurl |
- | //----------creates the message which will be send to the server---------- | + | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; |
- | //creates the request for the XML-RPC Server | + | |
- | $request = new xmlrpcmsg('server.get_possible_server_items'); | + | //----------creates the message which will be send to the server---------- |
- | //adds parameters to the request | + | |
- | $request->addParam | + | //creates the request for the XML-RPC Server |
- | ( | + | $request = new xmlrpcmsg('server.get_possible_server_items'); |
- | //creates a value of type struct which contains an array with the username and password | + | |
- | new xmlrpcval | + | //adds parameters to the request |
- | ( | + | $request->addParam |
- | array | + | ( |
- | ( | + | |
- | //creates a value of type string which contains the "$username" | + | //creates a value of type struct which contains an array with the username and password |
- | 'login' => new xmlrpcval($username, 'string'), | + | new xmlrpcval |
- | //creates a value of type string which contains the "$password" | + | ( |
- | 'password' => new xmlrpcval($password, 'string'), | + | array |
- | ) | + | |
- | ,'struct' | + | ( |
- | ) | + | //creates a value of type string which contains the "$username" |
- | ); | + | 'login' => new xmlrpcval($username, 'string'), |
- | //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- | + | |
- | //creates the client | + | //creates a value of type string which contains the "$password" |
- | $client = new xmlrpc_client($serverurl); | + | 'password' => new xmlrpcval($password, 'string'), |
- | //disable SSL Keycheck | + | ) |
- | $client->setSSLVerifyPeer(0); | + | ,'struct' |
- | //----------sends the request to the server and gets the response---------- | + | ) |
- | //sends the request via https and writes it into $response. timeout is set to 0 | + | ); |
- | $response = $client->send($request,0,'https'); | + | |
- | //generates a storable representation of $response and writes it into $result_xml | + | //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- |
- | //echo $response->serialize(); | + | |
- | //checks the response. if the method "faultCode" returns zero, the response was succesfull | + | //creates the client |
- | if (0==$response->faultCode()) | + | $client = new xmlrpc_client($serverurl); |
- | { | + | |
- | //returns the value sent by the server | + | //disable SSL Keycheck |
- | $value = $response->value(); | + | $client->setSSLVerifyPeer(0); |
- | //returns the actual PHP-language value of "value" | + | |
- | $result_obj = $value->scalarval(); | + | //----------sends the request to the server and gets the response---------- |
- | //destroys "value" | + | |
- | unset($value); | + | //sends the request via https and writes it into $response. timeout is set to 0 |
- | } | + | $response = $client->send($request,0,'https'); |
- | else | + | |
- | { | + | //generates a storable representation of $response and writes it into $result_xml |
- | //returns the faultCode and the faultString | + | //echo $response->serialize(); |
- | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); | + | |
- | } | + | //checks the response. if the method "faultCode" returns zero, the response was succesfull |
- | //destroys "client" | + | if (0==$response->faultCode()) |
- | unset($client); | + | { |
- | //destroys "response" | + | //returns the value sent by the server |
- | unset($response); | + | $value = $response->value(); |
- | //----------reads the result_obj---------- | + | |
- | //if result_obj is set then it returns the actual PHP-language value of "result_obj" | + | //returns the actual PHP-language value of "value" |
- | if (isset($result_obj['status'])) | + | $result_obj = $value->scalarval(); |
- | { | + | |
- | $value['status'] = $result_obj['status']->scalarval(); | + | //destroys "value" |
- | } | + | unset($value); |
- | if (isset($result_obj['possible_server_items'])) | + | } |
- | { | + | else |
- | //resets the internal pointer for structEach() to the beginning of the struct | + | { |
- | $result_obj['possible_server_items']->structreset(); | + | //returns the faultCode and the faultString |
- | //reads the keys and values and list returns an array. if no keys and values are read out list returns no array and the | + | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); |
- | while-loop stops execution | + | } |
- | while (list($keyname, $data) = $result_obj['possible_server_items']->structEach()) | + | |
- | { | + | //destroys "client" |
- | //gets the "server_items" | + | unset($client); |
- | $data= $data->scalarval(); | + | |
- | //reads the value of each member and writes it into an array | + | //destroys "response" |
- | $server_items[$keyname]['item_id'] = $data['item_id']->scalarval(); | + | unset($response); |
- | $server_items[$keyname]['item_name'] = $data['item_name']->scalarval(); | + | |
- | $server_items[$keyname]['item_net_amount'] = $data['item_net_amount']->scalarval(); | + | |
- | $server_items[$keyname]['item_gross_amount'] = $data['item_gross_amount']->scalarval(); | + | //----------reads the result_obj---------- |
- | $server_items[$keyname]['item_net_setup_fee'] = $data['item_net_setup_fee']->scalarval(); | + | |
- | $server_items[$keyname]['item_gross_setup_fee'] = $data['item_net_setup_fee']->scalarval(); | + | //if result_obj is set then it returns the actual PHP-language value of "result_obj" |
- | $server_items[$keyname]['item_billing_period'] = $data['item_billing_period']->scalarval(); | + | |
- | $server_items[$keyname]['item_contract_running_time'] = $data['item_contract_running_time']->scalarval(); | + | if (isset($result_obj['status'])) |
- | } | + | { |
- | //writes the array "server_list_data" into the array "value" | + | $value['status'] = $result_obj['status']->scalarval(); |
- | $value['possible_server_items'] = $server_items; | + | } |
- | } | + | |
- | return $value; | + | if (isset($result_obj['possible_server_items'])) |
+ | { | ||
+ | |||
+ | //resets the internal pointer for structEach() to the beginning of the struct | ||
+ | $result_obj['possible_server_items']->structreset(); | ||
+ | |||
+ | //reads the keys and values and list returns an array. if no keys and values are read out list returns no array and the while-loop stops execution | ||
+ | while (list($keyname, $data) = $result_obj['possible_server_items']->structEach()) | ||
+ | { | ||
+ | //gets the "server_items" | ||
+ | $data= $data->scalarval(); | ||
+ | |||
+ | //reads the value of each member and writes it into an array | ||
+ | $server_items[$keyname]['item_id'] = $data['item_id']->scalarval(); | ||
+ | $server_items[$keyname]['item_name'] = $data['item_name']->scalarval(); | ||
+ | $server_items[$keyname]['item_net_amount'] = $data['item_net_amount']->scalarval(); | ||
+ | $server_items[$keyname]['item_gross_amount'] = $data['item_gross_amount']->scalarval(); | ||
+ | $server_items[$keyname]['item_net_setup_fee'] = $data['item_net_setup_fee']->scalarval(); | ||
+ | $server_items[$keyname]['item_gross_setup_fee'] = $data['item_net_setup_fee']->scalarval(); | ||
+ | $server_items[$keyname]['item_billing_period'] = $data['item_billing_period']->scalarval(); | ||
+ | $server_items[$keyname]['item_contract_running_time'] = $data['item_contract_running_time']->scalarval(); | ||
+ | } | ||
+ | |||
+ | //writes the array "server_list_data" into the array "value" | ||
+ | $value['possible_server_items'] = $server_items; | ||
+ | } | ||
+ | return $value; | ||
} | } | ||
+ | |||
//calls the function | //calls the function | ||
- | $result = server_get_possible_server_items($host,$port,$username,$password,$api_path); | + | $result = server_get_possible_server_items($host,$port,$username,$password,$api_path); |
+ | |||
if(0==$result['faultCode']) | if(0==$result['faultCode']) | ||
{ | { | ||
- | echo "Status: ".$result['status']."<br><br>"; | + | echo "Status: ".$result['status']."<br><br>"; |
- | //writes the array "server_details" into "daten" | + | |
- | $daten = $result["possible_server_items"]; | + | //writes the array "server_details" into "daten" |
- | //gets the array_keys(members) of "daten" | + | $daten = $result["possible_server_items"]; |
- | $datenkeys = array_keys($daten); | + | |
- | $k=0; | + | //gets the array_keys(members) of "daten" |
- | //counts the arraykeys, the number of arraykeys will be used in the do-while construct | + | $datenkeys = array_keys($daten); |
- | $anzahlkeys = count($datenkeys); | + | $k=0; |
- | do | + | |
- | { | + | //counts the arraykeys, the number of arraykeys will be used in the do-while construct |
- | //outputs the data | + | $anzahlkeys = count($datenkeys); |
- | echo " <u>item_id:</u> ".$daten[$datenkeys[$k]]['item_id']; | + | do |
- | echo " <u>item_name:</u> ".$daten[$datenkeys[$k]]['item_name']; | + | { |
- | echo " <u>item_net_amount:</u> ".$daten[$datenkeys[$k]]['item_net_amount']; | + | //outputs the data |
- | echo " <u>item_gross_amount:</u> ".$daten[$datenkeys[$k]]['item_gross_amount']; | + | echo " <u>item_id:</u> ".$daten[$datenkeys[$k]]['item_id']; |
- | echo " <u>item_net_setup_fee:</u> ".$daten[$datenkeys[$k]]['item_net_setup_fee']; | + | echo " <u>item_name:</u> ".$daten[$datenkeys[$k]]['item_name']; |
- | echo " <u>item_gross_setup_fee:</u> ".$daten[$datenkeys[$k]]['item_gross_setup_fee']; | + | echo " <u>item_net_amount:</u> ".$daten[$datenkeys[$k]]['item_net_amount']; |
- | echo " <u>item_billing_period:</u> ".$daten[$datenkeys[$k]]['item_billing_period']; | + | echo " <u>item_gross_amount:</u> ".$daten[$datenkeys[$k]]['item_gross_amount']; |
- | echo " <u>item_contract_running_time:</u> ".$daten[$datenkeys[$k]]['item_contract_running_time']; | + | echo " <u>item_net_setup_fee:</u> ".$daten[$datenkeys[$k]]['item_net_setup_fee']; |
- | echo "<br>"; | + | echo " <u>item_gross_setup_fee:</u> ".$daten[$datenkeys[$k]]['item_gross_setup_fee']; |
- | $k=$k+1; | + | echo " <u>item_billing_period:</u> ".$daten[$datenkeys[$k]]['item_billing_period']; |
- | } | + | echo " <u>item_contract_running_time:</u> ".$daten[$datenkeys[$k]]['item_contract_running_time']; |
+ | echo "<br>"; | ||
+ | $k=$k+1; | ||
+ | } | ||
while($k<$anzahlkeys); | while($k<$anzahlkeys); | ||
} | } | ||
else | else | ||
{ | { | ||
- | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; | + | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; |
} | } | ||
?> | ?> | ||
</nowiki> | </nowiki> |
Aktuelle Version vom 07:45, 6. Sep. 2012
back to API Documentation
server.get_possible_server_items
<?php //includes the class library include_once("lib/xmlrpc.inc"); $xmlrpc_internalencoding = 'UTF-8'; $host="api.test.euserv.net"; $port=443; $username="<API_USER>"; $password="<API_USER_PASSWORD>"; $api_path="/"; //defines the function function server_get_possible_server_items($host,$port,$username,$password,$api_path) { //creates the serverurl $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; //----------creates the message which will be send to the server---------- //creates the request for the XML-RPC Server $request = new xmlrpcmsg('server.get_possible_server_items'); //adds parameters to the request $request->addParam ( //creates a value of type struct which contains an array with the username and password new xmlrpcval ( array ( //creates a value of type string which contains the "$username" 'login' => new xmlrpcval($username, 'string'), //creates a value of type string which contains the "$password" 'password' => new xmlrpcval($password, 'string'), ) ,'struct' ) ); //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- //creates the client $client = new xmlrpc_client($serverurl); //disable SSL Keycheck $client->setSSLVerifyPeer(0); //----------sends the request to the server and gets the response---------- //sends the request via https and writes it into $response. timeout is set to 0 $response = $client->send($request,0,'https'); //generates a storable representation of $response and writes it into $result_xml //echo $response->serialize(); //checks the response. if the method "faultCode" returns zero, the response was succesfull if (0==$response->faultCode()) { //returns the value sent by the server $value = $response->value(); //returns the actual PHP-language value of "value" $result_obj = $value->scalarval(); //destroys "value" unset($value); } else { //returns the faultCode and the faultString return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); } //destroys "client" unset($client); //destroys "response" unset($response); //----------reads the result_obj---------- //if result_obj is set then it returns the actual PHP-language value of "result_obj" if (isset($result_obj['status'])) { $value['status'] = $result_obj['status']->scalarval(); } if (isset($result_obj['possible_server_items'])) { //resets the internal pointer for structEach() to the beginning of the struct $result_obj['possible_server_items']->structreset(); //reads the keys and values and list returns an array. if no keys and values are read out list returns no array and the while-loop stops execution while (list($keyname, $data) = $result_obj['possible_server_items']->structEach()) { //gets the "server_items" $data= $data->scalarval(); //reads the value of each member and writes it into an array $server_items[$keyname]['item_id'] = $data['item_id']->scalarval(); $server_items[$keyname]['item_name'] = $data['item_name']->scalarval(); $server_items[$keyname]['item_net_amount'] = $data['item_net_amount']->scalarval(); $server_items[$keyname]['item_gross_amount'] = $data['item_gross_amount']->scalarval(); $server_items[$keyname]['item_net_setup_fee'] = $data['item_net_setup_fee']->scalarval(); $server_items[$keyname]['item_gross_setup_fee'] = $data['item_net_setup_fee']->scalarval(); $server_items[$keyname]['item_billing_period'] = $data['item_billing_period']->scalarval(); $server_items[$keyname]['item_contract_running_time'] = $data['item_contract_running_time']->scalarval(); } //writes the array "server_list_data" into the array "value" $value['possible_server_items'] = $server_items; } return $value; } //calls the function $result = server_get_possible_server_items($host,$port,$username,$password,$api_path); if(0==$result['faultCode']) { echo "Status: ".$result['status']."<br><br>"; //writes the array "server_details" into "daten" $daten = $result["possible_server_items"]; //gets the array_keys(members) of "daten" $datenkeys = array_keys($daten); $k=0; //counts the arraykeys, the number of arraykeys will be used in the do-while construct $anzahlkeys = count($datenkeys); do { //outputs the data echo " <u>item_id:</u> ".$daten[$datenkeys[$k]]['item_id']; echo " <u>item_name:</u> ".$daten[$datenkeys[$k]]['item_name']; echo " <u>item_net_amount:</u> ".$daten[$datenkeys[$k]]['item_net_amount']; echo " <u>item_gross_amount:</u> ".$daten[$datenkeys[$k]]['item_gross_amount']; echo " <u>item_net_setup_fee:</u> ".$daten[$datenkeys[$k]]['item_net_setup_fee']; echo " <u>item_gross_setup_fee:</u> ".$daten[$datenkeys[$k]]['item_gross_setup_fee']; echo " <u>item_billing_period:</u> ".$daten[$datenkeys[$k]]['item_billing_period']; echo " <u>item_contract_running_time:</u> ".$daten[$datenkeys[$k]]['item_contract_running_time']; echo "<br>"; $k=$k+1; } while($k<$anzahlkeys); } else { echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; } ?>