camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonathan Anstey (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > Yammer
Date Thu, 05 Sep 2013 15:33:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Yammer">Yammer</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~janstey">Jonathan
Anstey</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {code}yammer:sent?[options]{code}
| All messages sent by the user. |  <br>| {code}yammer:private?[options]{code} | Private
messages received by the user. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {code}yammer:received?[options]{code}
| <span class="diff-added-words"style="background-color: #dfd;">*Camel 2.12.1:*</span>
All messages received by the user | <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Yammer-Yammer"></a>Yammer</h2>
<p><b>Available as of Camel 2.12</b></p>

<p>The Yammer component allows you to interact with the <a href="https://www.yammer.com"
class="external-link" rel="nofollow">Yammer</a> enterprise social network. Consuming
messages, users, and user relationships is supported as well as creating new messages.</p>

<p>Yammer uses OAuth 2 for all client application authentication.  In order to use camel-yammer
with your account, you'll need to create a new application within Yammer and grant the application
access to your account. Finally, generate your access token. More details are at <a href="https://developer.yammer.com/authentication/"
class="external-link" rel="nofollow">https://developer.yammer.com/authentication/</a></p>

<p>Maven users will need to add the following dependency to their pom.xml for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
    &lt;artifactId&gt;camel-yammer&lt;/artifactId&gt;
    &lt;version&gt;${camel-version}&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>

<h3><a name="Yammer-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
yammer:[function]?[options]
</pre>
</div></div>

<h3><a name="Yammer-YammerComponent"></a>YammerComponent</h3>

<p>The yammer component can be configured with the Yammer account settings which are
mandatory to configure before using. You can also configure these options directly in the
endpoint.</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> consumerKey </td>
<td class='confluenceTd'> The consumer key </td>
</tr>
<tr>
<td class='confluenceTd'> consumerSecret </td>
<td class='confluenceTd'> The consumer secret </td>
</tr>
<tr>
<td class='confluenceTd'> accessToken </td>
<td class='confluenceTd'> The access token </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Yammer-Consumingmessages"></a>Consuming messages</h3>

<p>The camel-yammer component provides several endpoints for consuming messages:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> URI </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:messages?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> All public messages in the user's (whose access token is being
used to make the API call) Yammer network. Corresponds to "All" conversations in the Yammer
web interface. </td>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:my_feed?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> The user's feed, based on the selection they have made between
"Following" and "Top" conversations. </td>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:algo?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> The algorithmic feed for the user that corresponds to "Top"
conversations, which is what the vast majority of users will see in the Yammer web interface.
</td>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:following?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> The "Following" feed which is conversations involving people,
groups and topics that the user is following. </td>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:sent?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> All messages sent by the user. </td>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:private?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> Private messages received by the user. </td>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:received?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> <b>Camel 2.12.1:</b> All messages received by
the user </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="Yammer-URIOptionsforconsumingmessages"></a>URI Options for
consuming messages</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> useJson </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to true if you want to use raw JSON rather than converting
to POJOs. </td>
</tr>
<tr>
<td class='confluenceTd'> delay </td>
<td class='confluenceTd'> <tt>5000</tt> </td>
<td class='confluenceTd'> in milliseconds </td>
</tr>
<tr>
<td class='confluenceTd'> consumerKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Key. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> consumerSecret </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Secret. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> accessToken </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Access Token. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> limit </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> Return only the specified number of messages. Works for threaded=true
and threaded=extended. </td>
</tr>
<tr>
<td class='confluenceTd'> threaded </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> threaded=true will only return the first message in each thread.
This parameter is intended for apps which display message threads collapsed. threaded=extended
will return the thread starter messages in order of most recently active as well as the two
most recent messages, as they are viewed in the default view on the Yammer web interface.
</td>
</tr>
<tr>
<td class='confluenceTd'> olderThan </td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> Returns messages older than the message ID specified as a
numeric string. This is useful for paginating messages. For example, if you're currently viewing
20 messages and the oldest is number 2912, you could append "?olderThan=2912″ to your request
to get the 20 messages prior to those you're seeing. </td>
</tr>
<tr>
<td class='confluenceTd'> newerThan</td>
<td class='confluenceTd'> <tt>-1</tt> </td>
<td class='confluenceTd'> Returns messages newer than the message ID specified as a
numeric string. This should be used when polling for new messages. If you're looking at messages,
and the most recent message returned is 3516, you can make a request with the parameter "?newerThan=3516″
to ensure that you do not get duplicate copies of messages already on your page. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="Yammer-Messageformat"></a>Message format</h4>

