twitterscour 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/README +44 -0
- data/lib/tweet.rb +21 -0
- data/lib/tweet_location.rb +14 -0
- data/lib/twitterscour.rb +159 -0
- data/test/fixtures/brent_page_1.html +1197 -0
- data/test/fixtures/search.json +1 -0
- data/test/tc_tweets.rb +91 -0
- data/twitterscour.rb +1 -0
- metadata +97 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"completed_in":0.155,"max_id":96760062483234816,"max_id_str":"96760062483234816","next_page":"?page=2&max_id=96760062483234816&q=%23Ruby","page":1,"query":"%23Ruby","refresh_url":"?since_id=96760062483234816&q=%23Ruby","results":[{"created_at":"Fri, 29 Jul 2011 01:52:51 +0000","from_user":"ruby2itter","from_user_id":76768071,"from_user_id_str":"76768071","geo":{"coordinates":[35.26236,132.706875],"type":"Point"},"id":96760062483234816,"id_str":"96760062483234816","iso_language_code":"fr","metadata":{"result_type":"recent"},"profile_image_url":"http://a2.twimg.com/profile_images/517656304/ruby_normal.gif","source":"<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>","text":"Rails Hub\u60C5\u5831\u5C40: Rails 3.1\u306F8\u670822\u65E5\u306B\u30EA\u30EA\u30FC\u30B9\u3078: Ruby\u3068Rails\u306E\u4E21\u65B9\u306E\u30B3\u30DF\u30C3\u30BF\u3067\u3001\u65E5\u672C\u8A9E\u3082\u8A71\u305B\u308BAaron Patterson\u3055\u3093\u304C\u3001Ruby on Rails Talk\u30E1\u30FC\u30EA\u30F3\u30B0... http://bit.ly/p47Tpa #ruby","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 01:49:04 +0000","from_user":"keitaibanana","from_user_id":281580185,"from_user_id_str":"281580185","geo":null,"id":96759112540495872,"id_str":"96759112540495872","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a1.twimg.com/sticky/default_profile_images/default_profile_2_normal.png","source":"<a href="http://shinme.info/" rel="nofollow">shinme.info</a>","text":"\u30EB\u30D3\u30FC\u306E\u6307\u8F2A\u30B3\u30FC\u30C9\u9032\u884C http://shinme.info/x/4731/ #Ruby #ring #chords","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 01:34:03 +0000","from_user":"3EdotNET","from_user_id":212102140,"from_user_id_str":"212102140","geo":null,"id":96755330335248384,"id_str":"96755330335248384","iso_language_code":"fr","metadata":{"result_type":"recent"},"profile_image_url":"http://a1.twimg.com/profile_images/1219176705/EProgramm_NG_normal.jpg","source":"<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>","text":"Aannemers administratiepanel http://bit.ly/fGopoZ #programmer #web #designer #project #outsource #Telemarketing #Ruby #on #Rails #Aannemers","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 01:31:43 +0000","from_user":"JobMotel_Ruby","from_user_id":2556417,"from_user_id_str":"2556417","geo":{"coordinates":[51.481307,-3.180498],"type":"Point"},"id":96754745099812865,"id_str":"96754745099812865","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a3.twimg.com/profile_images/66481318/logos_jobmotel3._normal.jpg","source":"<a href="http://www.google.com/support/youtube/bin/answer.py?hl=en&answer=164577" rel="nofollow">Google</a>","text":"Senior Ruby Developer at Zooppa. Seattle, USA http://goo.gl/fb/OjiZC #ruby","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 01:25:04 +0000","from_user":"shyouhei","from_user_id":53241,"from_user_id_str":"53241","geo":null,"id":96753071266349056,"id_str":"96753071266349056","iso_language_code":"ja","metadata":{"result_type":"recent"},"profile_image_url":"http://a2.twimg.com/profile_images/1187365335/tmp2_normal.png","source":"<a href="http://github.com/cho45/net-irc/blob/master/examples/tig.rb" rel="nofollow">tig.rb</a>","text":"\u500B\u4EBA\u7684\u306B\u601D\u3044\u5F53\u305F\u308B\u3075\u3057\u3068\u304B\u306A\u3044\u3093\u3060\u3051\u3069\u4F55\u3060\u3063\u3051\u3053\u308C\u3002\u3060\u308C\u304B\u53CD\u5FDC\u3057\u3066\u3042\u3052\u3066\u3002 #ruby http://mla.n-z.jp/?r-t=385898","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 01:20:02 +0000","from_user":"ICloudCenter","from_user_id":185487948,"from_user_id_str":"185487948","geo":{"coordinates":[31.046051,34.851612],"type":"Point"},"id":96751806574624769,"id_str":"96751806574624769","iso_language_code":"fr","metadata":{"result_type":"recent"},"profile_image_url":"http://a1.twimg.com/profile_images/1249619926/bphlogo_bigger_normal.JPG","source":"<a href="http://www.icloudcenter.net" rel="nofollow">ICloudCenterPoster</a>","text":"Aannemers administratiepanel http://bit.ly/fGopoZ #programmer #web #designer #project #outsource #Telemarketing #Ruby #on #Rails #Aannemers","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 01:11:49 +0000","from_user":"ChrisBrett","from_user_id":3935854,"from_user_id_str":"3935854","geo":{"coordinates":[49.263588,-123.138565],"type":"Point"},"id":96749737407029248,"id_str":"96749737407029248","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a2.twimg.com/profile_images/1352823079/Hide_Sneak_normal.jpg","source":"<a href="http://twitpic.com" rel="nofollow">Twitpic</a>","text":"Big Day ~ #Ruby ~ http://twitpic.com/5xf2pk","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 00:51:50 +0000","from_user":"JDBarlow2","from_user_id":232424025,"from_user_id_str":"232424025","geo":{"coordinates":[32.678208,-83.173866],"type":"Point"},"id":96744706976907264,"id_str":"96744706976907264","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a2.twimg.com/profile_images/1248587322/uncle_normal.jpg","source":"<a href="http://www.twaitter.com" rel="nofollow">Twaitter</a>","text":"This is a #Photo of an #Undergroud #Waterfall at #Ruby #Falls\thttp://bit.ly/mGxhOz","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 00:41:50 +0000","from_user":"kblake","from_user_id":107293,"from_user_id_str":"107293","geo":{"coordinates":[37.437328,-122.159928],"type":"Point"},"id":96742191610863616,"id_str":"96742191610863616","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a1.twimg.com/profile_images/1372406512/5498219298_2f003e691b_normal.jpg","source":"<a href="http://itunes.apple.com/us/app/twitter/id409789998?mt=12" rel="nofollow">Twitter for Mac</a>","text":"@jeffcohen so far so good for me #ruby #rails","to_user":"jeffcohen","to_user_id":372814,"to_user_id_str":"372814"},{"created_at":"Fri, 29 Jul 2011 00:21:48 +0000","from_user":"jimmycuadra","from_user_id":5543533,"from_user_id_str":"5543533","geo":{"coordinates":[32.718834,-117.163841],"type":"Point"},"id":96737149948411904,"id_str":"96737149948411904","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a2.twimg.com/profile_images/1226970132/jc_logo_new_2_normal.png","source":"<a href="http://www.echofon.com/" rel="nofollow">Echofon</a>","text":"Excited to speak about my gem to_lang at @sdruby tonight! #ruby","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 00:21:20 +0000","from_user":"thiagomotoca","from_user_id":21108727,"from_user_id_str":"21108727","geo":{"coordinates":[-22.315443,-49.061465],"type":"Point"},"id":96737031790661632,"id_str":"96737031790661632","iso_language_code":"in","metadata":{"result_type":"recent"},"profile_image_url":"http://a1.twimg.com/profile_images/1432587776/tcruz2_normal.jpg","source":"<a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a>","text":"Taming #ruby","to_user_id":null,"to_user_id_str":null},{"created_at":"Fri, 29 Jul 2011 00:02:10 +0000","from_user":"x_rubydevs","from_user_id":229195870,"from_user_id_str":"229195870","geo":null,"id":96732207435100160,"id_str":"96732207435100160","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a0.twimg.com/profile_images/1242574217/XYDO_normal.jpeg","source":"<a href="http://www.xydo.com" rel="nofollow">XYDOhandles</a>","text":"Implementing a video player with Ruby #ruby #rails http://bit.ly/p1KAew","to_user_id":null,"to_user_id_str":null},{"created_at":"Thu, 28 Jul 2011 23:54:06 +0000","from_user":"DebraHurlbutt","from_user_id":276532831,"from_user_id_str":"276532831","geo":null,"id":96730179266813952,"id_str":"96730179266813952","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a3.twimg.com/profile_images/1344848378/722291322QkZ960cQ3V2271673_normal.jpg","source":"<a href="http://twitter.com/">web</a>","text":"10k White Gold #Ruby and #Diamond Twist #Pendant Review #necklace #discountdiamonds #jewelry","to_user_id":null,"to_user_id_str":null},{"created_at":"Thu, 28 Jul 2011 23:53:46 +0000","from_user":"treasamalassa","from_user_id":363489851,"from_user_id_str":"363489851","geo":{"coordinates":[52.474876,-8.157204],"type":"Point"},"id":96730095460429824,"id_str":"96730095460429824","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a2.twimg.com/profile_images/1453678785/image_normal.jpg","source":"<a href="http://twitter.com/#!/download/iphone" rel="nofollow">Twitter for iPhone</a>","text":"@DukeSpecial watched documentary on #ruby last night.Approached w/such care &obvious appreciation of an artist wen music was music well done","to_user":"DukeSpecial","to_user_id":1577951,"to_user_id_str":"1577951"},{"created_at":"Thu, 28 Jul 2011 23:49:53 +0000","from_user":"writeameer","from_user_id":1689731,"from_user_id_str":"1689731","geo":{"coordinates":[39.047422,-95.681523],"type":"Point"},"id":96729117805916160,"id_str":"96729117805916160","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http://a3.twimg.com/profile_images/920253856/Photo_on_2010-05-22_at_13.38_2_normal.jpg","source":"<a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>","text":"RT @ferventcoder: If you think #nodejs is an awesome #chocolatey #nuget package, wait until you install #ruby #devkit 'cinst ruby.devkit' http://ow.ly/5PRxE","to_user_id":null,"to_user_id_str":null}],"results_per_page":15,"since_id":0,"since_id_str":"0"}
|
data/test/tc_tweets.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/http'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
require File.dirname(__FILE__) + '/../lib/twitterscour'
|
6
|
+
|
7
|
+
class MockSuccess < Net::HTTPSuccess #:nodoc: all
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def code
|
12
|
+
200
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MockFailure < Net::HTTPServiceUnavailable #:nodoc: all
|
17
|
+
def initialize
|
18
|
+
end
|
19
|
+
def code
|
20
|
+
100
|
21
|
+
end
|
22
|
+
def body
|
23
|
+
"epic fail"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class MockHttpResponse #:nodoc: all
|
28
|
+
def initialize
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class TwitterScourTest < Test::Unit::TestCase #:nodoc: all
|
33
|
+
def test_get_user_tweets_success
|
34
|
+
test_data = File.read(File.dirname(__FILE__) + "/fixtures/brent_page_1.html")
|
35
|
+
MockHttpResponse.any_instance.stubs(:body).returns(test_data)
|
36
|
+
MockHttpResponse.any_instance.stubs(:code).returns(200)
|
37
|
+
HTTParty.expects(:get).twice.returns(MockHttpResponse.new)
|
38
|
+
tweets = nil
|
39
|
+
assert_nothing_raised do
|
40
|
+
tweets = TwitterScour.from_user('sowersb', 2, false)
|
41
|
+
end
|
42
|
+
assert_not_nil tweets
|
43
|
+
assert_equal 40, tweets.length
|
44
|
+
[tweets[1], tweets[21]].each do |t|
|
45
|
+
assert_equal "Yeah #Giants! Good pitching always beats good hitting. Finally a team I like wins the world series, first time since the 05 White Sox", t.text
|
46
|
+
assert_equal "sowersb", t.author_name
|
47
|
+
assert_equal "http://a3.twimg.com/profile_images/1084691799/Brent-sm_mini.jpg", t.author_pic
|
48
|
+
assert_equal Time.gm(2010,11,2,2,34,3).getlocal, t.time
|
49
|
+
assert_nil t.location
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_get_search_tweets_success
|
54
|
+
test_data = File.read(File.dirname(__FILE__) + "/fixtures/search.json")
|
55
|
+
MockHttpResponse.any_instance.stubs(:body).returns(test_data)
|
56
|
+
MockHttpResponse.any_instance.stubs(:code).returns(200)
|
57
|
+
HTTParty.expects(:get).twice.returns(MockHttpResponse.new)
|
58
|
+
tweets = nil
|
59
|
+
assert_nothing_raised do
|
60
|
+
tweets = TwitterScour.search_term('#Ruby', 2)
|
61
|
+
end
|
62
|
+
assert_not_nil tweets
|
63
|
+
assert_equal 30, tweets.length
|
64
|
+
[tweets[3], tweets[18]].each do |t|
|
65
|
+
assert_equal "Senior Ruby Developer at Zooppa. Seattle, USA http://goo.gl/fb/OjiZC #ruby", t.text
|
66
|
+
assert_equal "JobMotel_Ruby", t.author_name
|
67
|
+
assert_equal "http://a3.twimg.com/profile_images/66481318/logos_jobmotel3._normal.jpg", t.author_pic
|
68
|
+
assert_equal Time.parse("Fri, 29 Jul 2011 01:31:43 +0000"), t.time
|
69
|
+
assert_not_nil t.location
|
70
|
+
assert_equal [-3.180498, 51.481307], t.location.center
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def test_get_tweets_error
|
76
|
+
MockHttpResponse.any_instance.stubs(:body).returns("Error")
|
77
|
+
MockHttpResponse.any_instance.stubs(:code).returns(403)
|
78
|
+
HTTParty.expects(:get).twice.returns(MockHttpResponse.new)
|
79
|
+
tweets = nil
|
80
|
+
assert_raises Exception do
|
81
|
+
tweets = TwitterScour.from_user('sowersb', 1, false)
|
82
|
+
end
|
83
|
+
|
84
|
+
assert_raises Exception do
|
85
|
+
tweets = TwitterScour.search_term('Ruby', 1)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
data/twitterscour.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/twitterscour"
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twitterscour
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.2.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brent Sowers
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-28 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: httparty
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
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: json_pure
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
description: Search for tweets by a search term in one function call. Uses the Twitter API underneath. Also find all tweets by user. This doesn't use the API, because the API returns only what Twitter considers the "most popular" tweets in many cases. Using this gem will return everything that you can see by going to the Twitter web site for a user. User search probably shouldn't be relied upon for a production system, as Twitter can change the structure of their web page at any moment, and if so, this will not work until I update it.
|
50
|
+
email: brent@coordinatecommons.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README
|
57
|
+
- History.txt
|
58
|
+
files:
|
59
|
+
- twitterscour.rb
|
60
|
+
- lib/tweet.rb
|
61
|
+
- lib/twitterscour.rb
|
62
|
+
- lib/tweet_location.rb
|
63
|
+
- test/fixtures/search.json
|
64
|
+
- test/fixtures/brent_page_1.html
|
65
|
+
- test/tc_tweets.rb
|
66
|
+
- History.txt
|
67
|
+
- README
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://coordinatecommons.com/twitterscour/
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.6.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Class for retrieving tweets from Twitter, by user and search term
|
96
|
+
test_files:
|
97
|
+
- test/tc_tweets.rb
|