em-twitter-client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +67 -0
- data/README.markdown +28 -0
- data/Rakefile +9 -0
- data/bin/console +20 -0
- data/em-twitter-client.gemspec +32 -0
- data/examples/everything_else.rb +68 -0
- data/examples/search.rb +22 -0
- data/examples/user_info.rb +27 -0
- data/lib/em-twitter-client/twitter_client.rb +111 -0
- data/lib/em-twitter-client/twitter_user.rb +23 -0
- data/lib/em-twitter-client/version.rb +5 -0
- data/lib/em_twitter_client.rb +3 -0
- data/spec/lib/twitter_client_spec.rb +20 -0
- data/spec/spec_helper.rb +7 -0
- metadata +172 -0
    
        data/.gitignore
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            examples/mykeys
         | 
    
        data/.rvmrc
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            rvm ruby-1.9.2-p180@twitter-client --create
         | 
    
        data/Gemfile
    ADDED
    
    | @@ -0,0 +1,8 @@ | |
| 1 | 
            +
            source :rubygems
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            gemspec
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            gem 'em-http-request', '>=1.0.0.beta.4', :require => ['em-http', 'em-http/middleware/oauth','em-http/middleware/json_response'], :git => "git://github.com/igrigorik/em-http-request.git"
         | 
| 6 | 
            +
            gem 'em-synchrony', :git => 'https://github.com/igrigorik/em-synchrony.git', :require => ['em-synchrony', 'em-synchrony/em-http']
         | 
| 7 | 
            +
            gem 'rack-fiber_pool','0.9.0', :require => 'rack/fiber_pool'
         | 
| 8 | 
            +
            gem 'oauth', :git => "git://github.com/sujal/oauth-ruby.git"
         | 
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            GIT
         | 
| 2 | 
            +
              remote: git://github.com/igrigorik/em-http-request.git
         | 
| 3 | 
            +
              revision: c7848ff95a603c0d97b465ed1f2058178b3f78c0
         | 
| 4 | 
            +
              specs:
         | 
| 5 | 
            +
                em-http-request (1.0.0.beta.4)
         | 
| 6 | 
            +
                  addressable (>= 2.2.3)
         | 
| 7 | 
            +
                  em-socksify
         | 
| 8 | 
            +
                  eventmachine (>= 1.0.0.beta.3)
         | 
| 9 | 
            +
                  http_parser.rb (>= 0.5.1)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            GIT
         | 
| 12 | 
            +
              remote: git://github.com/sujal/oauth-ruby.git
         | 
| 13 | 
            +
              revision: 6e2249fd1130dbc5fb9991e6ade8cd4abdbf3b5c
         | 
| 14 | 
            +
              specs:
         | 
| 15 | 
            +
                oauth (0.4.4)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            GIT
         | 
| 18 | 
            +
              remote: https://github.com/igrigorik/em-synchrony.git
         | 
| 19 | 
            +
              revision: 20172584779485f1c8c46333943e5582750698d2
         | 
| 20 | 
            +
              specs:
         | 
| 21 | 
            +
                em-synchrony (0.3.0.beta.1)
         | 
| 22 | 
            +
                  eventmachine (>= 1.0.0.beta.1)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            PATH
         | 
| 25 | 
            +
              remote: .
         | 
| 26 | 
            +
              specs:
         | 
| 27 | 
            +
                em-twitter-client (0.0.1)
         | 
| 28 | 
            +
                  addressable (>= 2.2.3)
         | 
| 29 | 
            +
                  em-http-request (= 1.0.0.beta.4)
         | 
| 30 | 
            +
                  em-synchrony
         | 
| 31 | 
            +
                  eventmachine (>= 1.0.0.beta.3)
         | 
| 32 | 
            +
                  yajl-ruby
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            GEM
         | 
| 35 | 
            +
              remote: http://rubygems.org/
         | 
| 36 | 
            +
              specs:
         | 
| 37 | 
            +
                addressable (2.2.6)
         | 
| 38 | 
            +
                diff-lcs (1.1.2)
         | 
| 39 | 
            +
                em-socksify (0.1.0)
         | 
| 40 | 
            +
                  eventmachine
         | 
| 41 | 
            +
                eventmachine (1.0.0.beta.3)
         | 
