新手问题 不用 gem 写个 timeline widget

cconev · 2012年09月02日 · 2257 次阅读

对照看了 RubyChina 的 Github 代码库的 API,和 Twitter 的 user_timeline 是一致的,代码改个字段名称直接就能套用。可是看了国内的微博,多套了一层 statuses,然后我就弄不懂了,如:

http://open.t.163.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E7%94%A8%E6%88%B7%E7%9A%84%E5%BE%AE%E4%B8%93%E6%A0%8F%E5%88%97%E8%A1%A8%28statuses/user_column_timeline%29&oldid=32679

# Github 项目
  def github_repositories
    return [] if self.github.blank?
    count = 14
    cache_key = "github_repositories:#{self.github}+#{count}+v2"
    items = Rails.cache.read(cache_key)
    if items == nil
      begin
        json = open("https://api.github.com/users/#{self.github}/repos?type=owner&sort=pushed").read
      rescue => e
        Rails.logger.error("Github Repositiory fetch Error: #{e}")
        items = []
        Rails.cache.write(cache_key, items, :expires_in => 15.days)
        return items
      end

      items = JSON.parse(json)
      items = items.collect do |a1|
        {
          :name => a1["name"],
          :url => a1["html_url"],
          :watchers => a1["watchers"],
          :description => a1["description"]
        }
      end
      items = items.sort { |a1,a2| a2[:watchers] <=> a1[:watchers] }.take(count)
      Rails.cache.write(cache_key, items, :expires_in => 7.days)
    end
    items
  end

关键的代码段:

items = items.collect do |a1|
  {
    :name => a1["name"],
    :url => a1["html_url"],
    :watchers => a1["watchers"],
    :description => a1["description"]
  }

要怎么改改呢?

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号