Skip to content

Commit

Permalink
Remove twitter-text dependency and related methods
Browse files Browse the repository at this point in the history
This was causing more trouble than it was worth, mostly due to
twitter-text's hard $KCODE requirement.

Technically, removing methods should require a major version bump but
since these methods were just added in 2.0.0, I'm consciously breaking
the API. This may come back to bite me someday, but I can't think of a
better solution.

Users who want to continue to use these methods can extend the
Twitter::Status class.
  • Loading branch information
sferik committed Nov 28, 2011
1 parent 63dc814 commit 9645fde
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 103 deletions.
19 changes: 0 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,6 @@ method. This unifies the library's interfaces and will make the code easier to
maintain over time. As a result, you can no longer build queries by chaining
methods (ARel-style). The new syntax is more consistent and concise.

Version 2 also includes some advanced Tweet-parsing methods, for example:

# Fetch the Tweet at https://twitter.com/twitter/statuses/76360760606986241
status = Twitter.status(76360760606986241)

# Return all hashtags in the Tweet
status.hashtags #=> ["Photos"]

# Return all URLs in the Tweet
status.urls #=> ["http://t.co/qbJx26r"]

# Return all users mentioned in the Tweet
status.user_mentions #=> []

Tweet parsing is performed by [twitter-text][], Twitter's official text
processing library, so it should be consistent with all other Twitter services.

[twitter-text]: https://github.com/twitter/twitter-text-rb

This version also introduces object equivalence, so objects that are logically
equivalent are considered equal, even if they don't occupy the same address in
memory, for example:
Expand Down
25 changes: 0 additions & 25 deletions lib/twitter/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require 'twitter/metadata'
require 'twitter/place'
require 'twitter/user'
require 'twitter-text'

module Twitter
class Status < Twitter::Base
Expand All @@ -26,14 +25,6 @@ def ==(other)
super || (other.class == self.class && other.id == self.id)
end

# @return [Array<String>]
def all_urls
@all_urls ||= begin
all_urls = [urls, expanded_urls].flatten.compact.uniq
all_urls.length > 0 ? all_urls : nil
end
end

# @return [Array<String>]
def expanded_urls
@expanded_urls ||= Array(@attrs['entities']['urls']).map do |url|
Expand All @@ -46,11 +37,6 @@ def geo
@geo ||= Twitter::GeoFactory.new(@attrs['geo']) unless @attrs['geo'].nil?
end

# @return [Array<String>]
def hashtags
@hashtags ||= Twitter::Extractor.extract_hashtags(@attrs['text']) unless @attrs['text'].nil?
end

# @return [Array]
def media
@media ||= Array(@attrs['entities']['media']).map do |media|
Expand All @@ -68,21 +54,10 @@ def place
@place ||= Twitter::Place.new(@attrs['place']) unless @attrs['place'].nil?
end

# @return [Array<String>]
def urls
@urls ||= Twitter::Extractor.extract_urls(@attrs['text']) unless @attrs['text'].nil?
end

# @return [Twitter::User]
def user
@user ||= Twitter::User.new(@attrs.dup['user'].merge('status' => @attrs.except('user'))) unless @attrs['user'].nil?
end

# @return [Array<String>]
def user_mentions
@user_mentions ||= Twitter::Extractor.extract_mentioned_screen_names(@attrs['text']) unless @attrs['text'].nil?
end
alias :mentions :user_mentions

end
end
58 changes: 0 additions & 58 deletions spec/twitter/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@
end
end

describe "#all_urls" do
it "should return urls in the text, and in all fields from the entities" do
urls = [{'url' => 'http://t.co/example', 'expanded_url' => 'http://example.com'}]
status_attributes = { 'text' => "This tweet contains a http://t.co/example.", 'entities' => {'urls' => urls} }
all_urls = Twitter::Status.new(status_attributes).all_urls
all_urls.should be_an Array
all_urls.first.should == "http://t.co/example"
all_urls.last.should == "http://example.com"
end
it "should return nil when not set" do
all_urls = Twitter::Status.new.all_urls
all_urls.should be_nil
end
it "should not include nil" do
urls = [{'url' => 'http://t.co/example', 'expanded_url' => nil}]
status_attributes = { 'text' => "This tweet contains a http://t.co/example.", 'entities' => {'urls' => urls} }
all_urls = Twitter::Status.new(status_attributes).all_urls
all_urls.should be_an Array
all_urls.should == ["http://t.co/example"]
end
end

describe "#expanded_urls" do
it "should return the expanded urls" do
urls = [{'expanded_url' => 'http://example.com'}]
Expand Down Expand Up @@ -77,18 +55,6 @@
end
end

describe "#hashtags" do
it "should return hashtags" do
hashtags = Twitter::Status.new('text' => "This Tweet contains a #hashtag.").hashtags
hashtags.should be_an Array
hashtags.first.should == "hashtag"
end
it "should return nil when not set" do
hashtags = Twitter::Status.new.hashtags
hashtags.should be_nil
end
end

describe "#media" do
it "should return media" do
media = Twitter::Status.new('entities' => {'media' => [{'type' => 'photo'}]}).media
Expand Down Expand Up @@ -123,18 +89,6 @@
end
end

describe "#urls" do
it "should return urls" do
urls = Twitter::Status.new('text' => "This Tweet contains a http://example.com.").urls
urls.should be_an Array
urls.first.should == "http://example.com"
end
it "should return nil when not set" do
urls = Twitter::Status.new.urls
urls.should be_nil
end
end

describe "#user" do
it "should return a User when user is set" do
user = Twitter::Status.new('user' => {}).user
Expand All @@ -151,16 +105,4 @@
end
end

describe "#user_mentions" do
it "should return urls" do
user_mentions = Twitter::Status.new('text' => "This Tweet contains a @mention.").user_mentions
user_mentions.should be_an Array
user_mentions.first.should == "mention"
end
it "should return nil when not set" do
user_mentions = Twitter::Status.new.user_mentions
user_mentions.should be_nil
end
end

end
1 change: 0 additions & 1 deletion twitter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Gem::Specification.new do |gem|
gem.add_dependency 'faraday', '~> 0.7'
gem.add_dependency 'multi_json', '~> 1.0'
gem.add_dependency 'simple_oauth', '~> 0.1'
gem.add_dependency 'twitter-text', '~> 1.4'
gem.add_development_dependency 'json'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rdiscount'
Expand Down

0 comments on commit 9645fde

Please sign in to comment.