Coder Social home page Coder Social logo

gh's Introduction

gh

GitHub API

Linux Build Status Windows Build status CRAN RStudio mirror downloads

Minimalistic client to access GitHub's API v3.

Installation

devtools::install_github("gaborcsardi/gh")

Usage

library(gh)

Use the gh() function to access all API endpoints. The endpoints are listed in the documentation.

The first argument of gh() is the endpoint. Note that the leading slash must be included as well. Parameters can be passed as extra arguments. E.g.

my_repos <- gh("/user/repos", type = "public")
vapply(my_repos, "[[", "", "name")
#>  [1] "ask"                   "background"           
#>  [3] "baseimports"           "bundler"              
#>  [5] "clisymbols"            "closure"              
#>  [7] "cmaker"                "cranky"               
#>  [9] "crayon"                "datastore"            
#> [11] "decima"                "disposables"          
#> [13] "docstrings"            "dot-emacs"            
#> [15] "dotenv"                "elasticsearch-jetty"  
#> [17] "ensurethat"            "falsy"                
#> [19] "feast"                 "flock"                
#> [21] "gaborcsardi.github.io" "gh"                   
#> [23] "ISA"                   "json2r6"              
#> [25] "keypress"              "locker"               
#> [27] "macBriain"             "mason"                
#> [29] "mason.rpkg"            "massig"

The JSON result sent by the API is converted to an R object.

If the end point itself has parameters, these can also be passed as extra arguments:

j_repos <- gh("/users/:username/repos", username = "jeroenooms")
vapply(j_repos, "[[", "", "name")
#>  [1] "apps"                  "blog"                 
#>  [3] "cheerio"               "cmark"                
#>  [5] "commonmark"            "curl"                 
#>  [7] "daff"                  "data"                 
#>  [9] "devtools"              "DiagrammeR"           
#> [11] "docdbi"                "docplyr"              
#> [13] "dplyr"                 "encode"               
#> [15] "evaluate"              "fib"                  
#> [17] "git"                   "httr"                 
#> [19] "icu"                   "interactivity"        
#> [21] "ipyr"                  "IRkernel"             
#> [23] "jeroenooms.github.com" "JJcorr"               
#> [25] "js"                    "JSlibs"               
#> [27] "jsonlite"              "lausd-data"           
#> [29] "lawn"                  "leaflet-pip"

POST, PATCH, PUT and DELETE requests

POST, PATCH, PUT, and DELETE requests can be sent by including the HTTP verb before the endpoint, in the first argument. E.g. to create a repository:

new_repo <- gh("POST /user/repos", name = "my-new-repo-for-gh-testing")

and then delete it:

gh("DELETE /repos/:owner/:repo", owner = "gaborcsardi",
   repo = "my-new-repo-for-gh-testing")

Tokens

By default the GITHUB_TOKEN environment variable is used. Alternatively, one can set the .token argument of gh().

Pagination

Supply the page parameter to get subsequent pages:

my_repos2 <- gh("GET /users/:username/repos", username = "gaborcsardi",
  type = "public", page = 2)
vapply(my_repos2, "[[", "", "name")
#>  [1] "MISO"                   "my-old-MISO"           
#>  [3] "parsedate"              "pingr"                 
#>  [5] "pkgconfig"              "playground"            
#>  [7] "pretty"                 "prettyunits"           
#>  [9] "printr"                 "procrustes"            
#> [11] "progress"               "r-font"                
#> [13] "r-wiki-engine"          "ratlab"                
#> [15] "rcorpora"               "Rcpp"                  
#> [17] "redsvd"                 "regexp"                
#> [19] "resume"                 "rfunctions"            
#> [21] "roxygen"                "rsmith"                
#> [23] "rsync-mirror"           "scidb"                 
#> [25] "Semantic-plotting-in-R" "snap"                  
#> [27] "spark"                  "splicing"              
#> [29] "staticdocs"             "tab"

License

MIT © Gabor Csardi.

gh's People

Contributors

gaborcsardi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.