module Plugin::Bitly

Constants

APIKEY
SHRINKED_MATCHER
USER

Public Instance Methods

apikey() click to toggle source

bitly API keyを返す

# File core/plugin/bitly/bitly.rb, line 19
def apikey
  if UserConfig[:bitly_apikey] == '' or not UserConfig[:bitly_apikey]
    APIKEY
  else
    UserConfig[:bitly_apikey]
  end end
expand_url_many(urls) click to toggle source
# File core/plugin/bitly/bitly.rb, line 26
def expand_url_many(urls)
  query = "login=#{user}&apiKey=#{apikey}&" + urls.map{ |url|
    "shortUrl=#{CGI.escape(url)}" }.join('&')
  3.times do
    result = begin
               JSON.parse(Net::HTTP.get("api.bit.ly", "/v3/expand?#{query}"))
             rescue Exception
               nil end
    if result and result['status_code'].to_i == 200
      return Hash[ *result['data']['expand'].map{|token|
                     [token['short_url'], token['long_url']] }.flatten ] end
  end
end
user() click to toggle source

bitlyユーザ名を返す

# File core/plugin/bitly/bitly.rb, line 11
def user
  if UserConfig[:bitly_user] == '' or not UserConfig[:bitly_user]
    USER
  else
    UserConfig[:bitly_user]
  end end