module MikuTwitter::Utils

Constants

EXCLUDE_OPTIONS

Attributes

base_path[RW]
twitter_host[RW]

Public Class Methods

new(*a, &b) click to toggle source
Calls superclass method
# File core/plugin/twitter/mikutwitter/utils.rb, line 12
def initialize(*a, &b)
  @twitter_host = 'api.twitter.com'
  @base_path = "https://#{@twitter_host}/1.1".freeze
  super(*a, &b)
end

Public Instance Methods

get_args(args) click to toggle source

連想配列を受け取って、QueryStringを生成して返す

Args

args

QueryStringのHash

Return

URLの?以降のクエリ文字列(“?”含む)。無い場合は空の文字列

# File core/plugin/twitter/mikutwitter/utils.rb, line 23
def get_args(args)
  if (args.keys - EXCLUDE_OPTIONS).empty?
    ''.freeze
  else
    '?'.freeze + args.reject{|k, v|
      EXCLUDE_OPTIONS.include?(k)
    }.map{|k, v|
      "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
    }.to_a.join('&'.freeze)
  end
end
line_accumlator(splitter="\n", &proc) click to toggle source
# File core/plugin/twitter/mikutwitter/utils.rb, line 35
def line_accumlator(splitter="\n", &proc)
  splitter.freeze
  buffer = ""
  push = ->(str){ proc.(buffer + str); buffer = "" }
  ->(chunk){
    if chunk.end_with?(splitter)
      objects = chunk.split(splitter)
      if objects.empty? then push.("") else objects.each(&push) end
    else
      *objects, last = chunk.split(splitter)
      objects.each(&push)
      buffer += (last || "") end } end