mateothegreat
7/3/2016 - 4:43 PM

Demo using bash and cURL to create a gist with several files.

Demo using bash and cURL to create a gist with several files.

{
  "url": "https://api.github.com/gists/265b6f0f516c78807702b275daa918fe",
  "forks_url": "https://api.github.com/gists/265b6f0f516c78807702b275daa918fe/forks",
  "commits_url": "https://api.github.com/gists/265b6f0f516c78807702b275daa918fe/commits",
  "id": "265b6f0f516c78807702b275daa918fe",
  "git_pull_url": "https://gist.github.com/265b6f0f516c78807702b275daa918fe.git",
  "git_push_url": "https://gist.github.com/265b6f0f516c78807702b275daa918fe.git",
  "html_url": "https://gist.github.com/265b6f0f516c78807702b275daa918fe",
  "files": {
    "github.api.gists.create.examples.cURL.sh": {
      "filename": "github.api.gists.create.examples.cURL.sh",
      "type": "application/x-sh",
      "language": "Shell",
      "raw_url": "https://gist.githubusercontent.com/mateothegreat/265b6f0f516c78807702b275daa918fe/raw/32581edc8daec90b4b2c2a5c8fb8b17837181e08/github.api.gists.create.examples.cURL.sh",
      "size": 390,
      "truncated": false,
      "content": "#!/bin/bash\n\n# You can preset your git variables used on the command line\n# into your ~/.bashrc (or elsewhere) to make them easier to\n# user later.\n\n#export GIT_OAUTH_TOKEN=\"<this should already exist from before>\"\n#export GIT_USERNAME=\"mateothegreat\"\n\n curl \"Content-Type: application/json\" --data @github.api.gists.create.json \"https://api.github.com/gists?access_token=$GIT_OAUTH_TOKEN\"\n"
    },
    "github.api.gists.create.examples.payload.json": {
      "filename": "github.api.gists.create.examples.payload.json",
      "type": "application/json",
      "language": "JSON",
      "raw_url": "https://gist.githubusercontent.com/mateothegreat/265b6f0f516c78807702b275daa918fe/raw/8c8d30293aa00e7833a1c5b5dbc2ef89a15aaf0a/github.api.gists.create.examples.payload.json",
      "size": 184,
      "truncated": false,
      "content": "{\n  \"description\": \"Demo using cURL to create a gist.\",\n  \"public\": true,\n  \"files\": {\n    \"github.api.gists.create.payload.json\": {\n      \"content\": \"String file contents\"\n    }\n  }\n}"
    }
  },
  "public": true,
  "created_at": "2016-07-03T16:21:33Z",
  "updated_at": "2016-07-03T16:21:33Z",
  "description": "Demo using bash and cURL to create a gist with several files.",
  "comments": 0,
  "user": null,
  "comments_url": "https://api.github.com/gists/265b6f0f516c78807702b275daa918fe/comments",
  "owner": {
    "login": "mateothegreat",
    "id": 11623940,
    "avatar_url": "https://avatars.githubusercontent.com/u/11623940?v=3",
    "gravatar_id": "",
    "url": "https://api.github.com/users/mateothegreat",
    "html_url": "https://github.com/mateothegreat",
    "followers_url": "https://api.github.com/users/mateothegreat/followers",
    "following_url": "https://api.github.com/users/mateothegreat/following{/other_user}",
    "gists_url": "https://api.github.com/users/mateothegreat/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/mateothegreat/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/mateothegreat/subscriptions",
    "organizations_url": "https://api.github.com/users/mateothegreat/orgs",
    "repos_url": "https://api.github.com/users/mateothegreat/repos",
    "events_url": "https://api.github.com/users/mateothegreat/events{/privacy}",
    "received_events_url": "https://api.github.com/users/mateothegreat/received_events",
    "type": "User",
    "site_admin": false
  },
  "forks": [

  ],
  "history": [
    {
      "user": {
        "login": "mateothegreat",
        "id": 11623940,
        "avatar_url": "https://avatars.githubusercontent.com/u/11623940?v=3",
        "gravatar_id": "",
        "url": "https://api.github.com/users/mateothegreat",
        "html_url": "https://github.com/mateothegreat",
        "followers_url": "https://api.github.com/users/mateothegreat/followers",
        "following_url": "https://api.github.com/users/mateothegreat/following{/other_user}",
        "gists_url": "https://api.github.com/users/mateothegreat/gists{/gist_id}",
        "starred_url": "https://api.github.com/users/mateothegreat/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/mateothegreat/subscriptions",
        "organizations_url": "https://api.github.com/users/mateothegreat/orgs",
        "repos_url": "https://api.github.com/users/mateothegreat/repos",
        "events_url": "https://api.github.com/users/mateothegreat/events{/privacy}",
        "received_events_url": "https://api.github.com/users/mateothegreat/received_events",
        "type": "User",
        "site_admin": false
      },
      "version": "0408d3ab45a0c6e0e92279153de0ef1613c6a371",
      "committed_at": "2016-07-03T16:21:33Z",
      "change_status": {
        "total": 19,
        "additions": 19,
        "deletions": 0
      },
      "url": "https://api.github.com/gists/265b6f0f516c78807702b275daa918fe/0408d3ab45a0c6e0e92279153de0ef1613c6a371"
    }
  ],
  "truncated": false
}
#!/bin/bash

# You can preset your git variables used on the command line
# into your ~/.bashrc (or elsewhere) to make them easier to
# user later.

#export GIT_OAUTH_TOKEN="<this should already exist from before>"
#export GIT_USERNAME="mateothegreat"

 curl "Content-Type: application/json" --data @github.api.gists.create.examples.json "https://api.github.com/gists?access_token=$GIT_OAUTH_TOKEN"
{
  "description": "Demo using cURL to create a gist.",
  "public": true,
  "files": {
    "github.api.gists.create.payload.json": {
      "content": "String file contents"
    }
  }
}
Book: <..>
Title: Show by example
Author: Matthew Davis <matthew@appsoa.io>