Coder Social home page Coder Social logo

stream_grabber's Introduction

StreamGrabber

StreamGrabber is a Rails Engine that can be included in your application to multiplex streams and feeds together into a timeline, it supports twitter, last.fm and github at the moment but is designed to be fairly trivial to add new sources, providing they have some kind of public facing data stream…

Usage

At the moment StreamGrabber supports Twitter, last.fm and Github so you'll need to give it your username for these sites. Create #{RAILS_ROOT}/config/stream_grabber.yml so that it looks like the following

:twitter: 
  username: username

:last_fm: 
  username: username
  api_key: api_key

:github: 
  username: username
  api_key: api_key

And then you can include the plugin in your Gemfile like so

gem 'stream_grabber'

and load the helper method in your chosen controller.

class HomepageController < ApplicationController
  helper :stream_grabber

  # blah blah blah
end

then in your views you use

<%= generate_stream_list %>

to render an ordered list of your most recent activity, most recent first. There are a couple of additional options you can pass to customise the output, the first is the number of results you'd like back (defaults to 15) and the second is the css id and class you wish to be applied to the output. You can use these as follows

<%= generate_stream_list 5, :class => 'foo' , :id => 'bar' %>

Adding new Sources

Sources are defined as classes in the StreamGrabber module, they are all loaded dynamically so all your new source has to do is conform to the following interface

module StreamGrabber
  class Twitter
    def initialize(user_name, api_key)
      # do your setup in here to grab and parse the stream
    end

    def last_five
      # returns your data as a timestamp keyed hash
    end
  end
end

And as long as last_five returns a hash with timestamps as keys, the value of each key is an array of the form

[:classname, "value"]

where :classname is a symbol representing what css class you want li elements for that source to have and "value" is whatever string content you want to display in the body.

Over engineered? Damn Straight!! You can see it in action in the sidebar of my homepage

If you want to add sources, please give me a pull request and I'll merge them straight in.

stream_grabber's People

Contributors

eightbitraptor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.