| 42 | 
            +
                http_parser.rb (0.5.1)
         | 
| 43 | 
            +
                rack-fiber_pool (0.9.0)
         | 
| 44 | 
            +
                rake (0.8.7)
         | 
| 45 | 
            +
                rspec (2.5.0)
         | 
| 46 | 
            +
                  rspec-core (~> 2.5.0)
         | 
| 47 | 
            +
                  rspec-expectations (~> 2.5.0)
         | 
| 48 | 
            +
                  rspec-mocks (~> 2.5.0)
         | 
| 49 | 
            +
                rspec-core (2.5.1)
         | 
| 50 | 
            +
                rspec-expectations (2.5.0)
         | 
| 51 | 
            +
                  diff-lcs (~> 1.1.2)
         | 
| 52 | 
            +
                rspec-mocks (2.5.0)
         | 
| 53 | 
            +
                yajl-ruby (0.8.2)
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            PLATFORMS
         | 
| 56 | 
            +
              ruby
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            DEPENDENCIES
         | 
| 59 | 
            +
              bundler
         | 
| 60 | 
            +
              em-http-request (>= 1.0.0.beta.4)!
         | 
| 61 | 
            +
              em-synchrony!
         | 
| 62 | 
            +
              em-twitter-client!
         | 
| 63 | 
            +
              oauth!
         | 
| 64 | 
            +
              rack-fiber_pool (= 0.9.0)
         | 
| 65 | 
            +
              rake
         | 
| 66 | 
            +
              rspec
         | 
| 67 | 
            +
              rspec-core
         | 
    
        data/README.markdown
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            em-twitter-client
         | 
| 2 | 
            +
            =================
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            It provides a simple api to access twitter rest api using event machine. This has provided us with really fast and efficient way of retriving twitter data.
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            The current api is based on pages of information and will retrieve 
         | 
| 7 | 
            +
            It is based on em-http-request and event-machine.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            There are some usage examples in the examples folder.
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            The current implementation blocks for each api call to finish. Ie. 5 pages of user_timeline is fetched asynchronously but it waits for the call to complete.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            That's sort of what we needed, but the complete async api is coming soon as well. 
         | 
| 14 | 
            +
             | 
| 15 | 
            +
             | 
| 16 | 
            +
            Here are some examples. It's based on em-synchrony. So remember to wrap it into the EM.synchrony
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            	EM.synchrony do 
         | 
| 19 | 
            +
            		twitter = EM::TwitterClient.new(oauth)
         | 
| 20 | 
            +
              		twitter.rate_limit
         | 
| 21 | 
            +
              		twitter.home_timeline(2) do |data|
         | 
| 22 | 
            +
                		@data = data
         | 
| 23 | 
            +
                		puts data.flatten.inspect
         | 
| 24 | 
            +
                		EM.stop
         | 
| 25 | 
            +
              		end
         | 
| 26 | 
            +
            	end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            Will hopefully publish the gem then as well, when that is done. 
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            require 'irb'
         | 
| 3 | 
            +
            require 'irb/completion'
         | 
| 4 | 
            +
            require 'bundler'
         | 
| 5 | 
            +
            # Set up gems listed in the Gemfile.
         | 
| 6 | 
            +
            begin
         | 
| 7 | 
            +
              ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
         | 
| 8 | 
            +
              require 'bundler'
         | 
| 9 | 
            +
              Bundler.setup
         | 
| 10 | 
            +
            rescue Bundler::GemNotFound => e
         | 
| 11 | 
            +
              STDERR.puts e.message
         | 
| 12 | 
            +
              STDERR.puts "Try running 'bundle install'."
         | 
| 13 | 
            +
              exit!
         | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            Bundler.require(:default)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            require File.expand_path("../../lib/em-twitter-client/twitter_client", __FILE__)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            IRB.start
         | 
| @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            require "em-twitter-client/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name        = "em-twitter-client"
         | 
| 7 | 
            +
              s.version     = EM::TwitterClient::VERSION
         | 
| 8 | 
            +
              s.platform    = Gem::Platform::RUBY
         | 
| 9 | 
            +
              s.authors     = ["V Sreekanth"]
         | 
| 10 | 
            +
              s.email       = ["sreeix@gmail.com"]
         | 
| 11 | 
            +
              s.summary     = %q{Event Machined API to access twitter via rest}
         | 
| 12 | 
            +
              s.description = %q{Event Machined API to access twitter via rest}
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              s.rubyforge_project = "em-twitter-client"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.files         = `git ls-files`.split("\n")
         | 
| 17 | 
            +
              s.test_files    = `git ls-files -- {test,spec,features}/*`.split("\n")
         | 
| 18 | 
            +
              s.executables   = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              s.require_paths = ["lib"]
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              
         | 
| 23 | 
            +
              s.add_dependency('eventmachine', ">=1.0.0.beta.3")
         | 
| 24 | 
            +
              s.add_dependency('yajl-ruby')
         | 
| 25 | 
            +
              s.add_dependency('addressable', ">= 2.2.3")
         | 
| 26 | 
            +
              s.add_dependency('em-synchrony')
         | 
| 27 | 
            +
              s.add_dependency('em-http-request', "=1.0.0.beta.4")
         | 
| 28 | 
            +
              s.add_development_dependency('rspec')
         | 
| 29 | 
            +
              s.add_development_dependency('rspec-core')
         | 
| 30 | 
            +
              s.add_development_dependency('rake')
         | 
| 31 | 
            +
              s.add_development_dependency('bundler')
         | 
| 32 | 
            +
            end
         | 
| @@ -0,0 +1,68 @@ | |
| 1 | 
            +
            require File.expand_path('../../lib/em-twitter-client/twitter_client', __FILE__)
         | 
| 2 | 
            +
            require 'eventmachine'
         | 
| 3 | 
            +
            require 'em-http'
         | 
| 4 | 
            +
            require 'em-http/middleware/oauth'
         | 
| 5 | 
            +
            require 'em-http/middleware/json_response'
         | 
| 6 | 
            +
            require 'em-synchrony/em-http'
         | 
| 7 | 
            +
            require "em-synchrony"
         | 
| 8 | 
            +
            require "em-synchrony/em-http"
         | 
| 9 | 
            +
            @data = []
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            oauth = {:consumer_key     => 'LALA',
         | 
| 12 | 
            +
                     :consumer_secret  => 'FOO',
         | 
| 13 | 
            +
                     :access_token     => 'LALA',
         | 
| 14 | 
            +
                     :access_token_secret => 'LALA'
         | 
| 15 | 
            +
                   }
         | 
| 16 | 
            +
             | 
| 17 | 
            +
             | 
| 18 | 
            +
            EM.synchrony do 
         | 
| 19 | 
            +
              twitter = EM::TwitterClient.new(oauth)
         | 
| 20 | 
            +
              twitter.rate_limit
         | 
| 21 | 
            +
              twitter.mentions do |data|
         | 
| 22 | 
            +
                @data = data
         | 
| 23 | 
            +
                puts data.flatten.inspect
         | 
| 24 | 
            +
                EM.stop
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            EM.synchrony do 
         | 
| 29 | 
            +
              twitter = EM::TwitterClient.new(oauth)
         | 
| 30 | 
            +
              twitter.rate_limit
         | 
| 31 | 
            +
              twitter.home_timeline(2) do |data|
         | 
| 32 | 
            +
                @data = data
         | 
| 33 | 
            +
                puts data.flatten.inspect
         | 
| 34 | 
            +
                EM.stop
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
            end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            EM.synchrony do 
         | 
| 39 | 
            +
              twitter = EM::TwitterClient.new(oauth)
         | 
| 40 | 
            +
              twitter.rate_limit
         | 
| 41 | 
            +
              twitter.user_timeline('sreeix', 2) do |data|
         | 
| 42 | 
            +
                @data = data
         | 
| 43 | 
            +
                puts data.flatten.inspect
         | 
| 44 | 
            +
                EM.stop
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
            end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            EM.synchrony do 
         | 
| 49 | 
            +
              twitter = EM::TwitterClient.new(oauth)
         | 
| 50 | 
            +
              twitter.rate_limit
         | 
| 51 | 
            +
              twitter.user_friends('sreeix', 8) do |data|
         | 
| 52 | 
            +
                @data = data
         | 
