1
0
Эх сурвалжийг харах

Update `FORBIDDEN_MESSAGES` for the new already retweeted error message

cf. https://github.com/sferik/twitter/pull/890
Akinori MUSHA 7 жил өмнө
parent
commit
fc38b47f30

+ 19 - 3
app/concerns/twitter_concern.rb

@@ -55,6 +55,22 @@ module TwitterConcern
   end
   end
 end
 end
 
 
-Twitter::Error::FORBIDDEN_MESSAGES = Twitter::Error.send(:remove_const, :FORBIDDEN_MESSAGES).merge(
-  'You have already retweeted this tweet.' => Twitter::Error::AlreadyRetweeted
-).freeze
+class Twitter::Error
+  remove_const :FORBIDDEN_MESSAGES
+
+  FORBIDDEN_MESSAGES = proc do |message|
+    case message
+    when /(?=.*status).*duplicate/i
+      # - "Status is a duplicate."
+      Twitter::Error::DuplicateStatus
+    when /already favorited/i
+      # - "You have already favorited this status."
+      Twitter::Error::AlreadyFavorited
+    when /already retweeted|Share validations failed/i
+      # - "You have already retweeted this Tweet." (Nov 2017-)
+      # - "You have already retweeted this tweet." (?-Nov 2017)
+      # - "sharing is not permissible for this status (Share validations failed)" (-? 2017)
+      Twitter::Error::AlreadyRetweeted
+    end
+  end
+end