From c9bf100eedc89aee43689c17f160025e0f40cfb4 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Wed, 13 Jun 2018 07:45:19 +0900 Subject: [PATCH] Follow Twitter API which again changed the message for already retweeted error (#890) --- lib/twitter/error.rb | 21 +++++++++++++++------ spec/fixtures/already_retweeted.json | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/twitter/error.rb b/lib/twitter/error.rb index 4e8ee35e5..a6c8b6c0f 100644 --- a/lib/twitter/error.rb +++ b/lib/twitter/error.rb @@ -74,12 +74,21 @@ class Error < StandardError 504 => Twitter::Error::GatewayTimeout, }.freeze - FORBIDDEN_MESSAGES = { - 'Status is a duplicate.' => Twitter::Error::DuplicateStatus, - 'You have already favorited this status.' => Twitter::Error::AlreadyFavorited, - 'You have already retweeted this tweet.' => Twitter::Error::AlreadyRetweeted, - 'sharing is not permissible for this status (Share validations failed)' => Twitter::Error::AlreadyRetweeted, - }.freeze + 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 # If error code is missing see https://dev.twitter.com/overview/api/response-codes module Code diff --git a/spec/fixtures/already_retweeted.json b/spec/fixtures/already_retweeted.json index 147291410..f2e61eac7 100644 --- a/spec/fixtures/already_retweeted.json +++ b/spec/fixtures/already_retweeted.json @@ -1 +1 @@ -{"errors":"You have already retweeted this tweet."} \ No newline at end of file +{"errors":"You have already retweeted this Tweet."}