Skip to content

Instantly share code, notes, and snippets.

View EdwinGuzman's full-sized avatar
🐺
yep

Edwin Guzman EdwinGuzman

🐺
yep
  • The New York Public Library
View GitHub Profile
<div class="api_documentation_all_container container">
<div class="row">
<div class="span9">
<div class="docs-wrapper">
<section id="the-new-york-public-library-digital-collections-api">
<h2>The New York Public Library Digital Collections API</h2>
<p>For more than a century, The New York Public Library has amassed an extraordinary trove of rare and unique material
covering the full spectrum of recorded knowledge. Now, for the first time, significant portions of the Library's
digitized collections are available as machine-readable data: over one million objects and records for you to search,
const makeCurry = (fn) => {
const slice = [].slice;
return function curriedFn() {
let args = slice.call(arguments);
if (args.length < fn.length) {
return () => {
return curriedFn.apply(null, args.concat(slice.call(arguments)));
};
}
import React from 'react';
import PropTypes from 'prop-types';
class Select extends React.Component {
constructor(props) {
super(props);
this.state = {
selected: '',
};
// Search.jsx
class Search extends React.Component {
// Other class functions...
render() {
// Here we can pass the class that we want this “omni-search” component to have as a React prop.
const style = this.props.style;
return (
<form onKeyPress={this.triggerSubmit} method="POST">
var endpoint = 'https://refinery.nypl.org/api/nypl/ndo/v0.1/staff-picks/staff-pick-lists?filter[list-type]=monthly&fields[staff-pick-tag]=tag&fields[staff-pick-age]=age&fields[staff-pick-item]=title,author,catalog-slug,image-slug,tags,ebook-uri&page[size]=1&include=previous-list,next-list,picks.item.tags,picks.age';
var filters = [ { type: 'staff-pick-tag',
id: 'action-packed',
attributes: { tag: 'Action-packed' },
links: { self: 'https://refinery.nypl.org/api/nypl/ndo/v0.1/staff-picks/staff-pick-tags/action-packed' } },
{ type: 'staff-pick-tag',
id: 'adventure',
attributes: { tag: 'Adventure' },
links: { self: 'https://refinery.nypl.org/api/nypl/ndo/v0.1/staff-picks/staff-pick-tags/adventure' } },
// In the New Arrivals app, code reduced for brevity
// utils.js
import { gaUtils } from 'dgx-react-ga';
const trackNewArrivals = gaUtils.trackEvent('New Arrivals');
export default { trackNewArrivals };
// The `trackNewArrivals` function can now be used throughout the app wherever
// utils.js is imported and will track every event with a 'New Arrivals' category.
import ga from 'react-ga';
function GaUtils() {
// other GA related functions
this.trackEvent = category =>
(action, label) => (
// using ES6 object shortcut notation
ga.event({
category,
import ga from 'react-ga';
ga.event({ category: '', action: '', label: '' });
// We can use this function in our applications:
// In the New Arrivals app
ga.event({ category: 'New Arrivals', action: 'click', label: 'list view' });
ga.event({ category: 'New Arrivals', action: 'click', label: 'grid view' });
// In the Staff Picks app
const booksByTolkien = bookBy('J. R. R. Tolkien');
const booksByHerbert = bookBy('Frank Herbert');
// Better than:
const booksByTolkien = (book) => {
console.log(`J. R. R. Tolkien wrote ${book}.`);
}
const booksByHerbert = (book) => {
console.log(`Frank Herbert wrote ${book}.`);
}
const booksByRowling = (book) => {
console.log(`J. K. Rowling wrote ${book}.`);
}