module MikuTwitter::ApiCallSupport::Request::Parser

Public Instance Methods

direct_message(dm) click to toggle source
# File core/lib/mikutwitter/api_call_support.rb, line 189
def direct_message(dm)
  cnv = dm.dup
  cnv[:user] = cnv[:sender] = user(dm[:sender])
  cnv[:recipient] = user(dm[:recipient])
  cnv[:exact] = true
  cnv[:created] = Time.parse(dm[:created_at]).localtime
  Mikutter::Twitter::DirectMessage.new_ifnecessary(cnv) end
id(id) click to toggle source
# File core/lib/mikutwitter/api_call_support.rb, line 197
def id(id)
  id end
list(list) click to toggle source
# File core/lib/mikutwitter/api_call_support.rb, line 181
def list(list)
  cnv = list.dup
  cnv[:mode] = list[:mode] == 'public'
  cnv[:user] = user(list[:user])
  cnv[:exact] = true
  cnv[:exact] ? UserList.rewind(cnv) : UserList.new_ifnecessary(cnv)
end
message(msg) click to toggle source
# File core/lib/mikutwitter/api_call_support.rb, line 105
def message(msg)
  cnv = msg.dup
  cnv[:message] = msg[:full_text] || msg[:text]
  cnv[:source] = $1 if cnv[:source].is_a?(String) and cnv[:source].match(/\A<a\s+.*>(.*?)<\/a>\Z/)
  cnv[:created] = (Time.parse(msg[:created_at]).localtime rescue Time.now)
  cnv[:user] = user(msg[:user])
  cnv[:retweet] = message(msg[:retweeted_status]) if msg[:retweeted_status]
  cnv[:exact] = [:created_at, :source, :user, :retweeted_status].all?{|k|msg.has_key?(k)}
  message = cnv[:exact] ? Message.rewind(cnv) : Message.new_ifnecessary(cnv)
  # search/tweets.json の戻り値のquoted_statusのuserがたまにnullだゾ〜
  if msg[:quoted_status].is_a?(Hash) and msg[:quoted_status][:user]
    message(msg[:quoted_status]).add_quoted_by(message) end
  message end
messages(msgs) click to toggle source
# File core/lib/mikutwitter/api_call_support.rb, line 152
def messages(msgs)
  Messages.new msgs.map{ |msg| message(msg) } end
streaming_message(msg) click to toggle source

Streaming APIにはtweet_modeスイッチが効かないとかTwitterアホか!? ↓ #message に、compat modeも受け付けるような改修を入れる ↓ Twitter「Streaming APIのcompatモードはちょっと中身が違うんじゃ」 see: dev.twitter.com/overview/api/upcoming-changes-to-tweets ↓ 死にたいのか!? ↓ 恒例の身売り話が出てくる see: www.afpbb.com/articles/-/3101961 ↓ 死ぬのか!?

# File core/lib/mikutwitter/api_call_support.rb, line 132
def streaming_message(msg)
  cnv = msg.dup
  if msg[:extended_tweet]
    cnv.delete(:extended_tweet)
    cnv.merge!(msg[:extended_tweet])
    cnv[:message] = msg[:extended_tweet][:full_text]
  else
    cnv[:message] = msg[:text]
  end
  cnv[:source] = $1 if cnv[:source].is_a?(String) and cnv[:source].match(/\A<a\s+.*>(.*?)<\/a>\Z/)
  cnv[:created] = (Time.parse(msg[:created_at]).localtime rescue Time.now)
  cnv[:user] = user(msg[:user])
  cnv[:retweet] = streaming_message(msg[:retweeted_status]) if msg[:retweeted_status]
  cnv[:exact] = [:created_at, :source, :user, :retweeted_status].all?{|k|msg.has_key?(k)}
  message = cnv[:exact] ? Message.rewind(cnv) : Message.new_ifnecessary(cnv)
  # search/tweets.json の戻り値のquoted_statusのuserがたまにnullだゾ〜
  if msg[:quoted_status].is_a?(Hash) and msg[:quoted_status][:user]
    streaming_message(msg[:quoted_status]).add_quoted_by(message) end
  message end
user(u) click to toggle source
# File core/lib/mikutwitter/api_call_support.rb, line 155
def user(u)
  cnv = u.convert_key(:screen_name =>:idname, :url => :url)
  cnv[:created] = Time.parse(u[:created_at]).localtime
  cnv[:detail] = u[:description]
  cnv[:protected] = !!u[:protected]
  cnv[:followers_count] = u[:followers_count].to_i
  cnv[:friends_count] = u[:friends_count].to_i
  cnv[:statuses_count] = u[:statuses_count].to_i
  cnv[:notifications] = u[:notifications]
  cnv[:verified] = u[:verified]
  cnv[:following] = u[:following]
  cnv[:exact] = [:created_at, :description, :protected, :followers_count, :friends_count, :verified].all?{|k|u.has_key?(k)}
  # ユーザの見た目が変わっても過去のTweetのアイコン等はそのままにしたいので、新しいUserを作る
  existing_user = User.findbyid(u[:id].to_i, Diva::DataSource::USE_LOCAL_ONLY)
  if visually_changed?(existing_user, cnv)
    User.new(existing_user.to_hash).merge(cnv)
  else
    cnv[:exact] ? User.rewind(cnv) : User.new_ifnecessary(cnv) end end