# NOT RUN {
## Repositories of a user, these are equivalent
gh("/users/hadley/repos")
gh("/users/{username}/repos", username = "hadley")
## Starred repositories of a user
gh("/users/hadley/starred")
gh("/users/{username}/starred", username = "hadley")
# }
# NOT RUN {
## Create a repository, needs a token in GITHUB_PAT (or GITHUB_TOKEN)
## environment variable
gh("POST /user/repos", name = "foobar")
# }
# NOT RUN {
## Issues of a repository
gh("/repos/hadley/dplyr/issues")
gh("/repos/{owner}/{repo}/issues", owner = "hadley", repo = "dplyr")
## Automatic pagination
users <- gh("/users", .limit = 50)
length(users)
# }
# NOT RUN {
## Access developer preview of Licenses API (in preview as of 2015-09-24)
gh("/licenses") # used to error code 415
gh("/licenses", .accept = "application/vnd.github.drax-preview+json")
# }
# NOT RUN {
## Access Github Enterprise API
## Use GITHUB_API_URL environment variable to change the default.
gh("/user/repos", type = "public", .api_url = "https://github.foobar.edu/api/v3")
# }
# NOT RUN {
## Use I() to force body part to be sent as an array, even if length 1
## This works whether assignees has length 1 or > 1
assignees <- "gh_user"
assignees <- c("gh_user1", "gh_user2")
gh("PATCH /repos/OWNER/REPO/issues/1", assignees = I(assignees))
# }
# NOT RUN {
## There are two ways to send JSON data. One is that you supply one or
## more objects that will be converted to JSON automatically via
## jsonlite::toJSON(). In this case sometimes you need to use
## jsonlite::unbox() because fromJSON() creates lists from scalar vectors
## by default. The Content-Type header is automatically added in this
## case. For example this request turns on GitHub Pages, using this
## API: https://docs.github.com/v3/repos/pages/#enable-a-pages-site
gh::gh(
"POST /repos/{owner}/{repo}/pages",
owner = "gaborcsardi",
repo = "playground",
source = list(
branch = jsonlite::unbox("master"),
path = jsonlite::unbox("/docs")
),
.send_headers = c(Accept = "application/vnd.github.switcheroo-preview+json")
)
## The second way is to handle the JSON encoding manually, and supply it
## as a raw vector in an unnamed argument, and also a Content-Type header:
body <- '{ "source": { "branch": "master", "path": "/docs" } }'
gh::gh(
"POST /repos/{owner}/{repo}/pages",
owner = "gaborcsardi",
repo = "playground",
charToRaw(body),
.send_headers = c(
Accept = "application/vnd.github.switcheroo-preview+json",
"Content-Type" = "application/json"
)
)
# }
Run the code above in your browser using DataLab