LoginSignup
0

More than 5 years have passed since last update.

GitHubユーザーが公開しているプロジェクトの一覧が欲しい

Last updated at Posted at 2015-06-03

Google Samples にあるサンプルの一覧を取得したかったが、Webから一つ一つコピペするのも面倒なので、APIを叩いて一括して取ってくる方法があるはずだろうと思って調べた時のメモ

curlを使うのが一番簡単そう。 Getting Started | GitHub APIRepositories | GitHub API を見ながら。

$ curl https://api.github.com/users/googlesamples/repos
{
    "id": 23589308,
    "name": "android-ActionBarCompat-Basic",
    "full_name": "googlesamples/android-ActionBarCompat-Basic",
    "owner": {
...

これが得られればあとはフィルタをかければいい。

まずファイルに落として

$ curl https://api.github.com/users/googlesamples/repos > googlesamples.json

名前を出力する rubyのフィルタを書く。

require 'json'

File.open(ARGV[0], "r") do |f|
  json = f.read
  result = JSON.parse(json)

  result.each do |prj|
   puts prj["name"]
  end

end

実行。

$ ruby filter.rb googlesamples.json
android-ActionBarCompat-Basic
android-ActionBarCompat-ListPopupMenu
android-ActionBarCompat-ShareActionProvider
android-ActionBarCompat-Styled
android-ActiveNotifications
android-ActivityInstrumentation
android-ActivitySceneTransitionBasic
...

Jolly good.

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0