netshade-twitter 0.4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History +126 -0
- data/License +19 -0
- data/Manifest +69 -0
- data/README +84 -0
- data/Rakefile +42 -0
- data/bin/twitter +14 -0
- data/examples/blocks.rb +15 -0
- data/examples/direct_messages.rb +29 -0
- data/examples/favorites.rb +20 -0
- data/examples/friends_followers.rb +25 -0
- data/examples/friendships.rb +13 -0
- data/examples/identica_timeline.rb +7 -0
- data/examples/location.rb +8 -0
- data/examples/posting.rb +9 -0
- data/examples/replies.rb +27 -0
- data/examples/search.rb +18 -0
- data/examples/sent_messages.rb +27 -0
- data/examples/timeline.rb +34 -0
- data/examples/twitter.rb +27 -0
- data/examples/verify_credentials.rb +13 -0
- data/lib/twitter.rb +34 -0
- data/lib/twitter/base.rb +284 -0
- data/lib/twitter/cli.rb +334 -0
- data/lib/twitter/cli/config.rb +9 -0
- data/lib/twitter/cli/helpers.rb +109 -0
- data/lib/twitter/cli/migrations/20080722194500_create_accounts.rb +13 -0
- data/lib/twitter/cli/migrations/20080722194508_create_tweets.rb +16 -0
- data/lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb +9 -0
- data/lib/twitter/cli/migrations/20080722214606_create_configurations.rb +13 -0
- data/lib/twitter/cli/models/account.rb +33 -0
- data/lib/twitter/cli/models/configuration.rb +13 -0
- data/lib/twitter/cli/models/tweet.rb +20 -0
- data/lib/twitter/direct_message.rb +22 -0
- data/lib/twitter/easy_class_maker.rb +43 -0
- data/lib/twitter/rate_limit_status.rb +19 -0
- data/lib/twitter/search.rb +101 -0
- data/lib/twitter/search_result.rb +83 -0
- data/lib/twitter/search_result_info.rb +82 -0
- data/lib/twitter/status.rb +22 -0
- data/lib/twitter/user.rb +37 -0
- data/lib/twitter/version.rb +3 -0
- data/spec/base_spec.rb +139 -0
- data/spec/cli/helper_spec.rb +49 -0
- data/spec/direct_message_spec.rb +35 -0
- data/spec/fixtures/follower_ids.xml +11 -0
- data/spec/fixtures/followers.xml +706 -0
- data/spec/fixtures/friend_ids.xml +12 -0
- data/spec/fixtures/friends.xml +609 -0
- data/spec/fixtures/friends_for.xml +584 -0
- data/spec/fixtures/friends_lite.xml +192 -0
- data/spec/fixtures/friends_timeline.xml +66 -0
- data/spec/fixtures/friendship_already_exists.xml +5 -0
- data/spec/fixtures/friendship_created.xml +12 -0
- data/spec/fixtures/public_timeline.xml +148 -0
- data/spec/fixtures/rate_limit_status.xml +7 -0
- data/spec/fixtures/search_result_info.yml +147 -0
- data/spec/fixtures/search_results.json +1 -0
- data/spec/fixtures/status.xml +25 -0
- data/spec/fixtures/user.xml +38 -0
- data/spec/fixtures/user_timeline.xml +465 -0
- data/spec/search_spec.rb +100 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/status_spec.rb +40 -0
- data/spec/user_spec.rb +42 -0
- data/twitter.gemspec +42 -0
- data/website/css/common.css +47 -0
- data/website/images/terminal_output.png +0 -0
- data/website/index.html +147 -0
- metadata +177 -0
data/spec/search_spec.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Twitter::Search do
|
4
|
+
before do
|
5
|
+
@search = Twitter::Search.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be able to initialize with a search term" do
|
9
|
+
Twitter::Search.new('httparty').query[:q].should include('httparty')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to specify from" do
|
13
|
+
@search.from('jnunemaker').query[:q].should include('from:jnunemaker')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to specify to" do
|
17
|
+
@search.to('jnunemaker').query[:q].should include('to:jnunemaker')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to specify referencing" do
|
21
|
+
@search.referencing('jnunemaker').query[:q].should include('@jnunemaker')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should alias references to referencing" do
|
25
|
+
@search.references('jnunemaker').query[:q].should include('@jnunemaker')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should alias ref to referencing" do
|
29
|
+
@search.ref('jnunemaker').query[:q].should include('@jnunemaker')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be able to specify containing" do
|
33
|
+
@search.containing('milk').query[:q].should include('milk')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should alias contains to containing" do
|
37
|
+
@search.contains('milk').query[:q].should include('milk')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be able to specify hashed" do
|
41
|
+
@search.hashed('twitter').query[:q].should include('#twitter')
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be able to specify the language" do
|
45
|
+
@search.lang('en').query[:lang].should == 'en'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should be able to specify the number of results per page" do
|
49
|
+
@search.per_page(25).query[:rpp].should == 25
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be able to specify the page number" do
|
53
|
+
@search.page(20).query[:page].should == 20
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should be able to specify only returning results greater than an id" do
|
57
|
+
@search.since(1234).query[:since_id].should == 1234
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be able to specify geo coordinates" do
|
61
|
+
@search.geocode('40.757929', '-73.985506', '25mi').query[:geocode].should == '40.757929,-73.985506,25mi'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be able to clear the filters set" do
|
65
|
+
@search.from('jnunemaker').to('oaknd1')
|
66
|
+
@search.clear.query.should == {:q => []}
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should be able to chain methods together" do
|
70
|
+
@search.from('jnunemaker').to('oaknd1').referencing('orderedlist').containing('milk').hashed('twitter').lang('en').per_page(20).since(1234).geocode('40.757929', '-73.985506', '25mi')
|
71
|
+
@search.query[:q].should == ['from:jnunemaker', 'to:oaknd1', '@orderedlist', 'milk', '#twitter']
|
72
|
+
@search.query[:lang].should == 'en'
|
73
|
+
@search.query[:rpp].should == 20
|
74
|
+
@search.query[:since_id].should == 1234
|
75
|
+
@search.query[:geocode].should == '40.757929,-73.985506,25mi'
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "fetching" do
|
79
|
+
before do
|
80
|
+
@response = YAML.load_file(File.dirname(__FILE__) + '/fixtures/search_result_info.yml')
|
81
|
+
@search.class.stub!(:get).and_return(@response)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return results" do
|
85
|
+
@search.class.should_receive(:get).and_return(@response)
|
86
|
+
@search.from('jnunemaker').fetch().should == @response
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should support dot notation" do
|
90
|
+
@search.class.should_receive(:get).and_return(@response)
|
91
|
+
info = @search.from('httparty').fetch()
|
92
|
+
info["max_id"].should == info.max_id
|
93
|
+
info["results"].first["text"].should == info.results.first.text
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should be able to iterate over results" do
|
98
|
+
@search.respond_to?(:each).should == true
|
99
|
+
end
|
100
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
dir = File.dirname(__FILE__)
|
10
|
+
|
11
|
+
$:.unshift(File.join(dir, '/../lib/'))
|
12
|
+
require dir + '/../lib/twitter'
|
13
|
+
|
14
|
+
|
15
|
+
def stdout_for(&block)
|
16
|
+
# Inspired by http://www.ruby-forum.com/topic/58647
|
17
|
+
old_stdout = $stdout
|
18
|
+
$stdout = StringIO.new
|
19
|
+
yield
|
20
|
+
output = $stdout.string
|
21
|
+
$stdout = old_stdout
|
22
|
+
output
|
23
|
+
end
|
data/spec/status_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Twitter::Status do
|
4
|
+
it "should create new status from xml doc" do
|
5
|
+
xml = <<EOF
|
6
|
+
<status>
|
7
|
+
<created_at>Sun May 04 21:59:52 +0000 2008</created_at>
|
8
|
+
<id>803435310</id>
|
9
|
+
<text>Writing tests (rspec) for the twitter gem that all can run. Wish I would have done this when I wrote it years back.</text>
|
10
|
+
<source><a href="http://iconfactory.com/software/twitterrific">twitterrific</a></source>
|
11
|
+
<truncated>false</truncated>
|
12
|
+
<in_reply_to_status_id></in_reply_to_status_id>
|
13
|
+
<in_reply_to_user_id></in_reply_to_user_id>
|
14
|
+
<favorited>false</favorited>
|
15
|
+
<user>
|
16
|
+
<id>4243</id>
|
17
|
+
<name>John Nunemaker</name>
|
18
|
+
<screen_name>jnunemaker</screen_name>
|
19
|
+
<location>Indiana</location>
|
20
|
+
<description>Loves his wife, ruby, notre dame football and iu basketball</description>
|
21
|
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/52619256/ruby_enterprise_shirt_normal.jpg</profile_image_url>
|
22
|
+
<url>http://addictedtonew.com</url>
|
23
|
+
<protected>false</protected>
|
24
|
+
<followers_count>363</followers_count>
|
25
|
+
</user>
|
26
|
+
</status>
|
27
|
+
EOF
|
28
|
+
s = Twitter::Status.new_from_xml(Hpricot.XML(xml))
|
29
|
+
s.id.should == '803435310'
|
30
|
+
s.created_at.should == 'Sun May 04 21:59:52 +0000 2008'
|
31
|
+
s.text.should == 'Writing tests (rspec) for the twitter gem that all can run. Wish I would have done this when I wrote it years back.'
|
32
|
+
s.source.should == '<a href="http://iconfactory.com/software/twitterrific">twitterrific</a>'
|
33
|
+
s.truncated.should == false
|
34
|
+
s.in_reply_to_status_id.should == ''
|
35
|
+
s.in_reply_to_user_id.should == ''
|
36
|
+
s.favorited.should == false
|
37
|
+
s.user.id.should == '4243'
|
38
|
+
s.user.name.should == 'John Nunemaker'
|
39
|
+
end
|
40
|
+
end
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Twitter::User do
|
4
|
+
it "should create new user from xml doc" do
|
5
|
+
xml = <<EOF
|
6
|
+
<user>
|
7
|
+
<id>18713</id>
|
8
|
+
<name>Alex Payne</name>
|
9
|
+
<screen_name>al3x</screen_name>
|
10
|
+
<location>San Francisco, CA</location>
|
11
|
+
<description>Oh, hi. No, I just work here.</description>
|
12
|
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/51961745/al3x_normal.jpg</profile_image_url>
|
13
|
+
<url>http://www.al3x.net</url>
|
14
|
+
<protected>false</protected>
|
15
|
+
<followers_count>2889</followers_count>
|
16
|
+
<status>
|
17
|
+
<created_at>Sun May 04 22:38:39 +0000 2008</created_at>
|
18
|
+
<id>803453211</id>
|
19
|
+
<text>@5dots Yes. Give me about 8 hours. *sigh*</text>
|
20
|
+
|
21
|
+
<source><a href="http://iconfactory.com/software/twitterrific">twitterrific</a></source>
|
22
|
+
<truncated>false</truncated>
|
23
|
+
<in_reply_to_status_id>803450314</in_reply_to_status_id>
|
24
|
+
<in_reply_to_user_id>618923</in_reply_to_user_id>
|
25
|
+
<favorited>false</favorited>
|
26
|
+
|
27
|
+
</status>
|
28
|
+
</user>
|
29
|
+
EOF
|
30
|
+
u = Twitter::User.new_from_xml(Hpricot.XML(xml))
|
31
|
+
u.id.should == '18713'
|
32
|
+
u.name.should =='Alex Payne'
|
33
|
+
u.screen_name.should == 'al3x'
|
34
|
+
u.location.should == 'San Francisco, CA'
|
35
|
+
u.description.should == 'Oh, hi. No, I just work here.'
|
36
|
+
u.profile_image_url.should == 'http://s3.amazonaws.com/twitter_production/profile_images/51961745/al3x_normal.jpg'
|
37
|
+
u.url.should == 'http://www.al3x.net'
|
38
|
+
u.protected.should == false
|
39
|
+
u.followers_count.should == '2889'
|
40
|
+
u.status.text.should == '@5dots Yes. Give me about 8 hours. *sigh*'
|
41
|
+
end
|
42
|
+
end
|
data/twitter.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{twitter}
|
5
|
+
s.version = "0.4.2.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["John Nunemaker"]
|
9
|
+
s.date = %q{2009-02-11}
|
10
|
+
s.default_executable = %q{twitter}
|
11
|
+
s.description = %q{a command line interface for twitter, also a library which wraps the twitter api}
|
12
|
+
s.email = %q{nunemaker@gmail.com}
|
13
|
+
s.executables = ["twitter"]
|
14
|
+
s.extra_rdoc_files = ["bin/twitter", "lib/twitter/base.rb", "lib/twitter/cli/config.rb", "lib/twitter/cli/helpers.rb", "lib/twitter/cli/migrations/20080722194500_create_accounts.rb", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "lib/twitter/cli/migrations/20080722214606_create_configurations.rb", "lib/twitter/cli/models/account.rb", "lib/twitter/cli/models/configuration.rb", "lib/twitter/cli/models/tweet.rb", "lib/twitter/cli.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/rate_limit_status.rb", "lib/twitter/search.rb", "lib/twitter/search_result.rb", "lib/twitter/search_result_info.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "lib/twitter.rb", "README"]
|
15
|
+
s.files = ["bin/twitter", "examples/blocks.rb", "examples/direct_messages.rb", "examples/favorites.rb", "examples/friends_followers.rb", "examples/friendships.rb", "examples/identica_timeline.rb", "examples/location.rb", "examples/posting.rb", "examples/replies.rb", "examples/search.rb", "examples/sent_messages.rb", "examples/timeline.rb", "examples/twitter.rb", "examples/verify_credentials.rb", "History", "lib/twitter/base.rb", "lib/twitter/cli/config.rb", "lib/twitter/cli/helpers.rb", "lib/twitter/cli/migrations/20080722194500_create_accounts.rb", "lib/twitter/cli/migrations/20080722194508_create_tweets.rb", "lib/twitter/cli/migrations/20080722214605_add_account_id_to_tweets.rb", "lib/twitter/cli/migrations/20080722214606_create_configurations.rb", "lib/twitter/cli/models/account.rb", "lib/twitter/cli/models/configuration.rb", "lib/twitter/cli/models/tweet.rb", "lib/twitter/cli.rb", "lib/twitter/direct_message.rb", "lib/twitter/easy_class_maker.rb", "lib/twitter/rate_limit_status.rb", "lib/twitter/search.rb", "lib/twitter/search_result.rb", "lib/twitter/search_result_info.rb", "lib/twitter/status.rb", "lib/twitter/user.rb", "lib/twitter/version.rb", "lib/twitter.rb", "License", "Manifest", "Rakefile", "README", "spec/base_spec.rb", "spec/cli/helper_spec.rb", "spec/direct_message_spec.rb", "spec/fixtures/follower_ids.xml", "spec/fixtures/followers.xml", "spec/fixtures/friend_ids.xml", "spec/fixtures/friends.xml", "spec/fixtures/friends_for.xml", "spec/fixtures/friends_lite.xml", "spec/fixtures/friends_timeline.xml", "spec/fixtures/friendship_already_exists.xml", "spec/fixtures/friendship_created.xml", "spec/fixtures/public_timeline.xml", "spec/fixtures/rate_limit_status.xml", "spec/fixtures/search_result_info.yml", "spec/fixtures/search_results.json", "spec/fixtures/status.xml", "spec/fixtures/user.xml", "spec/fixtures/user_timeline.xml", "spec/search_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/status_spec.rb", "spec/user_spec.rb", "twitter.gemspec", "website/css/common.css", "website/images/terminal_output.png", "website/index.html"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://twitter.rubyforge.org}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Twitter", "--main", "README"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{twitter}
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
|
+
s.summary = %q{a command line interface for twitter, also a library which wraps the twitter api}
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 2
|
27
|
+
|
28
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.1"])
|
30
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.2.4"])
|
31
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<activesupport>, [">= 2.1"])
|
34
|
+
s.add_dependency(%q<httparty>, [">= 0.2.4"])
|
35
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
36
|
+
end
|
37
|
+
else
|
38
|
+
s.add_dependency(%q<activesupport>, [">= 2.1"])
|
39
|
+
s.add_dependency(%q<httparty>, [">= 0.2.4"])
|
40
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
@media screen, projection {
|
2
|
+
/*
|
3
|
+
Copyright (c) 2007, Yahoo! Inc. All rights reserved.
|
4
|
+
Code licensed under the BSD License:
|
5
|
+
http://developer.yahoo.net/yui/license.txt
|
6
|
+
version: 2.2.0
|
7
|
+
*/
|
8
|
+
body {font:13px arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}select, input, textarea {font:99% arial,helvetica,clean,sans-serif;}pre, code {font:115% monospace;*font-size:100%;}body * {line-height:1.22em;}
|
9
|
+
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}/*ol,ul {list-style:none;}*/caption,th {text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;}
|
10
|
+
/* end of yahoo reset and fonts */
|
11
|
+
|
12
|
+
body {color:#333; background:#4b1a1a; line-height:1.3;}
|
13
|
+
p {margin:0 0 20px;}
|
14
|
+
a {color:#4b1a1a;}
|
15
|
+
a:hover {text-decoration:none;}
|
16
|
+
strong {font-weight:bold;}
|
17
|
+
em {font-style:italics;}
|
18
|
+
h1,h2,h3,h4,h5,h6 {font-weight:bold;}
|
19
|
+
h1 {font-size:197%; margin:30px 0; color:#4b1a1a;}
|
20
|
+
h2 {font-size:174%; margin:20px 0; color:#b8111a;}
|
21
|
+
h3 {font-size:152%; margin:10px 0;}
|
22
|
+
h4 {font-size:129%; margin:10px 0;}
|
23
|
+
pre {background:#eee; margin:0 0 20px; padding:20px; border:1px solid #ccc; font-size:100%; overflow:auto;}
|
24
|
+
code {font-size:100%; margin:0; padding:0;}
|
25
|
+
ul, ol {margin:10px 0 10px 25px;}
|
26
|
+
ol li {margin:0 0 10px;}
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
div#wrapper {background:#fff; width:560px; margin:0 auto; padding:20px; border:10px solid #bc8c46; border-width:0 10px;}
|
33
|
+
div#header {position:relative; border-bottom:1px dotted; margin:0 0 10px; padding:0 0 10px;}
|
34
|
+
div#header p {margin:0; padding:0;}
|
35
|
+
div#header h1 {margin:0; padding:0;}
|
36
|
+
ul#nav {position:absolute; top:0; right:0; list-style:none; margin:0; padding:0;}
|
37
|
+
ul#nav li {display:inline; padding:0 0 0 5px;}
|
38
|
+
ul#nav li a {}
|
39
|
+
div#content {}
|
40
|
+
div#footer {margin:40px 0 0; border-top:1px dotted; padding:10px 0 0;}
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
}
|
Binary file
|
data/website/index.html
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Ruby Twitter Gem by John Nunemaker</title>
|
6
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<div id="wrapper">
|
11
|
+
<div id="header">
|
12
|
+
<h1>Twitter</h1>
|
13
|
+
<p>command line tweets and an api wrapper</p>
|
14
|
+
|
15
|
+
<ul id="nav">
|
16
|
+
<li><a href="rdoc/">Docs</a></li>
|
17
|
+
<li><a href="http://github.com/jnunemaker/twitter">Github</a></li>
|
18
|
+
<li><a href="http://jnunemaker.lighthouseapp.com/projects/14843-twitter-gem/overview">Lighthouse</a></li>
|
19
|
+
<li><a href="http://rubyforge.org/projects/twitter/">Rubyforge</a></li>
|
20
|
+
</ul>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<div id="content">
|
24
|
+
<h2>Install</h2>
|
25
|
+
<pre><code>$ sudo gem install twitter</code></pre>
|
26
|
+
<p><small>note: the twitter gem now works with hpricot 0.5+</small></p>
|
27
|
+
|
28
|
+
<h2>API Wrapping</h2>
|
29
|
+
<p>I do my best to keep it easy to use. Below are some code samples showing a few of the methods.</p>
|
30
|
+
|
31
|
+
<pre><code>twit = twit
|
32
|
+
twit.update('watching veronica mars')
|
33
|
+
|
34
|
+
puts "Public Timeline", "=" * 50
|
35
|
+
twit.timeline(:public).each do |s|
|
36
|
+
puts s.text, s.user.name
|
37
|
+
puts
|
38
|
+
end
|
39
|
+
|
40
|
+
puts '', "Friends Timeline", "=" * 50
|
41
|
+
twit.timeline(:friends).each do |s|
|
42
|
+
puts s.text, s.user.name
|
43
|
+
puts
|
44
|
+
end
|
45
|
+
|
46
|
+
puts '', "You and Your Friends Timeline", "=" * 50
|
47
|
+
twit.timeline(:user).each do |s|
|
48
|
+
puts s.text, s.user.name
|
49
|
+
puts
|
50
|
+
end
|
51
|
+
|
52
|
+
puts '', "Your Friends", "=" * 50
|
53
|
+
twit.friends.each do |u|
|
54
|
+
puts u.name, u.status.text
|
55
|
+
puts
|
56
|
+
end
|
57
|
+
|
58
|
+
puts '', "jnunemaker's Friends", "=" * 50
|
59
|
+
twit.friends_for('jnunemaker').each do |u|
|
60
|
+
puts u.name
|
61
|
+
puts
|
62
|
+
end
|
63
|
+
|
64
|
+
puts '', "Your Followers", "=" * 50
|
65
|
+
twit.followers.each do |u|
|
66
|
+
puts u.name
|
67
|
+
puts
|
68
|
+
end
|
69
|
+
</code></pre>
|
70
|
+
|
71
|
+
<h2>Search API Examples</h2>
|
72
|
+
|
73
|
+
<pre><code>#searches all tweets for httparty
|
74
|
+
Twitter::Search.new('httparty').each { |r| puts r.inspect }
|
75
|
+
|
76
|
+
# searches all of jnunemaker's tweets for httparty
|
77
|
+
Twitter::Search.new('httparty').from('jnunemaker').each { |r| puts r.inspect }
|
78
|
+
|
79
|
+
# searches all tweets from jnunemaker to oaknd1
|
80
|
+
Twitter::Search.new.from('jnunemaker').to('oaknd1').each { |r| puts r.inspect }
|
81
|
+
|
82
|
+
# you can also use fetch to actually just get the parsed response
|
83
|
+
Twitter::Search.new.from('jnunemaker').to('oaknd1').fetch()
|
84
|
+
</code></pre>
|
85
|
+
|
86
|
+
<h2>Command Line</h2>
|
87
|
+
|
88
|
+
<p><img src="images/terminal_output.png" alt="Terminal Output" style="width:560px;" /></p>
|
89
|
+
|
90
|
+
<p>I removed the command line dependencies from the gem dependencies list so if you want to use the command line part of the twitter gem be sure to install the following gems as well.</p>
|
91
|
+
|
92
|
+
<pre><code>$ sudo gem install main highline sqlite3-ruby
|
93
|
+
$ sudo gem install activerecord -v 2.2.2</code></pre>
|
94
|
+
|
95
|
+
<p>The first thing you'll want to do is install the database so your account(s) can be stored.</p>
|
96
|
+
|
97
|
+
<pre><code>$ twitter install</code></pre>
|
98
|
+
|
99
|
+
<p>You can always uninstall twitter like this:</p>
|
100
|
+
|
101
|
+
<pre><code>$ twitter uninstall</code></pre>
|
102
|
+
|
103
|
+
<p>Once the twitter database is installed and migrated, you can add accounts like this:</p>
|
104
|
+
|
105
|
+
<pre><code>$ twitter add
|
106
|
+
Add New Account:
|
107
|
+
Username: jnunemaker
|
108
|
+
Password (won't be displayed):
|
109
|
+
Account added.</code></pre>
|
110
|
+
|
111
|
+
<p>You can also list all the accounts you've added.</p>
|
112
|
+
|
113
|
+
<pre><code>$ twitter list
|
114
|
+
Account List
|
115
|
+
* jnunemaker
|
116
|
+
snitch_test</code></pre>
|
117
|
+
|
118
|
+
<p>The * means denotes the account that will be used when posting, befriending, defriending, following, leaving or viewing a timeline.</p>
|
119
|
+
|
120
|
+
<p>To post using the account marked with the *, simply type the following:</p>
|
121
|
+
|
122
|
+
<pre><code>$ twitter post "releasing my new twitter gem"</code></pre>
|
123
|
+
|
124
|
+
<p>That is about it. You can do pretty much anything that you can do with twitter from the command line interface.</p>
|
125
|
+
|
126
|
+
<pre><code>$ twitter</code></pre>
|
127
|
+
|
128
|
+
<p>Will give you a list of all the commands. You can get the help for each command by running twitter [command] -h. </p>
|
129
|
+
|
130
|
+
|
131
|
+
<h2>Support</h2>
|
132
|
+
<p>Conversations welcome in the <a href="http://groups.google.com/group/ruby-twitter-gem">google group</a> and bugs/features over at <a href="http://jnunemaker.lighthouseapp.com/projects/14843-twitter-gem/overview">lighthouse</a></p>
|
133
|
+
</div>
|
134
|
+
|
135
|
+
<div id="footer">
|
136
|
+
<p>Created by <a href="http://addictedtonew.com/about/">John Nunemaker</a></p>
|
137
|
+
</div>
|
138
|
+
</div>
|
139
|
+
|
140
|
+
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
|
141
|
+
<script type="text/javascript">_uacct = "UA-85301-9"; urchinTracker();</script>
|
142
|
+
|
143
|
+
<!-- 103bees.com 'bee' code v1.11 - please do not make any changes! -->
|
144
|
+
<script type="text/javascript" src="http://103bees.com/bees/?bee=3672&fid=5643"></script>
|
145
|
+
<!-- 103bees.com 'bee' code -->
|
146
|
+
</body>
|
147
|
+
</html>
|