Yammer
Available as of Camel
...
2.12
...
The
...
Yammer
...
component
...
allows
...
you
...
to
...
interact
...
with
...
the
...
...
enterprise
...
social
...
network.
...
Consuming
...
messages,
...
users,
...
and
...
user
...
relationships
...
is
...
supported
...
as
...
well
...
as
...
creating
...
new
...
messages.
...
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
...
https://developer.yammer.com/v1.0/docs/authentication
...
Maven
...
users
...
will
...
need
...
to
...
add
...
the
...
following
...
dependency
...
to
...
their
...
pom.xml
...
for
...
this
...
component:
Code Block | ||||
---|---|---|---|---|
| ||||
{code:xml} <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-yammer</artifactId> <version>${camel-version}</version> </dependency> {code} h3. URI format |
URI format
Code Block |
---|
{code} yammer:[function]?[options] {code} h3. YammerComponent 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. {div:class=confluenceTableSmall} || Option || Description || | consumerKey | The consumer key | | consumerSecret | The consumer secret | | accessToken | The access token | {div} h3. Consuming messages The camel-yammer component provides several endpoints for consuming messages: {div:class=confluenceTableSmall} || URI || Description || | {code} |
YammerComponent
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.
Div | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
|
Consuming messages
The camel-yammer component provides several endpoints for consuming messages:
Div | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
URI Options for consuming messages
Div | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||
|
Message format
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
...
&
...
producing
...
endpoints,
...
a
...
Messages
...
object
...
is
...
returned.
...
Take
...
for
...
example
...
a
...
route
...
like:
Code Block |
---|
{code} from("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken").to("mock:result"); {code} |
and
...
lets
...
say
...
the
...
yammer
...
server
...
returns:
Code Block |
---|
{code} { "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":[ ] } } ] } {code} |
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:
Code Block |
---|
{code} 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()); {code} |
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.
...
Creating
...
messages
...
To
...
create
...
a
...
new
...
message
...
in
...
the
...
account
...
of
...
the
...
current
...
user,
...
you
...
can
...
use
...
the
...
following
...
URI:
Code Block |
---|
{code} yammer:messages?[options] {code} |
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).
...
Take
...
this
...
route
...
for
...
instance:
Code Block |
---|
{code} from("direct:start").to("yammer:messages?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken").to("mock:result"); {code} |
By
...
sending
...
to
...
the
...
direct:start
...
endpoint
...
a
...
"Hi
...
from
...
Camel!"
...
message
...
body:
Code Block |
---|
{code} template.sendBody("direct:start", "Hi from Camel!"); {code} |
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:
Code Block |
---|
{code} 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()); {code} h3. Retrieving user relationships The |
Retrieving user relationships
The camel-yammer
...
component
...
can
...
retrieve
...
user
...
relationships:
Code Block |
---|
{code} yammer:relationships?[options] {code} h4. URI Options for retrieving relationships {div:class=confluenceTableSmall} || Name || Default Value || Description || | useJson | {{false}} | Set to true if you want to use raw JSON rather than converting to POJOs. | | delay | {{5000}} | in milliseconds | | consumerKey | {{null}} | Consumer Key. Can also be configured on the {{YammerComponent}} level instead. | | consumerSecret | {{null}} | Consumer Secret. Can also be configured on the {{YammerComponent}} level instead. | | accessToken | {{null}} | Access Token. Can also be configured on the {{YammerComponent}} level instead. | | userId | {{current user}} | To view the relationships for a user other than the current user. | {div} h3. Retrieving users The camel-yammer component provides several endpoints for retrieving users: {div:class=confluenceTableSmall} || URI || Description || | {code}yammer:users?[options]{code} | Retrieve users in the current user's Yammer network. | | {code}yammer:current?[options]{code} | View data about the current user. | {div} h4. URI Options for retrieving users {div:class=confluenceTableSmall} || Name || Default Value || Description || | useJson | {{false}} | Set to true if you want to use raw JSON rather than converting to POJOs. | | delay | {{5000}} | in milliseconds | | consumerKey | {{null}} | Consumer Key. Can also be configured on the {{YammerComponent}} level instead. | | consumerSecret | {{null}} | Consumer Secret. Can also be configured on the {{YammerComponent}} level instead. | | accessToken | {{null}} | Access Token. Can also be configured on the {{YammerComponent}} level instead. | {div} h3. Using an enricher 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. 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: {code} |
URI Options for retrieving relationships
Div | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||
|
Retrieving users
The camel-yammer component provides several endpoints for retrieving users:
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
|
URI Options for retrieving users
Div | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||
|
Using an enricher
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.
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:
Code Block |
---|
from("direct:start").pollEnrich("yammer:current?consumerKey=aConsumerKey&consumerSecret=aConsumerSecretKey&accessToken=aAccessToken").to("mock:result");
{code}
This will go out and fetch the current |
This will go out and fetch the current user's
...
User
...
object
...
and
...
set
...
it
...
as
...
the
...
Camel
...
message
...
body.
...
Include Page | ||||
---|---|---|---|---|
|