8000 GitHub - Shwetakale/databasedotcom-streaming
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Shwetakale/databasedotcom-streaming

 
 

Repository files navigation

What is databasedotcom-streaming?

This gem is an extension of the databasedotcom gem that makes it simple and convenient to consume the salesforce.com Streaming API in Ruby. It relies on the excellent Faye to subscribe to Salesforce's streaming servers and execute evented callbacks without introducing blocks in your code.

Notes

  • The only prerequisites for using the gem are to have it present in your system and to require it in your project. If you are already using the databasedotcom gem, this gem will integrate seamlessly with what you are already using.
  • This gem currently relies on eventmachine to run, so you're streaming code must be run from within an EventMachine block. If you are using an event based server like Thin, then you are all set.
  • If you are using OAuth, be sure to include a refresh token when authenticating ... otherwise the stream will stop working when the access token expires.

Usage

Use the 'subscribe_to_push_topic' method to listen to a streaming channel and pass a topic name and callback as arguments. Whenever the stream has new information to publish, it will call your callback and pass it an argument representing the new message in the form of a hash.

Setup

require "databasedotcom-streaming"

client = Databasedotcom::Client.new
client.authenticate(:token => my-access-token, :instance_url => my-instance-url, :refresh_token => my-refresh-token)  

Subscribe

EM.run{
  client.subscribe_to_push_topic('MyStreamingTopic'){ |message| puts message.inspect }
}

or

EM.run{
  client.subscribe_to_push_topic('MyStreamingTopic') do |message|
    # my block of code
    # goes here
    # and here
  end
}

See your push topics

client.materialize 'PushTopic'
all_push_topics = PushTopic.all
puts all_push_topics.to_yaml

Create a new topic

topic_attrs = {
  :query => 'SELECT Id, Name FROM Lead WHERE Source = \'Web\'' # All inbound leads that come from the web 
  :name  => 'WebLeads'
}

client.create('PushTopic', topic_attrs)

Possible Uses

  • A message queue backed in Databasedotcom
  • A service that pre caches data from Force.com into a local db or datastore
  • Push Notifications (Desktop, Mobile)

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%
0