Icontem

Using the webfanIntents API - µ.Flow package blog

Recommend this page to a friend!
  All package blogs All package blogs   µ.Flow µ.Flow   Blog µ.Flow package blog   RSS 1.0 feed RSS 2.0 feed   Blog Using the webfanInten...  
  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  

Author: Till Wehowski

Posted on:

Package: µ.Flow

With "webfanIntents" it is possible to delegate an "action" to an arbitrary 3rd party applications implementing the spec while server, client and API does not know of each other.




Read more about the specification...

Quick Usage Example:

First include the library on client and server side:
<script type="text/javascript" src="http://api.webfan.de/api-d/4/js-api/library.js"></script>
On the client regsiter an intent and start an Activity (by button click):
<intent
 action="http://webintents.org/pick"
 type="application/vnd.frdl.webfan.client.sdk+json"
 title="My SDK Client" 
 disposition="new"
 icon="favicon.ico" 
 href="?intents=1"
/>

<button onclick="
 window.navigator.startActivity( new Intent(
  'http://webintents.org/pick',
  'application/vnd.frdl.webfan.client.sdk+json' ,
  { 'API_CLIENT_URL' : frdl.route( 'API_CLIENT_URL' ),
    'title' : 'Webfan API SDK Client'
  }
            
 ), 
 function (data) {
  if( 200 !== parseInt(data.code) ) {
   alert( 'The service application throws an error:  ' + ( data.error || null).toString() );
  } else {
   if(!!data.message)alert(data.message.toString())
  }
 }); 
"
>
Test start webfanIntents activity with demo data...
</button>

On the server side include in your head section:
<script type="text/javascript" src = "http://webfan.de/cdn/frdl/flow/components/webfan/webfat/js/intents.js"></script>
Register and run and Service for an Action with a given mime-type:
<div ui-view="mainView"></div>
<script>
 var API_CLIENT_URL;

 frdl.when( function() { return ('undefined' !== typeof frdl.frdl$intentService ); },
 function(){
  frdl.frdl$intentService.register( 'application/vnd.frdl.webfan.client.sdk+json', 'http://webintents.org/pick', 
 function(_intent){
  API_CLIENT_URL = _intent.data.API_CLIENT_URL; 
  var r = {
   code : 200,
   replyTo : _intent._id,
   message : 'Your Client was picked! ' + "\n" + API_CLIENT_URL  + "\n"+' by '  + "\n"+ new frdl.Url().urlMakeNew(),
   error : null,
   data : {
		              	
   }
  }; 
       	           
  $('*[ui-view="mainView"]')
   .html(''
   + '<section class="console-screen">'
   +'  frdl://webfanIntents/' + 'application/' + 'vnd.frdl.webfan.client.sdk+json' + '/http://webintents.org/pick  > '+"\n"
   +' sendResponse > '+"\n"
   +  JSON.stringify(r)+"\n"
   +'</section>');
  return r;   	
 }, 
 { describe: 'config data' }, { describe: 'server data'})
  .run()  
  ;
 },
    		   
 { describe: 'callback argument' }, 
  function( _intent ){ console.log( 'Failed to register action server' );},
  1);
</script>


You need to be a registered user or login to post a comment

20,369 JavaScript developers registered to the JS Classes site.
Be One of Us!

Login Immediately with your account on:

FacebookGmail
HotmailStackOverflow
GitHubYahoo


Comments:

No comments were submitted yet.




  Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  
  All package blogs All package blogs   µ.Flow µ.Flow   Blog µ.Flow package blog   RSS 1.0 feed RSS 2.0 feed   Blog Using the webfanInten...