dschn-tweetsy 0.1.0
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/LICENSE +20 -0
- data/README.rdoc +6 -0
- data/VERSION.yml +4 -0
- data/lib/tweetsy/client.rb +140 -0
- data/lib/tweetsy/status.rb +14 -0
- data/lib/tweetsy/user.rb +15 -0
- data/lib/tweetsy.rb +11 -0
- data/spec/client_spec.rb +88 -0
- data/spec/fixtures/friend_ids.xml +6 -0
- data/spec/fixtures/friends_timeline.xml +66 -0
- data/spec/fixtures/user.xml +38 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/status_spec.rb +42 -0
- data/spec/tweetsy_spec.rb +0 -0
- data/spec/user_spec.rb +42 -0
- metadata +71 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 [name of plugin creator]
|
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
data/VERSION.yml
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
module Tweetsy
|
2
|
+
class Client
|
3
|
+
API_HOST = "http://twitter.com"
|
4
|
+
|
5
|
+
def initialize(login, password, options = {})
|
6
|
+
@config = options.merge(:auth => [login, password].join(':'))
|
7
|
+
end
|
8
|
+
|
9
|
+
def authenticate_as(login, password)
|
10
|
+
@config[:auth] = [login, password].join(':')
|
11
|
+
end
|
12
|
+
|
13
|
+
def authenticated?
|
14
|
+
begin
|
15
|
+
result = Curl::Easy.perform("#{API_HOST}/account/verify_credentials.xml") do |curl|
|
16
|
+
default_curl_options(curl)
|
17
|
+
curl.userpwd = @config[:auth]
|
18
|
+
end
|
19
|
+
rescue => e
|
20
|
+
raise CantConnect, "#{e.message}"
|
21
|
+
end
|
22
|
+
|
23
|
+
case result.response_code
|
24
|
+
when 200
|
25
|
+
return true
|
26
|
+
when 401
|
27
|
+
return false
|
28
|
+
else
|
29
|
+
raise CantConnect, "Twitter is returning a: #{result.response_code}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def verify_credentials
|
34
|
+
begin
|
35
|
+
doc = request(:get, '/account/verify_credentials.xml', :auth => true)
|
36
|
+
User.new(doc.at('user'))
|
37
|
+
rescue Tweetsy::Unauthorized
|
38
|
+
return false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_friendship(id_or_screen_name)
|
43
|
+
doc = request(:post, "/friendships/create/#{id_or_screen_name}.xml", :auth => true)
|
44
|
+
User.new(doc.at('user'))
|
45
|
+
end
|
46
|
+
|
47
|
+
def destroy_friendship(id_or_screen_name)
|
48
|
+
doc = request(:post, "/friendships/destroy/#{id_or_screen_name}.xml", :auth => true)
|
49
|
+
User.new(doc.at('user'))
|
50
|
+
end
|
51
|
+
|
52
|
+
def update(status, options = {})
|
53
|
+
form_data = { :status => status }
|
54
|
+
form_data[:source] = options[:source] if options[:source]
|
55
|
+
form_data[:in_reply_to_status_id] = options[:in_reply_to_status_id] if options[:in_reply_to_status_id]
|
56
|
+
|
57
|
+
request(:post, "/statuses/update.xml", :auth => true, :form_data => form_data)
|
58
|
+
|
59
|
+
# Update returns a <status> xml response but we don't need/care about that yet
|
60
|
+
# Can assume if no exceptions it was successful
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
64
|
+
def direct_message(recipient, status)
|
65
|
+
form_data = { :user => recipient, :text => status }
|
66
|
+
request(:post, "/direct_messages/new.xml", :auth => true, :form_data => form_data)
|
67
|
+
end
|
68
|
+
|
69
|
+
def friend_ids(id = nil)
|
70
|
+
endpoint = id ? "/friends/ids/#{id}.xml" : "/friends/ids.xml"
|
71
|
+
|
72
|
+
doc = request(:get, endpoint, :auth => id ? nil : true) # apparently don't need :auth
|
73
|
+
(doc/:ids/:id).inject([]) { |friends_ids, id| friends_ids << id.inner_text.to_i }
|
74
|
+
end
|
75
|
+
|
76
|
+
def user(id_or_screen_name)
|
77
|
+
doc = request(:get, "/users/show/#{id_or_screen_name}.xml", :auth => true)
|
78
|
+
User.new(doc.at('user'))
|
79
|
+
end
|
80
|
+
|
81
|
+
def friends_timeline(options = {})
|
82
|
+
if options[:since] && options[:since].kind_of?(Date)
|
83
|
+
options[:since] = options[:since].strftime('%a, %d-%b-%y %T GMT')
|
84
|
+
end
|
85
|
+
|
86
|
+
doc = request(:get, build_path("/statuses/friends_timeline.xml", options), :auth => true)
|
87
|
+
(doc/:status).inject([]) do |statuses, status|
|
88
|
+
statuses << Status.new(status)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# --------------------------------------------------------------
|
93
|
+
|
94
|
+
def build_path(path, params = {})
|
95
|
+
if params.any?
|
96
|
+
path += "?" + params.inject('') { |str, h| str += "#{CGI.escape(h[0].to_s)}=#{CGI.escape(h[1].to_s)}&" }
|
97
|
+
else
|
98
|
+
path
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def request(method, endpoint, options = {})
|
103
|
+
raise ArgumentError, "#{method} is not a valid request method" unless [:get, :post].include?(method)
|
104
|
+
|
105
|
+
begin
|
106
|
+
result = case method
|
107
|
+
when :get
|
108
|
+
Curl::Easy.perform("#{API_HOST}/#{endpoint}") do |curl|
|
109
|
+
default_curl_options(curl)
|
110
|
+
curl.userpwd = @config[:auth] if options[:auth]
|
111
|
+
end
|
112
|
+
when :post
|
113
|
+
options[:form_data] ||= {}
|
114
|
+
post_fields = options[:form_data].inject([]) { |pfs, fd| pfs << Curl::PostField.content(fd[0].to_s, fd[1]) }
|
115
|
+
|
116
|
+
Curl::Easy.http_post("#{API_HOST}/#{endpoint}", *post_fields) do |curl|
|
117
|
+
default_curl_options(curl)
|
118
|
+
curl.userpwd = @config[:auth] if options[:auth]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
rescue => e
|
122
|
+
raise CantConnect, "#{e.message}"
|
123
|
+
end
|
124
|
+
|
125
|
+
if [200, 304].include?(result.response_code)
|
126
|
+
Hpricot(result.body_str)
|
127
|
+
elsif result.response_code == 401
|
128
|
+
raise Unauthorized
|
129
|
+
elsif result.response_code == 503
|
130
|
+
raise CantConnect, "Service unavailable"
|
131
|
+
else
|
132
|
+
raise CantConnect, "#{result.response_code}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def default_curl_options(curl)
|
137
|
+
curl.timeout = @config[:timeout] || 10
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Tweetsy
|
2
|
+
class Status
|
3
|
+
ATTRIBUTES = [:created_at, :id, :favorited, :text, :user, :source, :truncated, :in_reply_to_status_id, :in_reply_to_user_id, :in_reply_to_screen_name, :text]
|
4
|
+
attr_accessor *ATTRIBUTES
|
5
|
+
|
6
|
+
def initialize(xml)
|
7
|
+
ATTRIBUTES.each do |attr|
|
8
|
+
self.send("#{attr}=", xml.at(attr.to_s).innerHTML) if xml.at(attr.to_s)
|
9
|
+
end
|
10
|
+
|
11
|
+
self.user = User.new(xml.at('user')) if xml.at('user')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/tweetsy/user.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Tweetsy
|
2
|
+
class User
|
3
|
+
ATTRIBUTES = [:id, :name, :screen_name, :location, :description, :url, :profile_image_url, :profile_background_color,
|
4
|
+
:profile_text_color, :profile_link_color, :profile_sidebar_fill_color, :profile_sidebar_border_color,
|
5
|
+
:friends_count, :favourites_count, :statuses_count, :followers_count, :utc_offset, :protected, :status]
|
6
|
+
|
7
|
+
attr_accessor *ATTRIBUTES
|
8
|
+
|
9
|
+
def initialize(xml)
|
10
|
+
ATTRIBUTES.each do |attr|
|
11
|
+
self.send("#{attr}=", xml.at(attr.to_s).innerHTML) if xml.at(attr.to_s)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/tweetsy.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'curb'
|
2
|
+
require 'hpricot'
|
3
|
+
|
4
|
+
module Tweetsy
|
5
|
+
class CantConnect < StandardError; end
|
6
|
+
class Unauthorized < CantConnect; end
|
7
|
+
end
|
8
|
+
|
9
|
+
require File.dirname(__FILE__) + '/tweetsy/user'
|
10
|
+
require File.dirname(__FILE__) + '/tweetsy/status'
|
11
|
+
require File.dirname(__FILE__) + '/tweetsy/client'
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Tweetsy::Client" do
|
4
|
+
before do
|
5
|
+
@base = Tweetsy::Client.new('foo', 'bar')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "authenticated?" do
|
9
|
+
it "should return true on successful authentication (200)" do
|
10
|
+
Curl::Easy.stub!(:perform).and_return(mock(:result, :response_code => 200))
|
11
|
+
@base.authenticated?.should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return false on unsuccessful authentication (401)" do
|
15
|
+
Curl::Easy.stub!(:perform).and_return(mock(:result, :response_code => 401))
|
16
|
+
@base.authenticated?.should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise CantConnect on anything that's not 200 or 401" do
|
20
|
+
Curl::Easy.stub!(:perform).and_return(mock(:result, :response_code => 502))
|
21
|
+
lambda {
|
22
|
+
@base.authenticated?
|
23
|
+
}.should raise_error(Tweetsy::CantConnect)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "being initialized" do
|
28
|
+
it "should require email and password" do
|
29
|
+
lambda { Tweetsy::Client.new }.should raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "timelines" do
|
34
|
+
it "should be able to retrieve friends timeline" do
|
35
|
+
data = open(File.dirname(__FILE__) + '/fixtures/friends_timeline.xml').read
|
36
|
+
@base.should_receive(:request).and_return(Hpricot::XML(data))
|
37
|
+
@base.friends_timeline.size.should == 3
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "social graphs" do
|
42
|
+
it "should be able to retrieve friend_ids" do
|
43
|
+
data = open(File.dirname(__FILE__) + '/fixtures/friend_ids.xml').read
|
44
|
+
@base.should_receive(:request).and_return(Hpricot::XML(data))
|
45
|
+
@base.friend_ids.size.should == 3
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "users" do
|
50
|
+
it "should be able to get single user" do
|
51
|
+
data = open(File.dirname(__FILE__) + '/fixtures/user.xml').read
|
52
|
+
@base.should_receive(:request).and_return(Hpricot::XML(data))
|
53
|
+
@base.user('4243').name.should == 'John Nunemaker'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "request" do
|
58
|
+
it "should raise ArgumentError on bad arguments" do
|
59
|
+
lambda {
|
60
|
+
@base.request(:whoa, 'nada')
|
61
|
+
}.should raise_error(ArgumentError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should raise Unauthorized on 401" do
|
65
|
+
response = mock(:response, :response_code => 401)
|
66
|
+
Curl::Easy.stub!(:perform).and_return(response)
|
67
|
+
|
68
|
+
lambda {
|
69
|
+
@base.request(:get, 'blah')
|
70
|
+
}.should raise_error(Tweetsy::Unauthorized)
|
71
|
+
|
72
|
+
lambda {
|
73
|
+
@base.request(:get, 'blah')
|
74
|
+
}.should raise_error(Tweetsy::CantConnect)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should raise CantConnect on anything that isn't 200 or 304 response" do
|
78
|
+
[401, 503, 504, 505, nil].each do |code|
|
79
|
+
response = mock(:response, :response_code => code)
|
80
|
+
Curl::Easy.stub!(:perform).and_return(response)
|
81
|
+
|
82
|
+
lambda {
|
83
|
+
@base.request(:get, 'blah')
|
84
|
+
}.should raise_error(Tweetsy::CantConnect)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<statuses type="array">
|
3
|
+
<status>
|
4
|
+
<created_at>Sun May 04 21:59:52 +0000 2008</created_at>
|
5
|
+
<id>803435310</id>
|
6
|
+
<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>
|
7
|
+
<source><a href="http://iconfactory.com/software/twitterrific">twitterrific</a></source>
|
8
|
+
<truncated>false</truncated>
|
9
|
+
<in_reply_to_status_id></in_reply_to_status_id>
|
10
|
+
<in_reply_to_user_id></in_reply_to_user_id>
|
11
|
+
<favorited>false</favorited>
|
12
|
+
<user>
|
13
|
+
<id>4243</id>
|
14
|
+
<name>John Nunemaker</name>
|
15
|
+
<screen_name>jnunemaker</screen_name>
|
16
|
+
<location>Indiana</location>
|
17
|
+
<description>Loves his wife, ruby, notre dame football and iu basketball</description>
|
18
|
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/52619256/ruby_enterprise_shirt_normal.jpg</profile_image_url>
|
19
|
+
<url>http://addictedtonew.com</url>
|
20
|
+
<protected>false</protected>
|
21
|
+
<followers_count>363</followers_count>
|
22
|
+
</user>
|
23
|
+
</status>
|
24
|
+
<status>
|
25
|
+
<created_at>Sun May 04 20:38:39 +0000 2008</created_at>
|
26
|
+
<id>803397135</id>
|
27
|
+
<text>This weekend's open-window apartment cleaning serenade to the corner of 4th & Harrison: My Morning Jacket.</text>
|
28
|
+
<source>web</source>
|
29
|
+
<truncated>false</truncated>
|
30
|
+
<in_reply_to_status_id></in_reply_to_status_id>
|
31
|
+
<in_reply_to_user_id></in_reply_to_user_id>
|
32
|
+
<favorited>false</favorited>
|
33
|
+
<user>
|
34
|
+
<id>18713</id>
|
35
|
+
<name>Alex Payne</name>
|
36
|
+
<screen_name>al3x</screen_name>
|
37
|
+
<location>San Francisco, CA</location>
|
38
|
+
<description>Oh, hi. No, I just work here.</description>
|
39
|
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/51961745/al3x_normal.jpg</profile_image_url>
|
40
|
+
<url>http://www.al3x.net</url>
|
41
|
+
<protected>false</protected>
|
42
|
+
<followers_count>2891</followers_count>
|
43
|
+
</user>
|
44
|
+
</status>
|
45
|
+
<status>
|
46
|
+
<created_at>Sun May 04 19:46:01 +0000 2008</created_at>
|
47
|
+
<id>803372400</id>
|
48
|
+
<text>Experiencing Philz Coffee for the first time. It's 2 blocks from my house. Don't know what took me so long.</text>
|
49
|
+
<source>web</source>
|
50
|
+
<truncated>false</truncated>
|
51
|
+
<in_reply_to_status_id></in_reply_to_status_id>
|
52
|
+
<in_reply_to_user_id></in_reply_to_user_id>
|
53
|
+
<favorited>false</favorited>
|
54
|
+
<user>
|
55
|
+
<id>20</id>
|
56
|
+
<name>Evan Williams</name>
|
57
|
+
<screen_name>ev</screen_name>
|
58
|
+
<location>San Francisco, CA, US</location>
|
59
|
+
<description>Founder of Obvious </description>
|
60
|
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/14019652/ev-sky_normal.jpg</profile_image_url>
|
61
|
+
<url>http://evhead.com</url>
|
62
|
+
<protected>false</protected>
|
63
|
+
<followers_count>11463</followers_count>
|
64
|
+
</user>
|
65
|
+
</status>
|
66
|
+
</statuses>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<user>
|
3
|
+
<id>4243</id>
|
4
|
+
<name>John Nunemaker</name>
|
5
|
+
<screen_name>jnunemaker</screen_name>
|
6
|
+
<location>Indiana</location>
|
7
|
+
<description>Loves his wife, ruby, notre dame football and iu basketball</description>
|
8
|
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/52619256/ruby_enterprise_shirt_normal.jpg</profile_image_url>
|
9
|
+
<url>http://addictedtonew.com</url>
|
10
|
+
<protected>false</protected>
|
11
|
+
<followers_count>363</followers_count>
|
12
|
+
<profile_background_color>FFFFFF</profile_background_color>
|
13
|
+
<profile_text_color>000000</profile_text_color>
|
14
|
+
|
15
|
+
<profile_link_color>000000</profile_link_color>
|
16
|
+
<profile_sidebar_fill_color>FD8C19</profile_sidebar_fill_color>
|
17
|
+
<profile_sidebar_border_color>F82500</profile_sidebar_border_color>
|
18
|
+
<friends_count>109</friends_count>
|
19
|
+
<created_at>Sun Aug 13 22:56:06 +0000 2006</created_at>
|
20
|
+
<favourites_count>18</favourites_count>
|
21
|
+
<utc_offset>-18000</utc_offset>
|
22
|
+
<time_zone>Indiana (East)</time_zone>
|
23
|
+
<profile_background_image_url>http://s3.amazonaws.com/twitter_production/profile_background_images/2349547/logo.jpg</profile_background_image_url>
|
24
|
+
<profile_background_tile>false</profile_background_tile>
|
25
|
+
<following>false</following>
|
26
|
+
<notifications>false</notifications>
|
27
|
+
<statuses_count>1981</statuses_count>
|
28
|
+
<status>
|
29
|
+
<created_at>Sun May 04 21:59:52 +0000 2008</created_at>
|
30
|
+
<id>803435310</id>
|
31
|
+
<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>
|
32
|
+
<source><a href="http://iconfactory.com/software/twitterrific">twitterrific</a></source>
|
33
|
+
<truncated>false</truncated>
|
34
|
+
<in_reply_to_status_id></in_reply_to_status_id>
|
35
|
+
<in_reply_to_user_id></in_reply_to_user_id>
|
36
|
+
<favorited>false</favorited>
|
37
|
+
</status>
|
38
|
+
</user>
|
data/spec/spec_helper.rb
ADDED
data/spec/status_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Tweetsy::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
|
+
<in_reply_to_screen_name>blah</in_reply_to_screen_name>
|
15
|
+
<favorited>false</favorited>
|
16
|
+
<user>
|
17
|
+
<id>4243</id>
|
18
|
+
<name>John Nunemaker</name>
|
19
|
+
<screen_name>jnunemaker</screen_name>
|
20
|
+
<location>Indiana</location>
|
21
|
+
<description>Loves his wife, ruby, notre dame football and iu basketball</description>
|
22
|
+
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/52619256/ruby_enterprise_shirt_normal.jpg</profile_image_url>
|
23
|
+
<url>http://addictedtonew.com</url>
|
24
|
+
<protected>false</protected>
|
25
|
+
<followers_count>363</followers_count>
|
26
|
+
</user>
|
27
|
+
</status>
|
28
|
+
EOF
|
29
|
+
s = Tweetsy::Status.new(Hpricot.XML(xml))
|
30
|
+
s.id.should == '803435310'
|
31
|
+
s.created_at.should == 'Sun May 04 21:59:52 +0000 2008'
|
32
|
+
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.'
|
33
|
+
s.source.should == '<a href="http://iconfactory.com/software/twitterrific">twitterrific</a>'
|
34
|
+
s.truncated.should == "false"
|
35
|
+
s.in_reply_to_status_id.should == ''
|
36
|
+
s.in_reply_to_user_id.should == ''
|
37
|
+
s.in_reply_to_screen_name.should == 'blah'
|
38
|
+
s.favorited.should == "false"
|
39
|
+
s.user.id.should == '4243'
|
40
|
+
s.user.name.should == 'John Nunemaker'
|
41
|
+
end
|
42
|
+
end
|
File without changes
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Tweetsy::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 = Tweetsy::User.new(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
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dschn-tweetsy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dustin Schneider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: dustin@genevate.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- README.rdoc
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/tweetsy
|
29
|
+
- lib/tweetsy/client.rb
|
30
|
+
- lib/tweetsy/status.rb
|
31
|
+
- lib/tweetsy/user.rb
|
32
|
+
- lib/tweetsy.rb
|
33
|
+
- spec/client_spec.rb
|
34
|
+
- spec/fixtures
|
35
|
+
- spec/fixtures/friend_ids.xml
|
36
|
+
- spec/fixtures/friends_timeline.xml
|
37
|
+
- spec/fixtures/user.xml
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- spec/status_spec.rb
|
40
|
+
- spec/tweetsy_spec.rb
|
41
|
+
- spec/user_spec.rb
|
42
|
+
- LICENSE
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/dschn/tweetsy
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --inline-source
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.2.0
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: TODO
|
70
|
+
test_files: []
|
71
|
+
|