| 53 | 
            +
                puts "sreeix friends = #{data.flatten.size}"
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
              twitter.user_friends('shufflr', 20) do |data|
         | 
| 56 | 
            +
                @data = data
         | 
| 57 | 
            +
                puts "shufflr friends = #{data.flatten.size}"
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
              twitter.user_friends('markhneedham', 20) do |data|
         | 
| 60 | 
            +
                @data = data
         | 
| 61 | 
            +
                puts "markneedham = #{data.flatten.size}"
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
              twitter.user_friends('WardCunningham', 10) do |data|
         | 
| 64 | 
            +
                @data = data
         | 
| 65 | 
            +
                puts "Wardcunningham friends #{data.flatten.size}"
         | 
| 66 | 
            +
                EM.stop
         | 
| 67 | 
            +
              end
         | 
| 68 | 
            +
            end
         | 
    
        data/examples/search.rb
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            require File.expand_path('../../lib/em-twitter-client/twitter_client', __FILE__)
         | 
| 2 | 
            +
            require 'eventmachine'
         | 
| 3 | 
            +
            require 'em-http'
         | 
| 4 | 
            +
            require 'em-http/middleware/oauth'
         | 
| 5 | 
            +
            require 'em-http/middleware/json_response'
         | 
| 6 | 
            +
            require 'em-synchrony/em-http'
         | 
| 7 | 
            +
            require "em-synchrony"
         | 
| 8 | 
            +
            require "em-synchrony/em-http"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            oauth = {:consumer_key     => 'tVcGxZZx9L2g7bFg2uiwGA',
         | 
| 11 | 
            +
                     :consumer_secret  => 'Rxh9kk8lqPgQgX04kPNr5TSp2kxgIvIZSbEcMUpC1Hg',
         | 
| 12 | 
            +
                     :access_token     => '237729849-imrgHKImaNXgSC9eThYGg0f0IMy9CkDCUhbyXwAU',
         | 
| 13 | 
            +
                     :access_token_secret => 'esWHYtuPnmnzMqAP6OC85SOOmUhUpbaLMoHFnO3vFuI'
         | 
| 14 | 
            +
                   }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            EM.synchrony do 
         | 
| 17 | 
            +
              twitter = EM::TwitterClient.new(oauth)
         | 
| 18 | 
            +
              twitter.search('tour de france', 4, :lang => 'fr' ) do |data|
         | 
| 19 | 
            +
                puts data.inspect
         | 
| 20 | 
            +
                EM.stop
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require File.expand_path('../../lib/em-twitter-client/twitter_client', __FILE__)
         | 
| 2 | 
            +
            # require 'eventmachine'
         | 
| 3 | 
            +
            # require 'em-http'
         | 
| 4 | 
            +
            # require 'em-http/middleware/oauth'
         | 
| 5 | 
            +
            # require 'em-http/middleware/json_response'
         | 
| 6 | 
            +
            # require 'em-synchrony/em-http'
         | 
| 7 | 
            +
            require 'eventmachine'
         | 
| 8 | 
            +
            require 'em-http'
         | 
| 9 | 
            +
            require 'em-http/middleware/oauth'
         | 
| 10 | 
            +
            require 'em-http/middleware/json_response'
         | 
| 11 | 
            +
            require 'em-synchrony/em-http'
         | 
| 12 | 
            +
            require "em-synchrony"
         | 
| 13 | 
            +
            require "em-synchrony/em-http"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            oauth = {:consumer_key     => 'YOUR KEY',
         | 
| 16 | 
            +
                     :consumer_secret  => 'YOUR SECRED',
         | 
| 17 | 
            +
                     :access_token     => 'TOKEN',
         | 
| 18 | 
            +
                     :access_token_secret => 'SECRET'
         | 
| 19 | 
            +
                   }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            EM.synchrony do 
         | 
| 22 | 
            +
              twitter = EM::TwitterClient.new(oauth)
         | 
| 23 | 
            +
              twitter.user_info('sreeix') do |data|
         | 
| 24 | 
            +
                puts data.inspect
         | 
| 25 | 
            +
                EM.stop
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,111 @@ | |
| 1 | 
            +
            module EventMachine
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              ## Takes the following hash
         | 
| 4 | 
            +
              ## {:consumer_key     => '',
         | 
| 5 | 
            +
              ##  :consumer_secret  => '',
         | 
| 6 | 
            +
              ##  :access_token     => '',
         | 
| 7 | 
            +
              ##  :access_token_secret => ''
         | 
| 8 | 
            +
              ## }
         | 
| 9 | 
            +
              
         | 
| 10 | 
            +
              class TwitterClient
         | 
| 11 | 
            +
                attr_accessor :errback
         | 
| 12 | 
            +
                
         | 
| 13 | 
            +
                def initialize(oauth_config)
         | 
| 14 | 
            +
                  EventMachine::HttpRequest.use EventMachine::Middleware::JSONResponse
         | 
| 15 | 
            +
                  @host = {:api => 'http://api.twitter.com', :search => 'http://search.twitter.com'}
         | 
| 16 | 
            +
                  @oauth = oauth_config
         | 
| 17 | 
            +
                  @errback = Proc.new {|data| puts data.inspect}
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                def rate_limit(&blk)
         | 
| 21 | 
            +
                  http = connection("1/account/rate_limit_status.json").aget
         | 
| 22 | 
            +
                  http.callback do 
         | 
| 23 | 
            +
                     @current_ratelimit = http.response
         | 
| 24 | 
            +
                     puts http.response.inspect
         | 
| 25 | 
            +
                     blk(@current_ratelimit) if block_given?
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
                
         | 
| 29 | 
            +
                def user_info(user, &blk)
         | 
| 30 | 
            +
                  path = "1/users/show.json?screen_name=#{user.strip}"
         | 
| 31 | 
            +
                  http = connection(path).aget
         | 
| 32 | 
            +
                  http.callback { yield(http.response) if block_given?}
         | 
| 33 | 
            +
                  http.errback { @errback.call(http.response) } 
         | 
| 34 | 
            +
                  self
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def search( text, pages = 1 ,search_opts = {}, &blk)
         | 
| 38 | 
            +
                  multi = EventMachine::Synchrony::Multi.new
         | 
| 39 | 
            +
                  Array(1..pages).each do |page|
         | 
| 40 | 
            +
                    conn = connection("search.json?q=#{URI::escape(text)}&page=#{page}", :search)
         | 
| 41 | 
            +
                    multi.add(page, conn.aget)
         | 
| 42 | 
            +
                    puts "q=#{URI::escape(text)}&page=#{page}"
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
                  
         | 
| 45 | 
            +
                  process_paged_responses multi.perform, blk
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             
         | 
| 48 | 
            +
                def user_friends(user, pages = 1, &blk)
         | 
| 49 | 
            +
                  multi = EventMachine::Synchrony::Multi.new
         | 
| 50 | 
            +
                  Array(1..pages).each do |page|
         | 
| 51 | 
            +
                    conn = connection("1/statuses/friends.json?screen_name=#{user}&page=#{page}")
         | 
| 52 | 
            +
                    multi.add(page, conn.aget)
         | 
| 53 | 
            +
                    puts "Adding 1/statuses/friends.json?screen_name=#{user}&page=#{page}"
         | 
| 54 | 
            +
                  end
         | 
| 55 | 
            +
                  
         | 
| 56 | 
            +
                  process_paged_responses multi.perform, blk
         | 
| 57 | 
            +
                  self
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def user_timeline(user, pages = 1, &blk)
         | 
| 61 | 
            +
                  multi = EventMachine::Synchrony::Multi.new
         | 
| 62 | 
            +
                  Array(1..pages).each do |page|
         | 
| 63 | 
            +
                    conn = connection("1/statuses/user_timeline.json?screen_name=#{user}&page=#{page}&count=200")
         | 
| 64 | 
            +
                    multi.add(page, conn.aget)
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                  process_paged_responses multi.perform, blk
         | 
| 67 | 
            +
                  self
         | 
| 68 | 
            +
                end   
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                # these are private  for the user. as in only available for that user.
         | 
| 71 | 
            +
                def home_timeline(pages = 1, &blk)
         | 
| 72 | 
            +
                  multi = EventMachine::Synchrony::Multi.new
         | 
| 73 | 
            +
                  Array(1..pages).each do |page|
         | 
| 74 | 
            +
                    conn = connection("1/statuses/home_timeline.json?page=#{page}&count=200")
         | 
| 75 | 
            +
                    multi.add(page, conn.aget)
         | 
| 76 | 
            +
                    puts "Adding 1/statuses/home_timeline.json?page=#{page}"
         | 
| 77 | 
            +
                  end
         | 
| 78 | 
            +
                  process_paged_responses multi.perform, blk
         | 
| 79 | 
            +
                  self
         | 
| 80 | 
            +
                end  
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                def mentions(pages = 1, &blk)
         | 
| 83 | 
            +
                  multi = EventMachine::Synchrony::Multi.new
         | 
| 84 | 
            +
                  Array(1..pages).each do |page|
         | 
| 85 | 
            +
                    conn = connection("1/statuses/mentions.json?page=#{page}&count=200")
         | 
| 86 | 
            +
                    multi.add(page, conn.aget)
         | 
| 87 | 
            +
                    puts "Adding 1/statuses/mentions.json?page=#{page}"
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
                  process_paged_responses multi.perform, blk
         | 
| 90 | 
            +
                  self
         | 
| 91 | 
            +
                end  
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              private
         | 
| 94 | 
            +
                def process_paged_responses(res, blk)
         | 
| 95 | 
            +
                  response = Array(res.responses[:callback]).sort{|a,b| a.first <=> b.first}.collect{|a,b| b.response}
         | 
| 96 | 
            +
                  blk.call(response)
         | 
| 97 | 
            +
                  errors = Array(res.responses[:errback]).sort{|a,b| a.first <=> b.first}.collect{|a,b| b.response}
         | 
| 98 | 
            +
                  puts res.responses[:errback].inspect
         | 
| 99 | 
            +
                  @errback.call(errors) unless errors.empty?
         | 
| 100 | 
            +
                end
         | 
| 101 | 
            +
                
         | 
| 102 | 
            +
                def connection(url, to=:api)
         | 
| 103 | 
            +
                  puts "#{@host[to]}/#{url}"
         | 
| 104 | 
            +
                  EventMachine::HttpRequest.new("#{@host[to]}/#{url}").tap {|c| c.use EventMachine::Middleware::OAuth, @oauth}
         | 
| 105 | 
            +
                end
         | 
| 106 | 
            +
              end
         | 
| 107 | 
            +
            end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
             | 
| 110 | 
            +
             | 
| 111 | 
            +
             | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            class TwitterUser
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              def initialize(user, oauth_config)
         | 
| 4 | 
            +
                @user = user
         | 
| 5 | 
            +
                @twitter = TwitterClient.new(oauth_config)
         | 
| 6 | 
            +
              end
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
              def info(&blk)
         | 
| 9 | 
            +
                @twitter.info(@user, blk)
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def mentions(page = 1, &blk)
         | 
| 13 | 
            +
                @twitter.mentions(page, blk)
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def timeline(page = 1, &blk)
         | 
| 17 | 
            +
                @twitter.home_timeline(page, blk)
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              def user_timeline(page = 1, &blk)
         | 
| 21 | 
            +
                @twitter.user_timeline(@user, page, blk)
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
         | 
| 2 | 
            +
            module EM
         | 
| 3 | 
            +
              describe TwitterClient do
         | 
| 4 | 
            +
                it "gets userinfo" do
         | 
| 5 | 
            +
                  credentials = {:consumer_key     => 'LALA',
         | 
| 6 | 
            +
                           :consumer_secret  => 'FOO',
         | 
| 7 | 
            +
                           :access_token     => 'LALA',
         | 
| 8 | 
            +
                           :access_token_secret => 'LALA'
         | 
| 9 | 
            +
                         }
         | 
| 10 | 
            +
                    EM.run do
         | 
| 11 | 
            +
                      tc = EM::TwitterClient.new(credentials)
         | 
| 12 | 
            +
                      timeline  = tc.user_timeline('sreeix')
         | 
| 13 | 
            +
                      timeline.callback do
         | 
| 14 | 
            +
                        timeline.size.should_not == 0
         | 
| 15 | 
            +
                        EM.stop
         | 
| 16 | 
            +
                      end
         | 
| 17 | 
            +
                    end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,172 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            +
            name: em-twitter-client
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            +
              prerelease: 
         | 
| 5 | 
            +
              version: 0.0.1
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors: 
         | 
| 8 | 
            +
            - V Sreekanth
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            date: 2011-07-13 00:00:00 +05:30
         | 
| 14 | 
            +
            default_executable: 
         | 
| 15 | 
            +
            dependencies: 
         | 
| 16 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 17 | 
            +
              name: eventmachine
         | 
| 18 | 
            +
              prerelease: false
         | 
| 19 | 
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         | 
| 20 | 
            +
                none: false
         | 
| 21 | 
            +
                requirements: 
         | 
| 22 | 
            +
                - - ">="
         | 
| 23 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 24 | 
            +
                    version: 1.0.0.beta.3
         | 
| 25 | 
            +
              type: :runtime
         | 
| 26 | 
            +
              version_requirements: *id001
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 28 | 
            +
              name: yajl-ruby
         | 
| 29 | 
            +
              prerelease: false
         | 
| 30 | 
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         | 
| 31 | 
            +
                none: false
         | 
| 32 | 
            +
                requirements: 
         | 
| 33 | 
            +
                - - ">="
         | 
| 34 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 35 | 
            +
                    version: "0"
         | 
| 36 | 
            +
              type: :runtime
         | 
| 37 | 
            +
              version_requirements: *id002
         | 
| 38 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 39 | 
            +
              name: addressable
         | 
| 40 | 
            +
              prerelease: false
         | 
| 41 | 
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         | 
| 42 | 
            +
                none: false
         | 
| 43 | 
            +
                requirements: 
         | 
| 44 | 
            +
                - - ">="
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 46 | 
            +
                    version: 2.2.3
         | 
| 47 | 
            +
              type: :runtime
         | 
| 48 | 
            +
              version_requirements: *id003
         | 
| 49 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 50 | 
            +
              name: em-synchrony
         | 
| 51 | 
            +
              prerelease: false
         | 
| 52 | 
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         | 
| 53 | 
            +
                none: false
         | 
| 54 | 
            +
                requirements: 
         | 
| 55 | 
            +
                - - ">="
         | 
| 56 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 57 | 
            +
                    version: "0"
         | 
| 58 | 
            +
              type: :runtime
         | 
| 59 | 
            +
              version_requirements: *id004
         | 
| 60 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 61 | 
            +
              name: em-http-request
         | 
| 62 | 
            +
              prerelease: false
         | 
| 63 | 
            +
              requirement: &id005 !ruby/object:Gem::Requirement 
         | 
| 64 | 
            +
                none: false
         | 
| 65 | 
            +
                requirements: 
         | 
| 66 | 
            +
                - - "="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 68 | 
            +
                    version: 1.0.0.beta.4
         | 
| 69 | 
            +
              type: :runtime
         | 
| 70 | 
            +
              version_requirements: *id005
         | 
| 71 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 72 | 
            +
              name: rspec
         | 
| 73 | 
            +
              prerelease: false
         | 
| 74 | 
            +
              requirement: &id006 !ruby/object:Gem::Requirement 
         | 
| 75 | 
            +
                none: false
         | 
| 76 | 
            +
                requirements: 
         | 
| 77 | 
            +
                - - ">="
         | 
| 78 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 79 | 
            +
                    version: "0"
         | 
| 80 | 
            +
              type: :development
         | 
| 81 | 
            +
              version_requirements: *id006
         | 
| 82 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 83 | 
            +
              name: rspec-core
         | 
| 84 | 
            +
              prerelease: false
         | 
| 85 | 
            +
              requirement: &id007 !ruby/object:Gem::Requirement 
         | 
| 86 | 
            +
                none: false
         | 
| 87 | 
            +
                requirements: 
         | 
| 88 | 
            +
                - - ">="
         | 
| 89 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 90 | 
            +
                    version: "0"
         | 
| 91 | 
            +
              type: :development
         | 
| 92 | 
            +
              version_requirements: *id007
         | 
| 93 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 94 | 
            +
              name: rake
         | 
| 95 | 
            +
              prerelease: false
         | 
