如何从octokit gem获取单个存储库?

时间:2016-03-07 07:07:54

标签: ruby-on-rails ruby ruby-on-rails-4 rubygems octokit

我是红宝石的初学者 我试图从" octokit gem"中获取数据。 我需要使用它的id,

的单个存储库的信息

我尝试了一个简单的代码,但它列出了我的所有存储库

require 'octokit'


=> true
2.2.4 :003 > user = Octokit.user 'parth1634'
 => {:login=>"parth1634", :id=>8487101, :avatar_url=>"https://avatars.githubusercontent.com/u/8487101?v=3", :gravatar_id=>"", :url=>"https://api.github.com/users/parth1634", :html_url=>"https://github.com/parth1634", :followers_url=>"https://api.github.com/users/parth1634/followers", :following_url=>"https://api.github.com/users/parth1634/following{/other_user}", :gists_url=>"https://api.github.com/users/parth1634/gists{/gist_id}", :starred_url=>"https://api.github.com/users/parth1634/starred{/owner}{/repo}", :subscriptions_url=>"https://api.github.com/users/parth1634/subscriptions", :organizations_url=>"https://api.github.com/users/parth1634/orgs", :repos_url=>"https://api.github.com/users/parth1634/repos", :events_url=>"https://api.github.com/users/parth1634/events{/privacy}", :received_events_url=>"https://api.github.com/users/parth1634/received_events", :type=>"User", :site_admin=>false, :name=>"Parth Patel", :company=>"BoTree Technologies.Pvt.Ltd", :blog=>"https://parthpatelsblog.wordpress.com/", :location=>"Visnagar, Gujarat.", :email=>"parth1634@gmail.com", :hireable=>nil, :bio=>nil, :public_repos=>10, :public_gists=>1, :followers=>3, :following=>6, :created_at=>2014-08-19 05:23:02 UTC, :updated_at=>2016-03-02 04:22:46 UTC}
2.2.4 :004 > repos = user.rels[:repos].get.data

1 个答案:

答案 0 :(得分:0)

看起来您当前的代码会返回您拥有的11个repos的数据。如果您只想返回指定了:id的一个数据的数据,请执行以下操作:

repos = user.rels[:repos].get.data.select {|r| r[:id] == 35797521 }

替换为您正在寻找的实际ID!