From 9645fde056353a4fe85a64632ed58f043cfe8871 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 28 Nov 2011 07:21:06 -0800 Subject: [PATCH] Remove twitter-text dependency and related methods 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. --- README.md | 19 ------------ lib/twitter/status.rb | 25 ---------------- spec/twitter/status_spec.rb | 58 ------------------------------------- twitter.gemspec | 1 - 4 files changed, 103 deletions(-) diff --git a/README.md b/README.md index 388a90912..a988d7ba7 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/twitter/status.rb b/lib/twitter/status.rb index 56f9b0000..08dfaeba2 100644 --- a/lib/twitter/status.rb +++ b/lib/twitter/status.rb @@ -6,7 +6,6 @@ require 'twitter/metadata' require 'twitter/place' require 'twitter/user' -require 'twitter-text' module Twitter class Status < Twitter::Base @@ -26,14 +25,6 @@ def ==(other) super || (other.class == self.class && other.id == self.id) end - # @return [Array] - 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] def expanded_urls @expanded_urls ||= Array(@attrs['entities']['urls']).map do |url| @@ -46,11 +37,6 @@ def geo @geo ||= Twitter::GeoFactory.new(@attrs['geo']) unless @attrs['geo'].nil? end - # @return [Array] - 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| @@ -68,21 +54,10 @@ def place @place ||= Twitter::Place.new(@attrs['place']) unless @attrs['place'].nil? end - # @return [Array] - 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] - def user_mentions - @user_mentions ||= Twitter::Extractor.extract_mentioned_screen_names(@attrs['text']) unless @attrs['text'].nil? - end - alias :mentions :user_mentions - end end diff --git a/spec/twitter/status_spec.rb b/spec/twitter/status_spec.rb index 1e2065e98..c4c453fc6 100644 --- a/spec/twitter/status_spec.rb +++ b/spec/twitter/status_spec.rb @@ -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'}] @@ -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 @@ -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 @@ -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 diff --git a/twitter.gemspec b/twitter.gemspec index da5801014..2c6a4cf9f 100644 --- a/twitter.gemspec +++ b/twitter.gemspec @@ -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'