Your SlideShare is downloading. ×
0
Barcamp
Barcamp
Barcamp
Barcamp
Barcamp
Barcamp
Barcamp
Barcamp
Barcamp
Barcamp
Barcamp
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Barcamp

1,195

Published on

Como generar un API para tu sitio web usando XML-RPC

Como generar un API para tu sitio web usando XML-RPC

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,195
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. XML-RPC <ul><ul><li>Como crear un API para tu sitio usando </li></ul></ul><ul><ul><li>XML-RPC y PHP </li></ul></ul><ul><ul><li>Barcamp 2 - Queretaro </li></ul></ul><ul><ul><li>René López Caballero </li></ul></ul>
  • 2. ¿XML-RPC? Es una especificacion que permite a software corriendo en diferentes SO y ambientes realizar llamadas a procedimientos sobre el internet Es una llamada a un procedimiento remoto usando HTTP y XML para la codificacion
  • 3. ¿Quienes lo usan? <ul><li>Flickr puede usar REST, SOAP, XML-RPC </li></ul><ul><li>Wordpress </li></ul><ul><li>Movable Type </li></ul><ul><li>Weblogs.Com </li></ul>
  • 4. Llamada XML-RPC &lt;?xml version=&amp;quot;1.0&amp;quot;?&gt; &lt;methodCall&gt; &lt;methodName&gt;jibberjobber.getContacts&lt;/methodName&gt; &lt;params&gt; &lt;param&gt; &lt;value&gt;&lt;struct&gt; &lt;member&gt;&lt;name&gt;name&lt;/name&gt; &lt;value&gt;&lt;string&gt;John&lt;/string&gt;&lt;/value&gt; &lt;/member&gt; &lt;member&gt;&lt;name&gt;lname&lt;/name&gt; &lt;value&gt;&lt;string&gt;Doe&lt;/string&gt;&lt;/value&gt; &lt;/member&gt; &lt;/struct&gt;&lt;/value&gt; &lt;/param&gt; &lt;/params&gt; &lt;/methodCall&gt;
  • 5. Tipos de Datos
  • 6. Struct y Array &lt;struct&gt; &lt;struct&gt; &lt;member&gt; &lt;name&gt;name&lt;/name&gt; &lt;value&gt;&lt;string&gt;John&lt;/string&gt;&lt;/value&gt; &lt;/member&gt; &lt;member&gt; &lt;name&gt;age&lt;/name&gt; &lt;value&gt;&lt;i4&gt;21&lt;/i4&gt;&lt;/value&gt; &lt;/member&gt; &lt;/struct&gt; &lt;array&gt; &lt;array&gt; &lt;data&gt; &lt;value&gt;&lt;i4&gt;12&lt;/i4&gt;&lt;/value&gt; &lt;value&gt;&lt;string&gt;Egypt&lt;/string&gt;&lt;/value&gt; &lt;value&gt;&lt;boolean&gt;0&lt;/boolean&gt;&lt;/value&gt; &lt;value&gt;&lt;int&gt;-31&lt;/int&gt;&lt;/value&gt; &lt;/data&gt; &lt;/array&gt;
  • 7. Respuestas XML &lt;?xml version=&amp;quot;1.0&amp;quot;?&gt; &lt;methodResponse&gt; &lt;params&gt; &lt;param&gt; &lt;value&gt;&lt;string&gt;South Dakota&lt;/string&gt;&lt;/value&gt; &lt;/param&gt; &lt;/params&gt; &lt;/methodResponse&gt; &lt;?xml version=&amp;quot;1.0&amp;quot;?&gt; &lt;methodResponse&gt; &lt;fault&gt; &lt;value&gt; &lt;struct&gt; &lt;member&gt; &lt;name&gt;faultCode&lt;/name&gt; &lt;value&gt;&lt;int&gt;4&lt;/int&gt;&lt;/value&gt; &lt;/member&gt; &lt;member&gt; &lt;name&gt;faultString&lt;/name&gt; &lt;value&gt;&lt;string&gt;Too many parameters.&lt;/string&gt;&lt;/value&gt; &lt;/member&gt; &lt;/struct&gt; &lt;/value&gt; &lt;/fault&gt; &lt;/methodResponse&gt;
  • 8. Libreria http://phpxmlrpc.sourceforge.net/
  • 9. Ejemplo Servidor &lt;?php include( &apos;xmlrpc/xmlrpc.inc&apos; ); include( &apos;xmlrpc/xmlrpcs.inc&apos; ); $xmlrpc_defencoding = &amp;quot;UTF8&amp;quot;; $xmlrpc_internalencoding = &apos;UTF-8&apos;; function getStructValue( &amp;$struct, $key ) { if( $struct-&gt;structMemExists( $key ) ) { $val = $struct-&gt;structMem($key); return $val-&gt;scalarVal(); } else { return false; } }
  • 10. Continua function add( $params ) { global $xmlrpcerruser; $struct = $params-&gt;getParam(0); $name = getStructValue( $struct, &apos;name&apos; ); // Aqui se prueba si el usuario esta autorizado if( true ){ $struct = array( &apos;id&apos; =&gt; new xmlrpcval( $id, &apos;int&apos; ), &apos;dateCreated&apos; =&gt; new xmlrpcval( $data[&apos;dateCreated&apos;], &apos;dateTime.iso8601&apos; ) ); return new xmlrpcresp( new xmlrpcval( $struct, &apos;struct&apos; ) ); } else { return new xmlrpcresp( 0, $xmlrpcerruser,, &amp;quot;The login failed&amp;quot; ); } } $s = new xmlrpc_server( array( &amp;quot;example.add&amp;quot; =&gt; array(&amp;quot;function&amp;quot; =&gt; &amp;quot;add&amp;quot;), ) ); ?&gt;
  • 11. Ejemplo del cliente &lt;?php include( &apos;xmlrpc/xmlrpc.inc&apos; ); include( &apos;xmlrpc/xmlrpcs.inc&apos; ); $client = new xmlrpc_client( &amp;quot;http://127.0.0.1/barcamp/xml-rpc.php&amp;quot; ); $client-&gt;setDebug( 2 ); $struct = array( &apos;username&apos; =&gt; new xmlrpcval(&apos;demo&apos;, &apos;string&apos;), &apos;password&apos; =&gt; new xmlrpcval(&apos;demo&apos;, &apos;string&apos; ), &apos;name&apos; =&gt; new xmlrpcval(&apos;John&apos;, &apos;string&apos; ) ); $message = new xmlrpcmsg( &amp;quot;example.add &amp;quot;, array( new xmlrpcval( $struct, &apos;struct&apos; ) ) ); $response = $client-&gt;send( $message ); ?&gt;

×