aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2016-10-06 04:36:38 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2016-10-06 05:05:03 +0900
commit9d39aaf18ffc12155cafc292675f8f9827fff666 (patch)
treef11dc9b86c08d683ed3022ade1535a8ca7c5a53d /core
parent538da0c3c3f870a71e20dd04ecf9b8bc58d0d534 (diff)
downloadmikutter-9d39aaf18ffc12155cafc292675f8f9827fff666.tar.gz
UserのpermalinkからUserを作成する手段 refs #866
Diffstat (limited to 'core')
-rw-r--r--core/user.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/core/user.rb b/core/user.rb
index 918b0a3d..7d247c82 100644
--- a/core/user.rb
+++ b/core/user.rb
@@ -33,7 +33,22 @@ class User < Retriever::Model
field.int :statuses_count
field.int :friends_count
- handle %r[\Ahttps?://twitter.com/[a-zA-Z0-9_]+/?\Z].freeze
+ handle %r[\Ahttps?://twitter.com/[a-zA-Z0-9_]+/?\Z] do |uri|
+ match = %r[\Ahttps?://twitter.com/(?<screen_name>[a-zA-Z0-9_]+)/?\Z].match(uri.to_s)
+ notice match.inspect
+ if match
+ user = findbyidname(match[:screen_name], Retriever::DataSource::USE_LOCAL_ONLY)
+ if user
+ user
+ else
+ Thread.new do
+ findbyidname(match[:screen_name], Retriever::DataSource::USE_ALL)
+ end
+ end
+ else
+ raise Retriever::RetrieverError, "id##{match[:screen_name]} does not exist in #{self}."
+ end
+ end
def self.system
Mikutter::System::User.system end