Skip to content

Instantly share code, notes, and snippets.

@DanielFGray
Last active September 1, 2017 02:35
Show Gist options
  • Save DanielFGray/d05aa6518bc17af4790af020bab83be8 to your computer and use it in GitHub Desktop.
Save DanielFGray/d05aa6518bc17af4790af020bab83be8 to your computer and use it in GitHub Desktop.
request all a user's gists
const { curry } = require('ramda')
const { Observable } = require('rxjs/Observable')
require('rxjs/add/observable/interval')
require('rxjs/add/operator/concatMap')
require('rxjs/add/operator/takeWhile')
require('rxjs/add/operator/reduce')
const request$ = curry((base, header, method, endpoint, query = {}) =>
Observable.defer(() => request(method, `${base}${endpoint}`).set(header).query(query))
.map(x => x.body))
const github$ = request$('https://api.github.com/', {
Authorization: `token ${secrets.github.key}`,
})
Observable.interval(1)
.concatMap(page => github$('get', `users/${secrets.github.user}/gists`, { page }))
.takeWhile(data => data.length > 0)
.reduce((p, c) => p.concat(c), [])
.subscribe(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment