user-stream-receiver 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
14
+
15
+ gem "oauth-cli-twitter"
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ highline (1.6.1)
7
+ jeweler (1.5.2)
8
+ bundler (~> 1.0.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ json (1.4.6)
12
+ notify (0.3.0)
13
+ oauth (0.4.4)
14
+ oauth-cli-twitter (0.0.2)
15
+ oauth
16
+ pit
17
+ termtter
18
+ pit (0.0.6)
19
+ rake (0.8.7)
20
+ rcov (0.9.9)
21
+ rspec (2.3.0)
22
+ rspec-core (~> 2.3.0)
23
+ rspec-expectations (~> 2.3.0)
24
+ rspec-mocks (~> 2.3.0)
25
+ rspec-core (2.3.1)
26
+ rspec-expectations (2.3.0)
27
+ diff-lcs (~> 1.1.2)
28
+ rspec-mocks (2.3.0)
29
+ rubytter (1.4.1)
30
+ json (>= 1.1.3)
31
+ oauth (>= 0.3.6)
32
+ termcolor (1.2.1)
33
+ highline (>= 1.5.0)
34
+ termtter (1.9.0)
35
+ highline (>= 1.5.0)
36
+ json (>= 1.1.3)
37
+ notify (>= 0.2.1)
38
+ rubytter (>= 1.4.0)
39
+ termcolor (>= 1.0.0)
40
+
41
+ PLATFORMS
42
+ ruby
43
+
44
+ DEPENDENCIES
45
+ bundler (~> 1.0.0)
46
+ jeweler (~> 1.5.2)
47
+ oauth-cli-twitter
48
+ rcov
49
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 hitode909
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ user-stream-receiver
2
+ ====================
3
+
4
+ usage
5
+ =====
6
+
7
+ require 'user-stream-receiver'
8
+ require 'json'
9
+
10
+ UserStreamReceiver.new.run{|chunk|
11
+ p JSON.parse(chunk)
12
+ }
13
+
14
+ == Copyright
15
+
16
+ Copyright (c) 2011 hitode909. See LICENSE.txt for
17
+ further details.
18
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "user-stream-receiver"
16
+ gem.homepage = "http://github.com/hitode909/user-stream-receiver"
17
+ gem.license = "MIT"
18
+ gem.summary = 'User Stream Receiver'
19
+ gem.description = 'User Stream Receiver.'
20
+ gem.email = "hitode909@gmail.com"
21
+ gem.authors = ["hitode909"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "user-stream-receiver #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'user-stream-receiver'
5
+ require 'json'
6
+ require 'mongo'
7
+ include Mongo
8
+
9
+ db = Connection.new.db('twitter')
10
+ # db.collection('status').remove
11
+ # db.collection('friends').remove
12
+ # db.collection('event').remove
13
+
14
+ UserStreamReceiver.new.run{|chunk|
15
+ data = JSON.parse(chunk)
16
+ coll_key = data['friends'] ? 'friends'
17
+ : data['event'] ? 'event'
18
+ : data['delete'] ? 'delete'
19
+ : 'status'
20
+ db.collection(coll_key).insert(data)
21
+
22
+ p data
23
+ p coll_key
24
+ }
data/example/print.rb ADDED
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'user-stream-receiver'
5
+ require 'json'
6
+
7
+ UserStreamReceiver.new.run{|chunk|
8
+ p JSON.parse(chunk)
9
+ }
@@ -0,0 +1,54 @@
1
+ require 'logger'
2
+ require 'oauth/cli/twitter'
3
+
4
+ class UserStreamReceiver
5
+ include OAuth::CLI::Twitter
6
+
7
+ CONSUMER_TOKEN = 'kHOuxYqXSINzOW3UzEqEcA'
8
+ CONSUMER_SECRET = 'x6dzx1oFjgDrtJSM2v8YYEYhyN2LnB1zUOeNo9Y'
9
+
10
+ def run(&block)
11
+ loop {
12
+ begin
13
+ self.process &block
14
+ rescue => error
15
+ self.logger.warn error
16
+ sleep 1
17
+ end
18
+ }
19
+ end
20
+
21
+ protected
22
+ ENDPOINT = URI.parse('https://userstream.twitter.com/2/user.json')
23
+
24
+ def access_token
25
+ @access_token ||= self.get_access_token(:pit => 'user-stream-receiver')
26
+ end
27
+
28
+ def logger
29
+ @logger ||= Logger.new(STDOUT)
30
+ @logger.level = Logger::INFO
31
+ @logger
32
+ end
33
+
34
+ def process(&block)
35
+ self.logger.info("connecting")
36
+ https = Net::HTTP.new(ENDPOINT.host, ENDPOINT.port)
37
+ https.use_ssl = true
38
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
39
+
40
+ https.start{ |https|
41
+ request = Net::HTTP::Get.new(ENDPOINT.request_uri)
42
+ request.oauth!(https, self.access_token.consumer, self.access_token)
43
+ https.request(request){ |response|
44
+ raise response.code.to_i unless response.code.to_i == 200
45
+ raise 'Response is not chuncked' unless response.chunked?
46
+ self.logger.info("connected")
47
+ response.read_body{ |chunk|
48
+ self.logger.debug("received: #{chunk}")
49
+ yield chunk
50
+ }
51
+ }
52
+ }
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'user-stream-receiver'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "UserStreamReceiver" do
4
+ it "exists" do
5
+ UserStreamReceiver.new.should be_kind_of UserStreamReceiver
6
+ end
7
+ end
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{user-stream-receiver}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["hitode909"]
12
+ s.date = %q{2011-01-18}
13
+ s.description = %q{User Stream Receiver.}
14
+ s.email = %q{hitode909@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "example/insert_mongo.rb",
29
+ "example/print.rb",
30
+ "lib/user-stream-receiver.rb",
31
+ "spec/spec_helper.rb",
32
+ "spec/user-stream-receiver_spec.rb",
33
+ "user-stream-receiver.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/hitode909/user-stream-receiver}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{User Stream Receiver}
40
+ s.test_files = [
41
+ "spec/spec_helper.rb",
42
+ "spec/user-stream-receiver_spec.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<oauth-cli-twitter>, [">= 0"])
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ s.add_development_dependency(%q<rspec>, ["> 1.2.3"])
56
+ else
57
+ s.add_dependency(%q<oauth-cli-twitter>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ s.add_dependency(%q<rspec>, ["> 1.2.3"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<oauth-cli-twitter>, [">= 0"])
66
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
69
+ s.add_dependency(%q<rcov>, [">= 0"])
70
+ s.add_dependency(%q<rspec>, ["> 1.2.3"])
71
+ end
72
+ end
73
+
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: user-stream-receiver
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - hitode909
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-18 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: oauth-cli-twitter
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 2
42
+ - 3
43
+ - 0
44
+ version: 2.3.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 0
58
+ - 0
59
+ version: 1.0.0
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: jeweler
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 1
72
+ - 5
73
+ - 2
74
+ version: 1.5.2
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: rcov
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: rspec
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">"
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 1
100
+ - 2
101
+ - 3
102
+ version: 1.2.3
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: *id006
106
+ description: User Stream Receiver.
107
+ email: hitode909@gmail.com
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files:
113
+ - LICENSE.txt
114
+ - README.rdoc
115
+ files:
116
+ - .document
117
+ - .rspec
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - LICENSE.txt
121
+ - README.rdoc
122
+ - Rakefile
123
+ - VERSION
124
+ - example/insert_mongo.rb
125
+ - example/print.rb
126
+ - lib/user-stream-receiver.rb
127
+ - spec/spec_helper.rb
128
+ - spec/user-stream-receiver_spec.rb
129
+ - user-stream-receiver.gemspec
130
+ has_rdoc: true
131
+ homepage: http://github.com/hitode909/user-stream-receiver
132
+ licenses:
133
+ - MIT
134
+ post_install_message:
135
+ rdoc_options: []
136
+
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 473998417439686367
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ requirements: []
157
+
158
+ rubyforge_project:
159
+ rubygems_version: 1.3.7
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: User Stream Receiver
163
+ test_files:
164
+ - spec/spec_helper.rb
165
+ - spec/user-stream-receiver_spec.rb