<p>All messages by default are converted to a POJO model provided in the org.apache.camel.component.yammer.model
package. The original message coming from yammer is in JSON. For all message consuming &amp;
producing endpoints, a Messages object is returned. Take for example a route like:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("yammer:messages?consumerKey=aConsumerKey&amp;consumerSecret=aConsumerSecretKey&amp;accessToken=aAccessToken").to("mock:result");
</pre>
</div></div>

<p>and lets say the yammer server returns:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
{
	"messages":[
		{
			"replied_to_id":null,
			"network_id":7654,
			"url":"https://www.yammer.com/api/v1/messages/305298242",
			"thread_id":305298242,
			"id":305298242,
			"message_type":"update",
			"chat_client_sequence":null,
			"body":{
				"parsed":"Testing yammer API...",
				"plain":"Testing yammer API...",
				"rich":"Testing yammer API..."
			},
			"client_url":"https://www.yammer.com/",
			"content_excerpt":"Testing yammer API...",
			"created_at":"2013/06/25 18:14:45 +0000",
			"client_type":"Web",
			"privacy":"public",
			"sender_type":"user",
			"liked_by":{
				"count":1,
				"names":[
					{
						"permalink":"janstey",
						"full_name":"Jonathan Anstey",
						"user_id":1499642294
					}
					
				]
				
			},
			"sender_id":1499642294,
			"language":null,
			"system_message":false,
			"attachments":[
				
			],
			"direct_message":false,
			"web_url":"https://www.yammer.com/redhat.com/messages/305298242"
		},
		{
			"replied_to_id":null,
			"network_id":7654,
			"url":"https://www.yammer.com/api/v1/messages/294326302",
			"thread_id":294326302,
			"id":294326302,
			"message_type":"system",
			"chat_client_sequence":null,
			"body":{
				"parsed":"(Principal Software Engineer) has [[tag:14658]] the redhat.com network. Take
a moment to welcome Jonathan.",
				"plain":"(Principal Software Engineer) has #joined the redhat.com network. Take a moment
to welcome Jonathan.",
				"rich":"(Principal Software Engineer) has #joined the redhat.com network. Take a moment
to welcome Jonathan."
			},
			"client_url":"https://www.yammer.com/",
			"content_excerpt":"(Principal Software Engineer) has #joined the redhat.com network. Take
a moment to welcome Jonathan.",
			"created_at":"2013/05/10 19:08:29 +0000",
			"client_type":"Web",
			"sender_type":"user",
			"privacy":"public",
			"liked_by":{
				"count":0,
				"names":[
					
				]
				
			}
		}	
		]
		
	}
</pre>
</div></div>

