Barcamp

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Barcamp - Presentation Transcript

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

    + renelcrenelc Nominate

    custom

    657 views, 0 favs, 1 embeds more stats

    Como generar un API para tu sitio web usando XML-RP more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 657
      • 633 on SlideShare
      • 24 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 1
    Most viewed embeds
    • 24 views on http://www.rene.com.mx

    more

    All embeds
    • 24 views on http://www.rene.com.mx

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories