Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Disclaimer: I have no idea how the Panda Video Converter works, this is just an example of using <code>RequestBuilder</code> to make GET and POST requests to a server.</p> <p>The steps to accomplish this seem to be roughly:</p> <ol> <li>Send a POST to <code>hq.pandastream.com/videos.(yaml|xml)</code> with your account ID as a parameter.</li> <li>Receive a response including the ID of the new video you've created (a placeholder)</li> <li>Display a form to the user based on the ID. The form is retrieved by sending a GET to <code>upload.pandastream.com/videos/[id]/form</code></li> <li>Submitting this form uploads the video, whose information can be retrieved by sending a GET to <code>GET hq.pandastream.com/videos/id.(yaml|xml)</code></li> </ol> <p>Since the only elements of this process are POST and GET requests, you can use the <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/http/client/RequestBuilder.html" rel="nofollow noreferrer">RequestBuilder</a> to make these requests for you in GWT.</p> <p>We'll go through step by step.</p> <p>Send a POST to <code>hq.pandastream.com/videos.xml</code> with your account ID as a parameter.</p> <pre><code>RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://hq.pandastream.com/videos.xml"); rb.sendRequest("account_key=foo", new RequestCallback() { protected void onResponseReceived(Request request, Response, response) { // parse XML to get "id" element } // onError() ... }); </code></pre> <p>Now that you have the ID, you can make another request to get the upload form HTML.</p> <pre><code>rb = new RequestBuilder(RequestBuilder.GET, "http://upload.pandastream.com/videos/" + id + "/form"); rb.sendRequest(null, new RequestCallback() { protected void onResponseReceived(Request request, Response, response) { // this may not work, and it may be a bad idea to inject third-party HTML // straight into your page. You might also want to open a popup window // instead of injecting the HTML directly. someWidget.setHTML(response.getText()); } // onError() ... }); </code></pre> <p>With that form, the user uploads the video, etc.</p> <p>Now, to get info about the video, it's -- you guessed it -- another <code>RequestBuilder</code> call.</p> <pre><code>rb = new RequestBuilder(RequestBuilder.GET, "http://hq.pandastream.com/videos/" + id + ".xml"); rb.sendRequest(null, new RequestCallback() { protected void onResponseReceived(Request request, Response, response) { // parse response XML to get info you want } // onError() ... }); </code></pre> <p>Another disclaimer: This is a <em>very</em> rough outline of what <em>appears</em> to be the process of uploading a video, based on the docs you linked. This just serves as a basic example of using <code>RequestBuilder</code> to make GET/POST calls.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload