module MikuTwitter::APIShortcuts

Constants

RELATIONAL_DEFAULT

Public Class Methods

defcursorpager(method_name, api, parser, key, key_convert = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 19
def self.defcursorpager(method_name, api, parser, key, key_convert = {})
  define_method(method_name){ |args = {}|
    key_convert.each{ |src, dst|
      args[dst] = args[src] if args.has_key?(src) }
    cursor_pager(self/api, parser, key, args) } end
defshortcut(method_name, api, parser, key_convert = {}, defaults = {}) { |api, parser| ... } click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 9
def self.defshortcut(method_name, api, parser, key_convert = {}, defaults = {})
  if block_given?
    define_method(method_name, &yield(api, parser))
  else
    define_method(method_name){ |args = {}|
      args = args.to_hash
      key_convert.each{ |src, dst|
        args[dst] = args[src] if args.has_key?(src) }
      (self/api).__send__(parser, defaults.merge(args)) } end end

Public Instance Methods

add_list(list) click to toggle source

list = {

:user => User(自分)
:name => String
:description => String
:public => boolean

}

# File core/lib/mikutwitter/api_shortcuts.rb, line 189
def add_list(list)
  (self/"lists/create").list( name: list[:name].to_s[0, 25],
                                      description: list[:description].to_s[0, 100],
                                      mode: (list[:mode] ? 'public' : 'private')) end
destroy(args) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 167
def destroy(args)
  id = args[:id]
  (self/"statuses/destroy"/id).message end
direct_messages(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 59
def direct_messages(args = {})
  (self/:direct_messages).direct_messages({:count => 200}.merge(args)) end
filter_stream(params={}, &chunk) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 213
def filter_stream(params={}, &chunk)
  stream("https://stream.twitter.com/1.1/statuses/filter.json", params, &chunk) end
followers(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 56
def followers(args = {})
  idlist2userlist(followers_id(RELATIONAL_DEFAULT.merge(args))) end
followings(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 53
def followings(args = {})
  idlist2userlist(friends_id(RELATIONAL_DEFAULT.merge(args))) end
list_members(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 89
def list_members(args = {})
  args[:list_id] = args[:id] if args[:id]
  request = self/'lists/members'
  request.force_oauth = !args[:public]
  cursor_pager(request, :paged_users, :users, args) end
list_statuses(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 101
def list_statuses(args = {})
  args[:list_id] = args[:id] if args[:id]
  request = self/"lists/statuses"
  request.force_oauth = !args[:public]
  request.messages(args)
end
list_subscriptions(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 85
def list_subscriptions(args = {})
  args[:user_id] = args[:user][:id] if args[:user]
  cursor_pager(self/'lists/subscriptions', :paged_lists, :lists, {count: 1000}.merge(args)) end
list_user_followers(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 95
def list_user_followers(args = {})
  args[:user_id] = args[:id] if args[:id]
  request = self/'lists/memberships'
  request.force_oauth = args[:filter_to_owned_lists] || !args[:public]
  cursor_pager(request, :paged_lists, :lists, args) end
lists(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 82
def lists(args = {})
  (self/'lists/list').lists(args) end
post(message)
Alias for: update
retweet(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 163
def retweet(args = {})
  id = args[:id]
  (self/"statuses/retweet"/id).message end
retweeted_users(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 108
def retweeted_users(args = {})
  args[:id] = args[:status_id] if args[:status_id]
  request = self/:statuses/:retweeters/:ids
  cursor_pager(request, :paged_ids, :ids, args).next do |ids|
    Thread.new{ User.findbyid(ids) } end end
search_destroy(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 76
def search_destroy(args = {})
  id = args[:id]
  args = args.dup
  args.delete(:id)
  (self/"saved_searches/destroy"/id).json(args) end
sent_direct_messages(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 62
def sent_direct_messages(args = {})
  (self/'direct_messages/sent').direct_messages({:count => 200}.merge(args)) end
status_show(args = {}) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 69
def status_show(args = {})
  (self/"statuses/show").message({cache: true}.merge(args)) end
update(message) click to toggle source

POST関連

# File core/lib/mikutwitter/api_shortcuts.rb, line 122
def update(message)
  text = message[:message]
  replyto = message[:replyto] && Message.generate(message[:replyto])
  receiver = message[:receiver] && User.generate(message[:receiver])
  iolist = message[:mediaiolist]
  is_reply = !!(receiver || replyto)
  data = {:status => text }
  data[:in_reply_to_user_id] = receiver.id if receiver
  data[:in_reply_to_status_id] = replyto.id if replyto
  if is_reply && UserConfig[:auto_populate_reply_metadata]
    data[:auto_populate_reply_metadata] = true
    forecast_receivers = Set.new
    exclude_receivers = Set.new
    if replyto
      replyto.each_ancestor.each do |m|
        forecast_receivers << m.user
        forecast_receivers.merge(m.receive_user_screen_names.map{|sn| User.findbyidname(sn) }.compact)
      end
    end
    mentions = text.match(%r[\A((?:@[a-zA-Z0-9_]+\s+)+)])
    if mentions
      specific_screen_names = mentions[1].split(/\s+/).map{|s|s[1, s.size]}
      exclude_receivers += forecast_receivers.reject{|u| specific_screen_names.include?(u.idname) }
      text = [*(specific_screen_names - forecast_receivers.map(&:idname)).map{|s|"@#{s}"}, text[mentions.end(0),text.size]].join(' '.freeze)
      data[:status] = text
    end
    data[:exclude_reply_user_ids] = exclude_receivers.map(&:id).join(',') unless exclude_receivers.empty?
  end
  if iolist and !iolist.empty?
    Deferred.when(*iolist.collect{ |io| upload_media(io) }).next{|media_list|
      data[:media_ids] = media_list.map{|media| media['media_id'] }.join(",")
      (self/'statuses/update').message(data) }
  else
    attachment_url = text.match(%r[\A(.+?)\s+(https?://twitter.com/(?:#!/)?(?:[a-zA-Z0-9_]+)/status(?:es)?/(?:\d+)(?:\?.*)?)\Z]m)
    if attachment_url
      data[:attachment_url] = attachment_url[2]
      data[:status] = attachment_url[1]
    end
    (self/'statuses/update').message(data) end end
Also aliased as: post
update_list(list) click to toggle source
# File core/lib/mikutwitter/api_shortcuts.rb, line 194
def update_list(list)
  (self/"lists/update").list( list_id: list[:id],
                              name: list[:name].to_s[0, 25],
                              description: list[:description].to_s[0, 100],
                              mode: (list[:mode] ? 'public' : 'private')) end
userstream(params={}, &chunk) click to toggle source

Streaming API関連

# File core/lib/mikutwitter/api_shortcuts.rb, line 210
def userstream(params={}, &chunk)
  stream("https://userstream.twitter.com/1.1/user.json", params, &chunk) end