Changes between Version 1 and Version 2 of ObserverTutorial/Output

Show
Ignore:
Timestamp:
06/21/10 16:42:25 (3 years ago)
Author:
jean-gui
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ObserverTutorial/Output

    v1 v2  
     1= Adapting calculator's output = 
     2For a web service to be able to send results back to Unicorn, it needs to implement a specific format called an observation response. Basically, this is an XML document listing all the messages (errors, warnings and information) that the web service produced. 
     3 
     4The following code shows how such a response would look like for the calculator. It contains two normal messages and an error. As you can see, each message has a type (info, warn, error), a context (optional) and a title. In our case, the context contains the arithmetic expression and the title contains the corresponding result. Each message element can have more data, like a longer text, an associated group, ... As you can see, there's also a status which is used to express if the test succeeded or failed. For a detailed description of this format check out its dedicated documentation. 
     5 
    16{{{ 
    27#!xml 
     
    2227 
    2328}}} 
     29So, back to our calculator, we already have our results in an array and errors in another one, so it's easy to turn them into a Unicorn response: 
     30 
    2431{{{ 
    2532#!xml 
     
    4350<?php endforeach ?> 
    4451</observationresponse> 
     52}}} 
     53Finally, we add it to the list of supported outputs in our main PHP script: 
    4554 
     55{{{ 
     56#!php 
     57$valid_formats[] = 'ucn'; 
    4658}}} 
     59Et voilà, we can now call the calculator with the parameter output=ucn to get results in Unicorn format. 
     60 
     61The [wiki:ObserverTutorial/Contract last step] as an observer developper will be to tell Unicorn how it can contact the service and which parameters to use. This is what we call the contract.