SlideShare a Scribd company logo
Consuming the Twitter Streaming API
                           with Ruby and MongoDB

                                      Jeff Linwood
                             Lone Star Ruby Conference V
                                     August 12, 2011
                              http://www.jefflinwood.com
                                      @jefflinwood




Friday, August 12, 2011
Goals

                  • Watch for any
                          tweet that contains
                          certain keywords
                  • Store those tweets
                          into the MongoDB
                          database



Friday, August 12, 2011
Demo (@aplusk)




Friday, August 12, 2011
Twitter Streaming API+
                         Mongo DB

                     • Twitter Streaming API
                     • MongoDB
                     • Not a web application


Friday, August 12, 2011
The many APIs of
                              Twitter
                     • Twitter Streaming API
                     • User Streams
                     • Site Streams (for the big boys)
                     • REST API
                     • Search API

Friday, August 12, 2011
Twitter Streaming API

                     • Keywords
                     • Users
                     • Locations
                                                                Great photo is by rachel_thecat
                                      http://www.flickr.com/photos/23209605@N00/2786126623/




Friday, August 12, 2011
TweetStream gem
                          by Michael Bleigh
                          https://github.com/intridea/tweetstream




Friday, August 12, 2011
Connecting to the
                          Twitter Streaming API
                     • JSON responses
                     • HTTP Basic Authentication
                     • One stream per account (dev/prod)
                     • Leave it open!
                     • Don’t constantly reconnect, and if you do,
                          back off


Friday, August 12, 2011
Limitations of Twitter
                             Streaming API
                     • 400 Keywords
                     • 5,000 User Ids
                     • 25 Location Boxes
                     • Can ask Twitter for increased access

Friday, August 12, 2011
A Tweet, in JSON




Friday, August 12, 2011
Intro to MongoDB

                     • NoSQL - what does that mean?
                     • Great fit for JSON-oriented applications
                     • If you don’t know your schema in advance
                     • Query language
                     • Map Reduce

Friday, August 12, 2011
Storing data in MongoDB

                     • Native format of MongoDB is BSON,
                          similar to JSON
                     • Connect to a database (similar to MySQL)
                     • Connect to a collection (created if it
                          doesn’t exist)
                     • Insert JSON (in our case, a tweet)

Friday, August 12, 2011
MongoDB + Ruby

                     • mongo gem
                     • bson_ext gem
                     • http://www.mongodb.org/display/DOCS/
                          Ruby+Language+Center




Friday, August 12, 2011
Considerations for
                                MongoDB
                     • Tweets - very verbose JSON
                     • Date format in Tweets not same as
                          MongoDB
                     • May want to pre-process Tweets
                     • Can use both MongoDB and MySQL in
                          same app if you want


Friday, August 12, 2011
Here’s the code


                     • Okay, the whole thing is really done in
                          about three lines.




Friday, August 12, 2011
Where do you run this?

                     • Command line
                     • Your own server
                     • Heroku + MongoLab
                     • Other cloud services

Friday, August 12, 2011
MongoLab




Friday, August 12, 2011
Now what?

                     • Step 1: Collect Tweets
                     • Step 2: ????
                     • Step 3: Profit!

Friday, August 12, 2011
To Learn More
                     • https://dev.twitter.com/docs/streaming-api/
                          concepts
                     • http://www.mongodb.org/
                     • https://github.com/jefflinwood/Tweeter-
                          Keeper
                     • http://www.jefflinwood.com/
                     • @jefflinwood on Twitter
Friday, August 12, 2011

More Related Content

PDF
Vex@demo camp stuttgart_2010-11-23
PDF
I love json module
PDF
Extending rails
PDF
Intro to Micro-frameworks
PDF
Using source control for domino development - AUSLUG 2016
PDF
Anatomy of a UI Control - Extension Library Case Study
PDF
Javascript Views, Client-side or Server-side with NodeJS
KEY
Advanced Django Forms Usage
Vex@demo camp stuttgart_2010-11-23
I love json module
Extending rails
Intro to Micro-frameworks
Using source control for domino development - AUSLUG 2016
Anatomy of a UI Control - Extension Library Case Study
Javascript Views, Client-side or Server-side with NodeJS
Advanced Django Forms Usage

What's hot (14)

PPSX
Build automation for XPages - AUSLUG 2015
PDF
Developers! Y U No Open Source Ur Code?
PDF
Business of APIs
PDF
WordPress: Getting Under the Hood
PDF
eMusic: WordPress in the Enterprise
PDF
Bringing WordPress to the front-end. o2 is the new P2
PPTX
WordPress Under Control
PDF
Interoperability with Standardless IoT (Global IoT Day Wien)
PDF
WordPress Security 101 - Meetup Nairobi March 2020
PPTX
Novmeber 2015 WordPress News 'n' Stuff
PDF
What a Thing API Should Look Like (Global IoT Day Wien)
PDF
[Nuxeo World 2013] DID YOU SAY DAM? DIGITAL ASSET MANAGEMENT WITH THE NUXEO P...
PDF
Fostering Community
PDF
How to Contribute to Apache Flink (and Flink at the Apache Software Foundation)
Build automation for XPages - AUSLUG 2015
Developers! Y U No Open Source Ur Code?
Business of APIs
WordPress: Getting Under the Hood
eMusic: WordPress in the Enterprise
Bringing WordPress to the front-end. o2 is the new P2
WordPress Under Control
Interoperability with Standardless IoT (Global IoT Day Wien)
WordPress Security 101 - Meetup Nairobi March 2020
Novmeber 2015 WordPress News 'n' Stuff
What a Thing API Should Look Like (Global IoT Day Wien)
[Nuxeo World 2013] DID YOU SAY DAM? DIGITAL ASSET MANAGEMENT WITH THE NUXEO P...
Fostering Community
How to Contribute to Apache Flink (and Flink at the Apache Software Foundation)
Ad

