Skip to content
Browse files

Break up Twitter::User class into 4 classes

* Twitter::BasicUser
* Twitter::SourceUser
* Twitter::TargetUser
* Twitter::User
  • Loading branch information...
1 parent 437f0d1 commit 9d4f1e5dc4001adb124d07584f64322555e0e73c @sferik committed
View
4 README.md
@@ -160,9 +160,9 @@ vulnerabilities are discovered.
Here are some fun facts about the 3.0 release:
-* The entire library is implemented in just 2,216 lines of code
+* The entire library is implemented in just 2,245 lines of code
* With over 5,000 lines of specs, the spec-to-code ratio is well over 2:1
-* The spec suite contains 643 examples and runs in under 2 seconds on a MacBook
+* The spec suite contains 657 examples and runs in under 2 seconds on a MacBook
* This project has 100% C0 code coverage (the tests execute every line of
source code at least once)
* At the time of release, this library is comprehensive: you can request all
View
10 lib/twitter/basic_user.rb
@@ -0,0 +1,10 @@
+require 'twitter/identity'
+
+module Twitter
+ class BasicUser < Twitter::Identity
+ attr_reader :following, :screen_name
+
+ alias following? following
+
+ end
+end
View
7 lib/twitter/relationship.rb
@@ -1,17 +1,18 @@
require 'twitter/base'
-require 'twitter/user'
+require 'twitter/source_user'
+require 'twitter/target_user'
module Twitter
class Relationship < Twitter::Base
# @return [Twitter::User]
def source
- @source ||= Twitter::User.fetch_or_create(@attrs[:source]) unless @attrs[:source].nil?
+ @source ||= Twitter::SourceUser.fetch_or_create(@attrs[:source]) unless @attrs[:source].nil?
end
# @return [Twitter::User]
def target
- @target ||= Twitter::User.fetch_or_create(@attrs[:target]) unless @attrs[:target].nil?
+ @target ||= Twitter::TargetUser.fetch_or_create(@attrs[:target]) unless @attrs[:target].nil?
end
# Update the attributes of a Relationship
View
15 lib/twitter/source_user.rb
@@ -0,0 +1,15 @@
+require 'twitter/basic_user'
+
+module Twitter
+ class SourceUser < BasicUser
+ attr_reader :all_replies, :blocking, :can_dm, :followed_by, :marked_spam,
+ :notifications_enabled, :want_retweets
+ alias all_replies? all_replies
+ alias blocking? blocking
+ alias can_dm? can_dm
+ alias followed_by? followed_by
+ alias marked_spam? marked_spam
+ alias notifications_enabled? notifications_enabled
+ alias want_retweets? want_retweets
+ end
+end
View
8 lib/twitter/target_user.rb
@@ -0,0 +1,8 @@
+require 'twitter/basic_user'
+
+module Twitter
+ class TargetUser < BasicUser
+ attr_reader :followed_by
+ alias followed_by? followed_by
+ end
+end
View
30 lib/twitter/user.rb
@@ -1,32 +1,25 @@
+require 'twitter/basic_user'
require 'twitter/core_ext/hash'
require 'twitter/creatable'
-require 'twitter/identity'
require 'twitter/status'
module Twitter
- class User < Twitter::Identity
+ class User < BasicUser
include Twitter::Creatable
- attr_reader :all_replies, :blocking, :can_dm, :connections,
- :contributors_enabled, :default_profile, :default_profile_image,
- :description, :favourites_count, :follow_request_sent, :followed_by,
- :followers_count, :following, :friends_count, :geo_enabled,
- :is_translator, :lang, :listed_count, :location, :marked_spam, :name,
- :notifications, :notifications_enabled, :profile_background_color,
- :profile_background_image_url, :profile_background_image_url_https,
- :profile_background_tile, :profile_image_url, :profile_image_url_https,
+ attr_reader :connections, :contributors_enabled, :default_profile,
+ :default_profile_image, :description, :favourites_count,
+ :follow_request_sent, :followers_count, :friends_count, :geo_enabled,
+ :is_translator, :lang, :listed_count, :location, :name, :notifications,
+ :profile_background_color, :profile_background_image_url,
+ :profile_background_image_url_https, :profile_background_tile,
:profile_link_color, :profile_sidebar_border_color,
:profile_sidebar_fill_color, :profile_text_color,
- :profile_use_background_image, :protected, :screen_name, :statuses_count,
- :time_zone, :url, :utc_offset, :verified, :want_retweets
- alias all_replies? all_replies
- alias blocking? blocking
- alias can_dm? can_dm
+ :profile_use_background_image, :protected, :statuses_count, :time_zone,
+ :url, :utc_offset, :verified
alias contributors_enabled? contributors_enabled
alias default_profile? default_profile
alias default_profile_image? default_profile_image
alias follow_request_sent? follow_request_sent
- alias following? following
- alias followed_by? followed_by
alias favorite_count favourites_count
alias favorites_count favourites_count
alias favourite_count favourites_count
@@ -34,9 +27,7 @@ class User < Twitter::Identity
alias friend_count friends_count
alias geo_enabled? geo_enabled
alias is_translator? is_translator
- alias marked_spam? marked_spam
alias notifications? notifications
- alias notifications_enabled? notifications_enabled
alias profile_background_tile? profile_background_tile
alias profile_use_background_image? profile_use_background_image
alias protected? protected
@@ -48,7 +39,6 @@ class User < Twitter::Identity
alias update_count statuses_count
alias updates_count statuses_count
alias verified? verified
- alias want_retweets? want_retweets
# Return the URL to the user's profile image
#
View
23 spec/twitter/basic_user_spec.rb
@@ -0,0 +1,23 @@
+require 'helper'
+
+describe Twitter::BasicUser do
+
+ describe "#==" do
+ it "returns true when objects IDs are the same" do
+ saved_search = Twitter::BasicUser.new(:id => 1, :name => "foo")
+ other = Twitter::BasicUser.new(:id => 1, :name => "bar")
+ (saved_search == other).should be_true
+ end
+ it "returns false when objects IDs are different" do
+ saved_search = Twitter::BasicUser.new(:id => 1)
+ other = Twitter::BasicUser.new(:id => 2)
+ (saved_search == other).should be_false
+ end
+ it "returns false when classes are different" do
+ saved_search = Twitter::BasicUser.new(:id => 1)
+ other = Twitter::Identity.new(:id => 1)
+ (saved_search == other).should be_false
+ end
+ end
+
+end
View
4 spec/twitter/relationship_spec.rb
@@ -5,7 +5,7 @@
describe "#source" do
it "returns a User when source is set" do
source = Twitter::Relationship.new(:relationship => {:source => {:id => 7505382}}).source
- source.should be_a Twitter::User
+ source.should be_a Twitter::SourceUser
end
it "returns nil when source is not set" do
source = Twitter::Relationship.new.source
@@ -16,7 +16,7 @@
describe "#target" do
it "returns a User when target is set" do
target = Twitter::Relationship.new(:relationship => {:target => {:id => 7505382}}).target
- target.should be_a Twitter::User
+ target.should be_a Twitter::TargetUser
end
it "returns nil when target is not set" do
target = Twitter::Relationship.new.target
View
23 spec/twitter/source_user_spec.rb
@@ -0,0 +1,23 @@
+require 'helper'
+
+describe Twitter::SourceUser do
+
+ describe "#==" do
+ it "returns true when objects IDs are the same" do
+ saved_search = Twitter::SourceUser.new(:id => 1, :name => "foo")
+ other = Twitter::SourceUser.new(:id => 1, :name => "bar")
+ (saved_search == other).should be_true
+ end
+ it "returns false when objects IDs are different" do
+ saved_search = Twitter::SourceUser.new(:id => 1)
+ other = Twitter::SourceUser.new(:id => 2)
+ (saved_search == other).should be_false
+ end
+ it "returns false when classes are different" do
+ saved_search = Twitter::SourceUser.new(:id => 1)
+ other = Twitter::Identity.new(:id => 1)
+ (saved_search == other).should be_false
+ end
+ end
+
+end
View
23 spec/twitter/target_user_spec.rb
@@ -0,0 +1,23 @@
+require 'helper'
+
+describe Twitter::TargetUser do
+
+ describe "#==" do
+ it "returns true when objects IDs are the same" do
+ saved_search = Twitter::TargetUser.new(:id => 1, :name => "foo")
+ other = Twitter::TargetUser.new(:id => 1, :name => "bar")
+ (saved_search == other).should be_true
+ end
+ it "returns false when objects IDs are different" do
+ saved_search = Twitter::TargetUser.new(:id => 1)
+ other = Twitter::TargetUser.new(:id => 2)
+ (saved_search == other).should be_false
+ end
+ it "returns false when classes are different" do
+ saved_search = Twitter::TargetUser.new(:id => 1)
+ other = Twitter::Identity.new(:id => 1)
+ (saved_search == other).should be_false
+ end
+ end
+
+end

0 comments on commit 9d4f1e5

Please sign in to comment.
Something went wrong with that request. Please try again.