<p>Camel will marshal that into a Messages object containing 2 Message objects. As shown
below there is a rich object model that makes it easy to get any information you need:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
        Exchange exchange = mock.getExchanges().get(0);
        Messages messages = exchange.getIn().getBody(Messages.class);

        assertEquals(2, messages.getMessages().size());
        assertEquals("Testing yammer API...", messages.getMessages().get(0).getBody().getPlain());
        assertEquals("(Principal Software Engineer) has #joined the redhat.com network. Take
a moment to welcome Jonathan.", messages.getMessages().get(1).getBody().getPlain());
</pre>
</div></div>

<p>That said, marshaling this data into POJOs is not free so if you need you can switch
back to using pure JSON by adding the useJson=false option to your URI.</p>

<h3><a name="Yammer-Creatingmessages"></a>Creating messages</h3>

<p>To create a new message in the account of the current user, you can use the following
URI:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
yammer:messages?[options]
</pre>
</div></div>

<p>The current Camel message body is what will be used to set the text of the Yammer
message. The response body will include the new message formatted the same way as when you
consume messages (i.e. as a Messages object by default). </p>

<p>Take this route for instance:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("direct:start").to("yammer:messages?consumerKey=aConsumerKey&amp;consumerSecret=aConsumerSecretKey&amp;accessToken=aAccessToken").to("mock:result");
</pre>
</div></div>

<p>By sending to the direct:start endpoint a "Hi from Camel!" message body:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
        template.sendBody("direct:start", "Hi from Camel!");
</pre>
</div></div>

<p>a new message will be created in the current user's account on the server and also
this new message will be returned to Camel and converted into a Messages object. Like when
consuming messages you can interrogate the Messages object:     </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">        
        Exchange exchange = mock.getExchanges().get(0);
        Messages messages = exchange.getIn().getBody(Messages.class);

        assertEquals(1, messages.getMessages().size());
        assertEquals("Hi from Camel!", messages.getMessages().get(0).getBody().getPlain());
       
</pre>
</div></div>        

<h3><a name="Yammer-Retrievinguserrelationships"></a>Retrieving user relationships</h3>

<p>The camel-yammer component can retrieve user relationships:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
yammer:relationships?[options]
</pre>
</div></div>

<h4><a name="Yammer-URIOptionsforretrievingrelationships"></a>URI Options
for retrieving relationships</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> useJson </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to true if you want to use raw JSON rather than converting
to POJOs. </td>
</tr>
<tr>
<td class='confluenceTd'> delay </td>
<td class='confluenceTd'> <tt>5000</tt> </td>
<td class='confluenceTd'> in milliseconds </td>
</tr>
<tr>
<td class='confluenceTd'> consumerKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Key. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> consumerSecret </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Secret. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> accessToken </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Access Token. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> userId </td>
<td class='confluenceTd'> <tt>current user</tt> </td>
<td class='confluenceTd'> To view the relationships for a user other than the current
user. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Yammer-Retrievingusers"></a>Retrieving users</h3>

<p>The camel-yammer component provides several endpoints for retrieving users:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> URI </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:users?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> Retrieve users in the current user's Yammer network. </td>
</tr>
<tr>
<td class='confluenceTd'> <div class="code panel" style="border-width: 1px;"><div
class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">yammer:current?[options]</pre>
</div></div> </td>
<td class='confluenceTd'> View data about the current user. </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="Yammer-URIOptionsforretrievingusers"></a>URI Options for retrieving
users</h4>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> useJson </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to true if you want to use raw JSON rather than converting
to POJOs. </td>
</tr>
<tr>
<td class='confluenceTd'> delay </td>
<td class='confluenceTd'> <tt>5000</tt> </td>
<td class='confluenceTd'> in milliseconds </td>
</tr>
<tr>
<td class='confluenceTd'> consumerKey </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Key. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> consumerSecret </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Consumer Secret. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
<tr>
<td class='confluenceTd'> accessToken </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Access Token. Can also be configured on the <tt>YammerComponent</tt>
level instead. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Yammer-Usinganenricher"></a>Using an enricher</h3>

<p>It is helpful sometimes (or maybe always in the case of users or relationship consumers)
to use an enricher pattern rather than a route initiated with one of the polling consumers
in camel-yammer. This is because the consumers will fire repeatedly, however often you set
the delay for. If you just want to look up a user's data, or grab a message at a point in
time, it is better to call that consumer once and then get one with your route. </p>

<p>Lets say you have a route that at some point needs to go out and fetch user data
for the current user. Rather than polling for this user over and over again, use the pollEnrich
DSL method:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("direct:start").pollEnrich("yammer:current?consumerKey=aConsumerKey&amp;consumerSecret=aConsumerSecretKey&amp;accessToken=aAccessToken").to("mock:result");
</pre>
</div></div>

<p>This will go out and fetch the current user's User object and set it as the Camel
message body.        </p>

<h3><a name="Yammer-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Yammer">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=33294177&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Yammer?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message