Similar to Twitter streamingapi rubymongodbv2 (20)

PPTX
Taming Social Media with MongoDB
PPTX
MongoDC 2012: Taming Social Media with MongoDB
PDF
20131008 - Wajug - TweetWall Pro
PDF
Flowdock's full-text search with MongoDB
PDF
Jordan Kay's Twitter API tour
PDF
20130504 - FeWeb - Twitter API
PDF
Everyday - mongodb
PDF
Twitter Platform 2013
PPTX
Twitter api
ZIP
The Twitter API: A Presentation to Adobe
PDF
Twitter Trend Analyzer
PDF
CSE5656 Complex Networks - Gathering Data from Twitter
PDF
MongoDB at Sailthru: Scaling and Schema Design
KEY
Building a Highly Scalable, Open Source Twitter Clone
PDF
Twitter Protobufs And Hadoop Hug 021709
PPTX
HATEOAS 101 - Opinionated Introduction to a REST API Style
PPT
Coalmine spie 2012 presentation - jsw -d3
PDF
500Startups @ Twitter
KEY
Twitter API 2.0
KEY
Spiffy Applications With JavaScript
Taming Social Media with MongoDB
MongoDC 2012: Taming Social Media with MongoDB
20131008 - Wajug - TweetWall Pro
Flowdock's full-text search with MongoDB
Jordan Kay's Twitter API tour
20130504 - FeWeb - Twitter API
Everyday - mongodb
Twitter Platform 2013
Twitter api
The Twitter API: A Presentation to Adobe
Twitter Trend Analyzer
CSE5656 Complex Networks - Gathering Data from Twitter
MongoDB at Sailthru: Scaling and Schema Design
Building a Highly Scalable, Open Source Twitter Clone
Twitter Protobufs And Hadoop Hug 021709
HATEOAS 101 - Opinionated Introduction to a REST API Style
Coalmine spie 2012 presentation - jsw -d3
500Startups @ Twitter
Twitter API 2.0
Spiffy Applications With JavaScript
Ad

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Approach and Philosophy of On baking technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Programs and apps: productivity, graphics, security and other tools
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectroscopy.pptx food analysis technology
Understanding_Digital_Forensics_Presentation.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Approach and Philosophy of On baking technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Twitter streamingapi rubymongodbv2

  • 1. Consuming the Twitter Streaming API with Ruby and MongoDB Jeff Linwood Lone Star Ruby Conference V August 12, 2011 http://www.jefflinwood.com @jefflinwood Friday, August 12, 2011
  • 2. Goals • Watch for any tweet that contains certain keywords • Store those tweets into the MongoDB database Friday, August 12, 2011
  • 4. Twitter Streaming API+ Mongo DB • Twitter Streaming API • MongoDB • Not a web application Friday, August 12, 2011
  • 5. The many APIs of Twitter • Twitter Streaming API • User Streams • Site Streams (for the big boys) • REST API • Search API Friday, August 12, 2011
  • 6. Twitter Streaming API • Keywords • Users • Locations Great photo is by rachel_thecat http://www.flickr.com/photos/23209605@N00/2786126623/ Friday, August 12, 2011
  • 7. TweetStream gem by Michael Bleigh https://github.com/intridea/tweetstream Friday, August 12, 2011
  • 8. Connecting to the Twitter Streaming API • JSON responses • HTTP Basic Authentication • One stream per account (dev/prod) • Leave it open! • Don’t constantly reconnect, and if you do, back off Friday, August 12, 2011
  • 9. Limitations of Twitter Streaming API • 400 Keywords • 5,000 User Ids • 25 Location Boxes • Can ask Twitter for increased access Friday, August 12, 2011
  • 10. A Tweet, in JSON Friday, August 12, 2011
  • 11. Intro to MongoDB • NoSQL - what does that mean? • Great fit for JSON-oriented applications • If you don’t know your schema in advance • Query language • Map Reduce Friday, August 12, 2011
  • 12. Storing data in MongoDB • Native format of MongoDB is BSON, similar to JSON • Connect to a database (similar to MySQL) • Connect to a collection (created if it doesn’t exist) • Insert JSON (in our case, a tweet) Friday, August 12, 2011
  • 13. MongoDB + Ruby • mongo gem • bson_ext gem • http://www.mongodb.org/display/DOCS/ Ruby+Language+Center Friday, August 12, 2011
  • 14. Considerations for MongoDB • Tweets - very verbose JSON • Date format in Tweets not same as MongoDB • May want to pre-process Tweets • Can use both MongoDB and MySQL in same app if you want Friday, August 12, 2011
  • 15. Here’s the code • Okay, the whole thing is really done in about three lines. Friday, August 12, 2011
  • 16. Where do you run this? • Command line • Your own server • Heroku + MongoLab • Other cloud services Friday, August 12, 2011
  • 18. Now what? • Step 1: Collect Tweets • Step 2: ???? • Step 3: Profit! Friday, August 12, 2011
  • 19. To Learn More • https://dev.twitter.com/docs/streaming-api/ concepts • http://www.mongodb.org/ • https://github.com/jefflinwood/Tweeter- Keeper • http://www.jefflinwood.com/ • @jefflinwood on Twitter Friday, August 12, 2011