Revver Developer Center: Samples : Asp

Revver Developer Center

XML-RPC API.Example Code

ASP

System Requirements

The Revver API utilizes XML/RPC calls. There is an opensource library available for XML/RPC for ASP. You can download it here:

  • http://aspxmlrpc.sourceforge.net
  • Download

    The software samples below are provided to you free of charge, and on an “as-is” basis.

  • There are no files to download at this time.

  • Special Notes

    ASP/VBScript does not fully support the "Struct" form that is returned by the API. You will have to use a combination of Arrays and Dictionary Objects in order to store the returned values. It is recommended that you use JScript for this purpose.

    C#/.NET

    System Requirements

    The Revver API utilizes XML-RPC. The XML-RPC.NET library by Cook Computing is required to execute the code below. The library and further documentation are availble at the XML-RPC.NET Website.

    Downloads

    The software examples below are provided to you free of charge, and on an “as-is” basis.

    Description

    The GUI code samples were contributed by a RevverAPI user. Please Note: the code sample compromises an incomplete set of functions for the API. There are many more available functions as you will see in the API Documentation. In order to use this code you will have to have a C#/.NET compiler, and for the GUI version, you will need Microsoft Visual Studio Express or greater.

    View Code

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using CookComputing.XmlRpc;
    
    namespace RevverAPIImpl
    {
    
        [XmlRpcUrl("https://api.staging.revver.com/xml/1.0/?login=username&passwd=password")]
    
    
    
        public interface RevverApiInterfaces : IXmlRpcProxy
        {
            [XmlRpcMethod("user.authenticate")]
            bool authenticate(string user, string password);
    
            [XmlRpcMethod("video.find")]
            System.Object video_find(XmlRpcStruct query, string[] return_fields, XmlRpcStruct result_options);
    
            [XmlRpcMethod("collection.create")]
            int collection_create(string type, string name, XmlRpcStruct query);
    
            [XmlRpcMethod("collection.collect")]
            System.Object collection_collect(int id, string[] return_fields);
    
            [XmlRpcMethod("user.create")]
            void user_create(string login_name, XmlRpcStruct options);
    
            [XmlRpcMethod("user.find")]
            System.Object user_find(XmlRpcStruct query, string[] return_fields, XmlRpcStruct options);
    
            [XmlRpcMethod("video.getUploadTokens")]
            System.Object video_get_upload_tokens(int count, XmlRpcStruct options);
    
            [XmlRpcMethod("video.create")]
            int video_create(string token, string title, string[] keywords, int age_restriction, XmlRpcStruct options);
        }
    
    
    
        class Program
        {
            static void Main(string[] args)
            {
                RevverAPI api = new RevverAPI();
                api.authenticate("username", "password");
    
                System.Object return_object = null;
                XmlRpcStruct options = new XmlRpcStruct();
                XmlRpcStruct query = new XmlRpcStruct();
    
                // "URL" in the documentation is wrong. It is all lowercase: "url"
                string[] fields_to_return = {"id", "title", "owner", "author", "status", "ageRestriction", "publicationDate", "modifiedDate", "url",
                                             "description", "keywords", "duration", "size", "rating", "credits", "thumbnailUrl", "quicktimeMediaUrl",
                                             "quicktimeJsUrl", "quicktimeDownloadUrl", "flashMediaUrl", "flashJsUrl", "views", "clicks", "revenue",
                                             "affiliateId"};
    
                // --------------------------------------------- Searching Videos ---------------------------------------------
                try
                {
                    options.Add("count", true);
                    options.Add("limit", 10);
                    query.Add("search", new string[] { "comedy" });
    
                    return_object = api.video_find(query, fields_to_return, options);
                    options.Clear();
                    query.Clear();
    
                    PrintObject(return_object, 0);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception occured in test_find_user() in test_child_user_upload_video. Description: " + ex.Message);
                }
                // -------------------------------------------- Uploading Files -----------------------------
                try
                {
                    options.Add("owner", "SomeTestUser");
                    System.Object tokens = api.video_get_upload_tokens(1, options);
                    System.Array token_tuple = (System.Array)tokens;
                    string upload_url = (string)token_tuple.GetValue(0);
                    System.Array token_array = (System.Array)token_tuple.GetValue(1);
                    string upload_token = (string)token_array.GetValue(0);
                    string title = "Greg Dolley's video test #3...";
                    string[] keywords = new string[] { ".net", "test", "example" };
                    int age_restriction = 1;
    
                    //options.Add("description", "This is a video of an iPod that crashes and then reboots continuously");
                    options.Add("description", "Example using .Net Sample Code");
    
                    int new_video_id = api.video_create(upload_token, title, keywords, age_restriction, options);
    
                    System.Net.WebClient client = new System.Net.WebClient();
                    //client.UploadFile(upload_url+"/"+upload_token, "c:\\Watch_Marks_Video_Ipod_Crash_Infinitely.wmv");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception occured in test_find_user() in test_child_user_upload_video. Description: " + ex.Message);
                }
    
    
    
    
    
                // --------------------------------------------- Video_Report ---------------------------------------------
                options.Add("count", true);
                options.Add("limit", 10);
                query.Add("search", new string[] { "comedy" });
    
                return_object = api.video_find(query, fields_to_return, options);
                options.Clear();
                query.Clear();
    
                PrintObject(return_object, 0);
    
                // --------------------------------------------- Video_Find ---------------------------------------------
                options.Add("count", true);
                options.Add("limit", 10);
                query.Add("search", new string[] { "comedy" });
    
                return_object = api.video_find(query, fields_to_return, options);
                options.Clear();
                query.Clear();
    
                PrintObject(return_object, 0);
            }
        }
    
    
    
        class RevverAPI
        {
    
            private string username = "username";
            private string password = "passwd";
    
            public string authenticate(string user, string password)
            {
                RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
    
                api.KeepAlive = false;
                api.Credentials = new NetworkCredential(username, password);
                bool ret_val = api.authenticate(user, password);
    
                if (ret_val)
                {
                    return ("true");
                }
    
                return ("false");
            }
    
            public System.Object video_find(XmlRpcStruct query, string[] return_fields, XmlRpcStruct options)
            {
                System.Object return_struct = null;
                XmlRpcStruct my_options = new XmlRpcStruct();
                XmlRpcStruct my_query = new XmlRpcStruct();
    
                try
                {
                    RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
    
                    api.KeepAlive = false;
                    api.Credentials = new NetworkCredential(username, password);
    
                    return_struct = api.video_find(query, return_fields, options);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
    
                return (return_struct);
            }
    
            public int collection_create(string type, string name, XmlRpcStruct query)
            {
                int new_collection_id = -1;
    
                try
                {
                    RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
                    api.KeepAlive = false;
                    api.Credentials = new NetworkCredential(username, password);
    
                    new_collection_id = api.collection_create(type, name, query);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
    
                return (new_collection_id);
            }
    
            public System.Object collection_collect(int id, string[] return_fields)
            {
                System.Object return_object = null;
    
                try
                {
                    RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
                    api.KeepAlive = false;
                    api.Credentials = new NetworkCredential(username, password);
    
                    return_object = api.collection_collect(id, return_fields);
                }
                catch (Exception ex)
                {
                    return_object = new Object();
                    return_object = ex.Message;
                }
    
                return (return_object);
            }
    
            public void user_create(string login_name, XmlRpcStruct options)
            {
                try
                {
                    RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
                    api.KeepAlive = false;
                    api.Credentials = new NetworkCredential(username, password);
    
                    api.user_create(login_name, options);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    
            public System.Object user_find(XmlRpcStruct query, string[] return_fields, XmlRpcStruct options)
            {
                System.Object return_object = null;
    
                try
                {
                    RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
                    api.KeepAlive = false;
                    api.Credentials = new NetworkCredential(username, password);
    
                    return_object = api.user_find(query, return_fields, options);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
    
                return (return_object);
            }
    
            public System.Object video_get_upload_tokens(int count, XmlRpcStruct options)
            {
                System.Object return_object = null;
    
                try
                {
                    RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
                    api.KeepAlive = false;
                    api.Credentials = new NetworkCredential(username, password);
    
                    return_object = api.video_get_upload_tokens(count, options);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
    
                return (return_object);
            }
    
            public int video_create(string token, string title, string[] keywords, int age_restriction, XmlRpcStruct options)
            {
                int return_id = -1;
    
                try
                {
                    RevverApiInterfaces api = XmlRpcProxyGen.Create<RevverApiInterfaces>();
                    api.KeepAlive = false;
                    api.Credentials = new NetworkCredential(username, password);
    
                    return_id = api.video_create(token, title, keywords, age_restriction, options);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
    
                return (return_id);
            }
        }
    }
    

    Python

    System Requirements

    The Revver API utilizes XML/RPC calls, and Python's core set of libraries already contains an XML-RPC library, nothing needs to be downloaded.

    Download

    The software samples below are provided to you free of charge, and on an “as-is” basis.

  • Download the file: RevverExamplePython.zip  (released Jun 13, 2007)
  • Description

    The following code shows how to upload content, then query the video database. The included Command Line Upload Script is useful for those using python to create a process to batch upload many files, as well as an excellent example of using the Revver API in Python.

    code

    The code sample below shows how incredibly easy it is to utilize the Revver API from within a python application. In fact, much of Revver's own site is built in python.

    import urlparse, xmlrpclib, subprocess
    import sys
    
    api_url='https://api.revver.com/xml/1.0?login=username&passwd=password'
    upload_url='http://httpupload.revver.com/'
    
    #The video to upload
    filename='test_video.mov'
    
    api = xmlrpclib.Server(api_url)
    
    #generate an upload token
    url, tokens = api.video.getUploadTokens(1)
    token = tokens[0]
    
    print 'allocated token %s' % token
    
    #use curl to upload the movie file
    upload_url = urlparse.urljoin(upload_url, token)
    retcode = subprocess.call(['curl','-F','file=@%s' % filename,'--',upload_url,])
    if retcode !=0:
        print '%s: upload failed with code %d' % retcode
        sys.exit(1)
    
    print '\nused token %s for %s' % (token, filename)
    
    #1=G,2=PG,3=PG13,4=R,5=NC17
    age_restriction=1
    title='test video'
    
    #keywords to tag the video with
    tags=['dog','ball','park']
    
    #optional data for the video, for a complete list of options see the api
    #documentation
    data = {}
    
    #credits for the media
    data['credits'] = 'dave and phil'
    
    #url associated with the video
    data['url'] = 'http://httpupload.revver.com/'
    
    #text description of the video
    data['description'] = 'My dog playing'
    
    #author of the video
    data['author'] = 'Dave'
    
    
    #create the video on revver.com
    media_id = api.video.create(token,title,tags,age_restriction,data)
    
    
    print 'created media %r from %r' % (media_id,filename)
    
    
    print "Revver API Example\n"
    
    # Example 1: returns all videos tagged "comedy"
    query1 = {"search":["comedy"]}
    
    # Example 2: returns all videos created in the last
    # 24 hours that are greater than 2 minutes long
    query2 = {"createdWithin":60*60*24,"minDuration":120}
    
    # Grab relevant information
    returnFields = ["id","title","author","url","description",
                                 "thumbnailUrl","quicktimeMediaUrl"]
    
    # Only return 10 items
    options = {"limit":10}
    results1 = api.video.find(query1,returnFields,options)
    results2 = api.video.find(query2,returnFields,options)
    
    # Show Results
    print "10 comedy videos"
    for i,rec in enumerate(results1):
        print "\n\nrecord: ", i
        for key in rec:
            print key, ": ", unicode(rec[key]).encode('utf-8','ignore')
    
    print "Videos longer than 2 minutes posted in the last 24 hours"
    for i,rec in enumerate(results2):
        print "\n\nrecord: ", i
        for key in rec:
            print key, ":", unicode(rec[key]).encode('utf-8','ignore')
    

    Java

    System Requirements

    The Revver API utilizes XML-RPC calls. The Apache XML-RPC library is required to execute the code below. The library and further documentation are availble at the Apache XML-RPC Website.

    Download

    The software samples below are provided to you free of charge, and on an “as-is” basis.

  • Download the file: RevverExampleJava.zip  (released Jun 13, 2007)
  • Description

    The following code was graciously contributed by a user of the Revver API. The code demonstrates how to use the API to retrieve video meta-data for general video queries, multiple tag matches and by collection.

    View Code

    import java.net.URL;
    import java.security.cert.X509Certificate;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import javax.net.ssl.HostnameVerifier;
    import javax.net.ssl.HttpsURLConnection;
    import javax.net.ssl.SSLContext;
    import javax.net.ssl.SSLSession;
    import javax.net.ssl.TrustManager;
    import javax.net.ssl.X509TrustManager;
    import org.apache.log4j.Logger;
    import org.apache.xmlrpc.client.XmlRpcClient;
    import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
    
    public class RevverConnector {
    
        private static final Logger log = Logger.getLogger(RevverConnector.class);
        private String username;
        private String password;
        private String api_url;
        private XmlRpcClient client;
    
        // since this is a Spring bean this method is guaranteed to be called at the startup
        public void init() {
            try {
                SSLContext sc = SSLContext.getInstance("SSL");
                sc.init(null, trustAllCerts, new java.security.SecureRandom());
                HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
                HttpsURLConnection.setDefaultHostnameVerifier(hv);
    
                XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
                //config.setEnabledForExtensions(true);
                config.setServerURL(new URL(api_url + "?login=" + username + "&passwd=" + password));
                client = new XmlRpcClient();
                client.setConfig(config);
            } catch (Exception e) {
                log.error("Error initializing Revver Connector ",e);
            }
    
        }
    
        /**
         * @param collectionId
         * @throws Exception
         *             returns Revver Clips from Revver's collection with provided
         *             collectionId
         */
        public List getClipsFromCollection(Integer collectionId) {
            List clips = new ArrayList();
            try {
                HashMap<String,Integer[]> query = new HashMap<String,Integer[]>();
                query.put("ids", new Integer[] { collectionId });
                Object[] result = (Object[]) client.execute("collection.find", new Object[] { query,
                        new String[] { "id", "name", "count", "description", "type", "subtype", "query" } });
                log.debug("result.length" + result.length);
                if (result == null || result.length == 0) // collection not found
                    return clips;
    
                HashMap results = (HashMap) result[0];
                clips.addAll(getClips((HashMap) results.get("query")));
    
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
            return clips;
    
        }
    
        public List getClipsForTags(String[] tags){
            String[][] tagsArray = {tags};
            tagsArray[0]= tags;
            HashMap<String,String[][]> query = new HashMap<String,String[][]>();
            query.put("keywords",tagsArray);
            return getClips(query);
        }
    
        public List getClips(HashMap query)  {
            List clips = new ArrayList();
            try {
                HashMap options = new HashMap();
                //options.put("limit", 300);
    
                Object[] result = (Object[]) client.execute("video.find", new Object[] { query,
                        new String[] { "id",  "title","keywords"},options });
    
                        /*new String[] { "id", "description", "title", "size", "flashMediaUrl", "quicktimeMediaUrl", "quicktimeDownloadUrl", "thumbnailUrl",
                                "status", "keywords", "rating", "views", "revenue", "affiliateId", "credits" } });
                */
    
    
                for (int i = 0; i < result.length; i++) {
                    HashMap results = (HashMap) result[i];
    
                    // iterate through results and for each result create appropriate object...
                    // for example we can create custom class that represents revver clip
                    RevverClip clip = new RevverClip();
    
                    clip.setRevverId(((Integer) results.get("id")).toString());
                    clip.setDescription((String) results.get("description"));
                    clip.setTitle((String) results.get("title"));
                    Object[] keywords = (Object[]) results.get("keywords");
                    StringBuffer keywordBuffer = new StringBuffer();
    
                    if (log.isDebugEnabled()) {
                          log.debug("---------------------------------------------- Clip " + "\n" +
                            results.get("id") + "\n" +
                            results.get("title") + "\n" +
                            results.get("size") + "\n" +
                            results.get("status") + "\n" +
                            results.get("credits") + "\n" +
                            results.get("thumbnailUrl") + "\n" +
                            results.get("views") + "\n" +
                            results.get("revenue") + "\n" +
                            results.get("affiliateId") + "\n" +
                            keywords + "\n" +
                            results.get("flashMediaUrl") + "\n" +
                            results.get("flashMediaUrl") + "\n" +
                            results.get("quicktimeMediaUrl") + "\n" +
                            results.get("quicktimeDownloadUrl") + "\n" +
                            results.get("rating") + "\n"
                        );
                    }
                    clips.add(clip);
                }
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
            return clips;
        }
    
        // Create a trust manager that does not validate certificate chains
        static TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
    
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
    
            public void checkClientTrusted(X509Certificate[] certs, String authType) {
                // Trust always
            }
    
            public void checkServerTrusted(X509Certificate[] certs, String authType) {
                // Trust always
            }
        } };
    
        static HostnameVerifier hv = new HostnameVerifier() {
            public boolean verify(String arg0, SSLSession arg1) {
                return true;
            }
        };
    
        public void setApi_url(String api_url) {
            this.api_url = api_url;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    }
    

    AppleScript

    System Requirements

    The Revver API utilizes XML/RPC calls. Apple's scripting language, "AppleScript" has built-in support for XML/RPC in versions of OS X after 10.3

    Download

    The software samples below are provided to you free of charge, and on an “as-is” basis.

  • Download the file: RevverExampleAS.zip  (released Jun 13, 2007)
  • Description

    The following code shows how easy it is to build simple scripts that access the RevverAPI on OS X. This code requests a keyword, then grabs the most popular video with that tag, and opens it in Quicktime. If you have OS X, you can run the script right from the finder, and see it in action. This is merely used as an example to show how universal the API truly can be.

    View Code

    -- Supply default tag
    set videoTag to "comedy"

    --
    --Query user for different tag.

    set dialogResult to display dialog "Enter a videoTag:" default answer videoTag
    if button returned of dialogResult is "OK" then

      set videoTag to text returned of dialogResult

        --
    Call videoSearch handler.

      
    set resultList to first item of videoSearch(videoTag)

        --
    Show result in Quicktime

      
    tell application "QuickTime Player"
        activate
          
    close movies
          
    open location (quicktimedownloadurl of resultList)
          
    set the name of window 1 of movie 1 to ("Revver: " & title of resultList)

      end tell
    end if

    on videoSearch(tag)
      -- Uber Simple VideoSearch function

      
    set query to {search:{tag}}
      
    set options to {limit:1, |orderBy|:{"views", false}, affiliate:""}
      
    set returnFields to {"id", "title", "quicktimeDownloadUrl"}
      
    set params to {query, returnFields, options}

      
    tell application "https://api.revver.com/xml/1.0?login=username&passwd=password"

        return call xmlrpc {method name:"video.find", parameters:{query, returnFields, options}}
      end tell
    end videoSearch

    Perl

    System Requirements

    The Revver API utilizes XML-RPC.
    In order to make XML-RPC calls, you must install the perl RPC::XML module. This is readily available via the CPAN archives. Check the Perldocs for a more detailed list of the methods that are avaialble.

    Download

    The software samples below are provided to you free of charge, and on an “as-is” basis.

  • There are no files to download at this time.

  • Description

    The following code utilizes Perl's object model to call "video.find" with a simple search string. The results will be returned as a hashref.

    View Code

    #!/opt/local/bin/perl -w
    use Data::Dumper;
    use RPC::XML::Client;
    use strict;
    
    my $xml;
    my $search_string = 'funny';
    my $api_url = 'https://api.revver.com/xml/1.0';
    my $api_user = 'username';
    my $api_passwd = 'password';
    
    # Perform Video Find
    my $query = {'search'=>[$search_string]};
    my $returns = ['id','title'];
    my $options = {'count'=>RPC::XML::boolean->new(1), 'limit'=>1} ;
    my $xmlrpcrequest = RPC::XML::request->new('video.find', $query, $returns, $options);
    
    #Show XML Request
    $xml = $xmlrpcrequest->as_string();
    print "XML-RPC Request: \n";
    print Dumper($xml);
    
    my $api_rpc = RPC::XML::Client->new("$api_url?login=$api_user&passwd=$api_passwd");
    my $results = $api_rpc->simple_request('video.find', $query, $returns, $options);
    
    #Show Results
    print "Results: \n";
    print Dumper($results);
    

    Special Notes

    Perl does not support boolean types natively as they are required to be sent via XML-RPC. For this reason when using booleans you must explicitly instantiate the RPC::XML::boolean class. For more information see the perldocs for RPC::XML.

    PHP

    System Requirements

    The Revver API utilizes XML-RPC calls, which require a few additional modules for out of the box support

    • PHP 4.0.2 or higher
    • PHP compiled with Curl support
    • PHP with XML/RPC support recommended, however if not present sample code will use the phpxmlrpc library to handle calls to the Revver API. This library is included in the download.

    Download

    The software samples below are provided to you free of charge, and on an “as-is” basis.

    Description

    The PHPXMLRPC library included with this sample code has been slightly modified in response to customer feedback. Certain shared hosting providers do not allow “.” characters in directory names, so the XMLRPC library directory has been renamed to xmlrpc-2_1. Each call below assumes the opening and closing PHP tags.

    View Code

    <?php
    /*
    The RevverAPI class determines which method of packaging xmlrpc requests is to be
    used, prepares and launches the method call and then returns the result as a standard
    PHP variable. It requires curl support and will use the 'XMLRPC for PHP' library if
    the built in XMLRPC functions for PHP are unavailable.
    
    PHP
    http://www.php.net/
    
    XMLRPC
    http://www.xmlrpc.com/
    
    XMLRPC for PHP
    http://www.php.net/xmlrpc
    http://phpxmlrpc.sourceforge.net/
    */
    
    class RevverAPI {
        function RevverAPI($url) {
            $this->url = $url;
            $this->curl = function_exists('curl_init');
            $this->xmlrpc = function_exists('xmlrpc_encode_request');
        }
    
        function callRemote($method) {
    // Curl is required so generate a fault if curl functions cannot be found.
            if (!$this->curl) return array('faultCode' => -1, 'faultString' => 'Curl functions are unavailable.');
    // The first argument will always be the method name while all remaining arguments need
    // to be passed along with the call.
            $args = func_get_args();
            array_shift($args);
            if ($this->xmlrpc) {
    // If php has xmlrpc support use the built in functions.
                $request = xmlrpc_encode_request($method, $args);
                $result = $this->__xmlrpc_call($request);
                $decodedResult = xmlrpc_decode($result);
            } else {
    // If no xmlrpc support is found, use the phpxmlrpc library. This involves containing
    // all variables inside the xmlrpcval class.
                $encapArgs = array();
                foreach ($args as $arg) $encapArgs[] = $this->__phpxmlrpc_encapsulate($arg);
                $msg = new xmlrpcmsg($method, $encapArgs);
                $client = new xmlrpc_client($this->url);
                $client->verifypeer = false;
                $result = $client->send($msg);
                if ($result->errno) {
                    $decodedResult = array('faultCode' => $result->errno, 'faultString' => $result->errstr);
                } else {
                    $decodedResult = php_xmlrpc_decode($result->value());
                }
            }
            return $decodedResult;
        }
    
        function __phpxmlrpc_encapsulate($arg) {
    // The class xmlrpcval is defined in the phpxmlrpc library. It requires both the variable
    // and the type. Dates are handled through the API as ISO 8601 string representations.
            if (is_string($arg)) {
                $encapArg = new xmlrpcval($arg, 'string');
            } elseif (is_int($arg)) {
                $encapArg = new xmlrpcval($arg, 'int');
            } elseif (is_bool($arg)) {
                $encapArg = new xmlrpcval($arg, 'boolean');
            } elseif (is_array($arg)) {
    // The API server treats indexed arrays (lists) and associative arrays (dictionaries)
    // differently where in php they are essentially the same. Assuming that having a zero
    // index set indicates an indexed array is not perfect but should suffice for the
    // purpose of the API examples.
                if (isset($arg[0])) {
                    $array = array();
                    foreach ($arg as $key => $value) {
                        $array[] = $this->__phpxmlrpc_encapsulate($value);
                    }
                    $encapArray = new xmlrpcval();
                    $encapArray->addArray($array);
                    $encapArg = $encapArray;
                } else {
                    $struct = array();
                    foreach ($arg as $key => $value) {
                        $struct[$key] = $this->__phpxmlrpc_encapsulate($value);
                    }
                    $encapStruct = new xmlrpcval();
                    $encapStruct->addStruct($struct);
                    $encapArg = $encapStruct;
                }
            } else {
                $encapArg = new xmlrpcval($arg, 'string');
            }
    
            return $encapArg;
        }
    
        function __xmlrpc_call($request) {
            $header[] = "Content-type: text/xml";
            $header[] = "Content-length: ".strlen($request);
    
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $this->url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    
            $data = curl_exec($ch);
            if (curl_errno($ch)) {
    // Curl errors are returned as emulated xmlrpc faults.
                $errorCurl = curl_error($ch);
                curl_close($ch);
                return xmlrpc_encode(array('faultCode' => -1, 'faultString' => 'Curl Error : '.$errorCurl));
            } else {
                curl_close($ch);
                return $data;
            }
        }
    
    }
    
    
    /*
    user.create
    Attempt to create a new user with a login name of longjohn and the provided details.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $login = 'longjohn';
    $options = array(
        'password' => 'avast888',
        'email' => 'longjohn@example.net',
        'paypal' => 'longjohn@example.com',
        'allowBroadcast' => true,
        'allowMobile' => false
    );
    
    $results = $api->callRemote('user.create', $login, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    user.find
    Return the login, email address, paypal address and balance details of the first 10
    active users.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $query = array('statuses' => array('active'));
    $return = array('login', 'email', 'paypal', 'balance');
    $options = array('limit' => 10, 'offset' => 0);
    
    $results = $api->callRemote('user.find', $query, $return, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    user.count
    Determine how many active users exist.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $query = array('statuses' => array('active'));
    
    $results = $api->callRemote('user.count', $query);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    user.authenticate
    Determine if the user blackbeard with a password of avast888 is valid.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $username = 'blackbeard';
    $password = 'avast888';
    
    $results = $api->callRemote('user.authenticate', $username, $password);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    user.update
    Update the email address of the user longjohn to longjohn@arrmail.com.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $login = 'longjohn';
    $options = array('email' => 'longjohn@arrmail.com');
    
    $results = $api->callRemote('user.update', $login, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    user.delete
    Delete the users longjohn and davyjones.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $logins = array('longjohn', 'davyjones');
    
    $results = $api->callRemote('user.delete', $logins);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    collection.create
    Create a video collection called 'Parrots of the World' that is owned by blackbeard.
    Include in this collection all videos tagged with the keyword parrot.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $type = 'video';
    $name = 'Parrots of the World';
    $query = array('keywords' => array('parrot'));
    $options = array('owner' => 'blackbeard');
    
    $results = $api->callRemote('collection.create', $type, $name, $query, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    collection.update
    Change the name of collection 5777 to 'Monkeys of the World' and change the
    collection query to videos tagged with the keywords monkey or chimp.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $id = 5777;
    $collection = array(
        'name' => 'Monkeys of the World',
        'query' => array('keywords' => array('monkey', 'chimp'))
    );
    
    $results = $api->callRemote('collection.update', $id, $collection);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    collection.delete
    Delete collections 5777, 5787 and 5798.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $ids = array(5777, 5787, 5798);
    
    $results = $api->callRemote('collection.delete', $ids);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    collection.find
    Return the id, owner, name and type of the first 10 video collections.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $query = array('types' => array('video'));
    $return = array('id', 'owner', 'name', 'type');
    $options = array('limit' => 10);
    
    $results = $api->callRemote('collection.find', $query, $return, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    collection.collect
    Return the id, title and thumbnail image url of all videos in collection 5366.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $id = 5366;
    $return = array('id', 'title', 'thumbnailUrl');
    
    $results = $api->callRemote('collection.collect', $id, $return);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    video.find
    Return the id, title and thumbnail url of the 10 most viewed videos owned by
    longjohn that contain the word parrot in their metadata.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $query = array('owners' => array('longjohn'), 'search' => array('parrot'));
    $return = array('id', 'title', 'thumbnailUrl');
    $options = array('limit' => 10, 'orderBy' => array('views', true));
    
    $results = $api->callRemote('video.find', $query, $return, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    video.getUploadTokens
    Return 1 upload token for a new video to be owned by blackbeard.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $count = 1;
    $options = array('owner' => 'blackbeard');
    
    $results = $api->callRemote('video.getUploadTokens', $count, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    video.create
    Create the metadata for video 65535.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $id = 65535;
    $title = 'My New Parrot';
    $keywords = array('parrot', 'pet');
    $ageRestriction = 1;
    $options = array('url' => 'arrvideos.example.com', 'author' => 'Billy Doyle');
    
    $results = $api->callRemote('video.create', $id, $title, $keywords,
    $ageRestriction, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    video.count
    Determine how many videos owned by longjohn contain the word parrot in the metadata.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $query = array('owners' => array('longjohn'), 'search' => array('parrot'));
    
    $results = $api->callRemote('video.count', $query);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    video.rate
    Set the rating of video 65535 to 4.5 for the identified client.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $id = 65535;
    $client = '192.0.0.1';
    $rating = 4.5;
    
    $results = $api->callRemote('video.rate', $id, $client, $rating);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    /*
    video.update
    Update the metadata for video 65535 to include parrot, pet and galah as the keywords.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $id = 65535;
    $options = array('keywords' => array('parrot', 'pet', 'galah'));
    
    $results = $api->callRemote('video.update', $id, $options);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    
    video.delete
    Delete videos 65535, 65808 and 66002.
    */
    
    include('xmlrpc-2_1/lib/xmlrpc.inc');
    include('class.RevverAPI.php');
    
    $api = new RevverAPI('https://api.staging.revver.com/xml/1.0?login=revtester&#038;passwd=testacct');
    
    $ids = array(65535, 65808, 66002);
    
    $results = $api->callRemote('video.delete', $ids);
    
    echo '<pre>';
    var_dump($results);
    echo '</pre>';
    ?>