2016-03-07 79 views
-2

我初學紅寶石 我嘗試從「octokit寶石」 獲取數據我使用它的ID需要單個存儲庫中的信息,如何從octokit gem中獲取單個存儲庫?

我嘗試它的一個簡單的代碼,但它列出了我所有的倉庫

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=>"[email protected]", :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 

回答

0

它看起來像你當前的代碼返回你有11個倉庫的數據。如果你只想要回數據爲您指定的一個數據:身份證,像這樣做:

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

替換爲您正在尋找實際的ID!

相關問題