Sha256: 250737f2a80675d0e2ec76545265e627b02bdf257a5c7e1e88a2a7a1ca65ffd2

Contents?: true

Size: 918 Bytes

Versions: 3

Compression:

Stored size: 918 Bytes

Contents

class TwitterBinder < Bowline::Binders::Collection
  cattr_accessor :user, :pass
  
  class << self    
    def index
      self.items = timeline
    end
    
    def update(text)
      twit.update(text)
      index # update timeline
    end
    
    def login
      self.user, self.pass = params[:user], params[:pass]
      if logged_in?
        show_view :twitter
        index
      else
        js.alert('Credentials invalid')
      end
    end
    
    def logged_in?
      return false unless self.user && self.pass
      begin
        twit.timeline && true
      rescue Twitter::CantConnect
        false
      end
    end
    
    protected
      def twit
        httpauth = Twitter::HTTPAuth.new(self.user, self.pass)
        Twitter::Base.new(httpauth)
      end
      
      def timeline
        twit.friends_timeline.collect {|t|
          t.delete('user')
          t.to_hash
        }
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
maccman-bowline-0.1.2 examples/twitter_binder.rb
maccman-bowline-0.1.3 examples/twitter_binder.rb
maccman-bowline-0.1.4 examples/twitter_binder.rb