| 96 | 
            +
              requirement: &id008 !ruby/object:Gem::Requirement 
         | 
| 97 | 
            +
                none: false
         | 
| 98 | 
            +
                requirements: 
         | 
| 99 | 
            +
                - - ">="
         | 
| 100 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 101 | 
            +
                    version: "0"
         | 
| 102 | 
            +
              type: :development
         | 
| 103 | 
            +
              version_requirements: *id008
         | 
| 104 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 105 | 
            +
              name: bundler
         | 
| 106 | 
            +
              prerelease: false
         | 
| 107 | 
            +
              requirement: &id009 !ruby/object:Gem::Requirement 
         | 
| 108 | 
            +
                none: false
         | 
| 109 | 
            +
                requirements: 
         | 
| 110 | 
            +
                - - ">="
         | 
| 111 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 112 | 
            +
                    version: "0"
         | 
| 113 | 
            +
              type: :development
         | 
| 114 | 
            +
              version_requirements: *id009
         | 
| 115 | 
            +
            description: Event Machined API to access twitter via rest
         | 
| 116 | 
            +
            email: 
         | 
| 117 | 
            +
            - sreeix@gmail.com
         | 
| 118 | 
            +
            executables: 
         | 
| 119 | 
            +
            - console
         | 
| 120 | 
            +
            extensions: []
         | 
| 121 | 
            +
             | 
| 122 | 
            +
            extra_rdoc_files: []
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            files: 
         | 
| 125 | 
            +
            - .gitignore
         | 
| 126 | 
            +
            - .rvmrc
         | 
| 127 | 
            +
            - Gemfile
         | 
| 128 | 
            +
            - Gemfile.lock
         | 
| 129 | 
            +
            - README.markdown
         | 
| 130 | 
            +
            - Rakefile
         | 
| 131 | 
            +
            - bin/console
         | 
| 132 | 
            +
            - em-twitter-client.gemspec
         | 
| 133 | 
            +
            - examples/everything_else.rb
         | 
| 134 | 
            +
            - examples/search.rb
         | 
| 135 | 
            +
            - examples/user_info.rb
         | 
| 136 | 
            +
            - lib/em-twitter-client/twitter_client.rb
         | 
| 137 | 
            +
            - lib/em-twitter-client/twitter_user.rb
         | 
| 138 | 
            +
            - lib/em-twitter-client/version.rb
         | 
| 139 | 
            +
            - lib/em_twitter_client.rb
         | 
| 140 | 
            +
            - spec/lib/twitter_client_spec.rb
         | 
| 141 | 
            +
            - spec/spec_helper.rb
         | 
| 142 | 
            +
            has_rdoc: true
         | 
| 143 | 
            +
            homepage: 
         | 
| 144 | 
            +
            licenses: []
         | 
| 145 | 
            +
             | 
| 146 | 
            +
            post_install_message: 
         | 
| 147 | 
            +
            rdoc_options: []
         | 
| 148 | 
            +
             | 
| 149 | 
            +
            require_paths: 
         | 
| 150 | 
            +
            - lib
         | 
| 151 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 152 | 
            +
              none: false
         | 
| 153 | 
            +
              requirements: 
         | 
| 154 | 
            +
              - - ">="
         | 
| 155 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 156 | 
            +
                  version: "0"
         | 
| 157 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 158 | 
            +
              none: false
         | 
| 159 | 
            +
              requirements: 
         | 
| 160 | 
            +
              - - ">="
         | 
| 161 | 
            +
                - !ruby/object:Gem::Version 
         | 
| 162 | 
            +
                  version: "0"
         | 
| 163 | 
            +
            requirements: []
         | 
| 164 | 
            +
             | 
| 165 | 
            +
            rubyforge_project: em-twitter-client
         | 
| 166 | 
            +
            rubygems_version: 1.6.2
         | 
| 167 | 
            +
            signing_key: 
         | 
| 168 | 
            +
            specification_version: 3
         | 
| 169 | 
            +
            summary: Event Machined API to access twitter via rest
         | 
| 170 | 
            +
            test_files: 
         | 
| 171 | 
            +
            - spec/lib/twitter_client_spec.rb
         | 
| 172 | 
            +
            - spec/spec_helper.rb
         |