Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Flet committed Nov 29, 2016
0 parents commit 8400c19
Show file tree
Hide file tree
Showing 101 changed files with 33,053 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .gitignore
@@ -0,0 +1,35 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

lib/
.DS_Store
jsconfig.json

test/testdb.sqlite
.nyc_output
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,5 @@
## Changelog

__1.0.0__

- Initial release
61 changes: 61 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,61 @@
# Contributing Guidelines

Contributions welcome!

**Before spending lots of time on something, ask for feedback on your idea first!**

Please search issues and pull requests before adding something new to avoid duplicating efforts and conversations.

In addition to improving the project by refactoring code and implementing relevant features, this project welcomes the following types of contributions:

- **Ideas**: participate in an issue thread or start your own to have your voice heard.
- **Writing**: contribute your expertise in an area by helping expand the included content.
- **Copy editing**: fix typos, clarify language, and generally improve the quality of the content.
- **Formatting**: help keep content easy to read with consistent formatting.

## Installing

Fork and clone the repo, then `npm install` to install all dependencies.

## Testing

Tests are run with `npm test`. Unless you're creating a failing test to increase test coverage or show a problem, please make sure all tests are passing before submitting a pull request.

## Code Style

[![semistandard][semistandard-image]][semistandard-url]

This repository uses [`semistandard`][semistandard-url] to maintain code style and consistency and avoid style arguments. `npm test` runs `semistandard` so you don't have to!

[semistandard-image]: https://cdn.rawgit.com/Flet/semistandard/master/badge.svg
[semistandard-url]: https://github.com/Flet/semistandard
[semisemistandard-image]: https://cdn.rawgit.com/Flet/semisemistandard/master/badge.svg
[semisemistandard-url]: https://github.com/Flet/semisemistandard

---

# Collaborating Guidelines

**This is an OPEN Open Source Project.**

## What?

Individuals making significant and valuable contributions are given commit access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

## Rules

There are a few basic ground rules for collaborators:

1. **No `--force` pushes** or modifying the Git history in any way.
1. **Non-master branches** ought to be used for ongoing work.
1. **External API changes and significant modifications** ought to be subject to an **internal pull request** to solicit feedback from other collaborators.
1. Internal pull requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor.
1. Contributors should attempt to adhere to the prevailing code style.

## Releases

Declaring formal releases remains the prerogative of the project maintainer.

## Changes to this arrangement

This is an experiment and feedback is welcome! This document may also be subject to pull requests or changes by collaborators where you believe you have something valuable to add or change.
163 changes: 163 additions & 0 deletions LICENSE-DATASET.md

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions LICENSE-SOURCE.md
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © `2016` `Best Buy`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
73 changes: 73 additions & 0 deletions README.md
@@ -0,0 +1,73 @@
# Best Buy API Playground

### What the API Playground Is

The Best Buy API Playground is an API training tool for students, educators and other learners to explore the possibilities of a fully functional [RESTful API](http://www.restapitutorial.com/) in a simple, non-production environment. API Playground was developed by Best Buy and makes use of a [Creative Commons licensed](https://creativecommons.org/licenses/by-nc/4.0/) dataset including product and store-related information - making it easy for teaching APIs (both consumption and creation) to classrooms with realistic data. The playground supports full [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) (Create Read Update Delete) operations for all API endpoints and does not require any external services nor databases.

**Please note: This system is for educational and training purposes only. It behaves differently than Best Buy's actual API, uses an older version of our catalog, and does not represent any real-world data.**

API Playground makes use of solid API standards and best practices. It is designed to allow you to learn about an API framework in a local environment. Beyond being a fully functional API, it also includes several top-notch API tools such as the [Feathers Framework](http://feathersjs.com), [Mocha test framework](https://mochajs.org/), [Swagger](http://swagger.io/) and [Postman](https://www.getpostman.com/).

### What the API Playground Isn't

API Playground does not give users access to usable data from BestBuy.com or any production Best Buy APIs. For information on accessing Best Buy's complete API suite, check out https://developer.bestbuy.com/. API Playground isn't designed to be used in production environments, although many of its building blocks are production grade.

API Playground does not represent any guarantees of patterns or design principles used at Best Buy.

## Getting Started

Make sure you have [NodeJS](https://nodejs.org/) installed (we require version 4 or newer).

```bash
git clone https://github.com/bestbuy/api-playground/
cd api-playground
npm install
npm start
# Best Buy API Playground started at http://localhost:3030
```

Now open http://localhost:3030 in your browser to begin exploring the API. From there we'll guide you on using tools such as Swagger and Postman to get meaningful experience interacting with APIs.

## Things That Power the Playground

Beyond all the great libraries (which are mentioned within the [package.json](package.json), such as [Sequelize](http://sequelizejs.com/)), here are some of the crucial components and resources that made assembling with API Playground possible:

__[Feathers](http://feathersjs.com)__

This project uses Feathers, an open source web framework for building modern real-time applications. Feathers does the majority of the heavy lifting within the application. It is an amazing framework that we highly recommend and enjoy using.

__[Swagger](http://swagger.io/)__

Swagger is a wonderful way to describe APIs, and coupled with [Swagger UI](https://github.com/swagger-api/swagger-ui) creates a great way to interact with them. It offers a nice sanity check that basically boils down to, "If you can't describe it in Swagger, it probably isn't a RESTful API."

__[Postman](https://www.getpostman.com/)__

Writing an API is only half the challenge, and consuming it is the other half. Within API Playground we include a [Postman Collection](https://www.getpostman.com/docs/collections) that helps developers learn how to interact with the API Playground for all CRUD operations and a couple interesting API operations. Another great aspect of Postman is the [generate code](https://www.getpostman.com/docs/creating_curl) functionality, which leads to repeatable cURL commands as well as usable code in most popular languages.

__[GeoNames](https://www.getpostman.com/)__

GeoNames has been around since 2002 and provides many useful datasets to help people make meaningful products. Particularly relevant to API Playground is their [postal code service](http://www.geonames.org/postal-codes/postal-codes-us.html), which enables this API to do semi-accurate location searching.

__[18F API Standards](https://github.com/18F/api-standards)__

The work of defining an API is difficult, and creating consistency within an organization is a large challenge. We really appreciate the work that the 18F has done to help set standards. In addition to the 18F, Microsoft also has a [great set of API guidelines](https://github.com/Microsoft/api-guidelines). Both of these sets are recommended readings for anyone creating or contributing to API development.

## Testing

Run `npm test` and all the tests in the `test/` directory will be executed. Our test suite uses a combination of the [Mocha JavaScript test framework](https://mochajs.org/) and [semistandard](https://github.com/Flet/semistandard) to ensure code quality and consistency.

## Help

If you have questions, encounter a bug or would like to submit a new feature, please [open an issue on GitHub](https://github.com/bestbuy/api-playground/issues).

## Credit

This application has been provided by [Best Buy's API team](https://developer.bestbuy.com/). If your company has a web or mobile application that talks about consumer electronics, please consider [signing up](https://developer.bestbuy.com/) for an API key and [integrating us](http://bestbuyapis.github.io/api-documentation/) into your application.

## Licenses

Copyright (c) 2016

* All source code is licensed under the [MIT license](LICENSE-SOURCE.md).
* Product, store and category information - stored within `dataset.sqlite` - is licensed under [Creative Commons Attribution-NonCommercial 4.0 International](LICENSE-DATASET.md).
* Location information within the dataset was made possible by [GeoNames](http://www.geonames.org) under the [Creative Commons Attribution 3.0](https://creativecommons.org/licenses/by/3.0/) license.
6 changes: 6 additions & 0 deletions config/default.json
@@ -0,0 +1,6 @@
{
"host": "localhost",
"name": "Best Buy API Playground",
"port": 3030,
"public": "../public/"
}
Binary file added dataset.sqlite
Binary file not shown.
38 changes: 38 additions & 0 deletions markdown/index.md
@@ -0,0 +1,38 @@
# Best Buy - API Playground

## Overview

The Best Buy API Playground is a dataset of products, categories, and stores exposed over HTTP via a simple REST API. This application is meant to be a tool used for educational purposes.

### Endpoints

* [/products](/products) - a subset of ~50,000 products available at Best Buy.
* [/categories](/categories) - All product categories and their subcategories/path.
* [/stores](/stores) - A list of all Best Buy store locations.
* [/services](/services) - A list of all services available at Best Buy stores.

## Exploring the API

### Swagger
* Swagger config URL: [/swagger.json](/swagger.json)
* Explore the API via the [Swagger UI](/docs)

### Postman Collection
The API can also be explored via a [Postman Collection](https://www.getpostman.com/docs/collections).
* Import the collection from this URL: [/postman/API.postman_collection.json](/postman/API.postman_collection.json)

### Querying the API
* Check out our [Example Queries](queries) to get an idea of whats possible.
* All querystrings on GET requests are parsed using [qs](http://npmjs.com/packages/qs) to turn them into JSON.
* Nearly all the [Sequelize Operators](http://docs.sequelizejs.com/en/latest/docs/querying/#operators) are supported.
* Use `*` instead of `%` for the `$like` Operators
* Use `$select` instead of `$attributes` for selecting specific fields
* Use Feathers [Pagination and sorting](https://docs.feathersjs.com/databases/pagination.html) fields (`$limit, $skip, $sort`)

### Technologies

* [Feathers](http://feathersjs.com/)
* [Sequelize](http://docs.sequelizejs.com/en/v3/)

### Attribution
Zipcode data provided by [geonames.org](http://www.geonames.org/)
56 changes: 56 additions & 0 deletions markdown/queries.md
@@ -0,0 +1,56 @@

<link rel="stylesheet" href="/darcula.css">
<script src="/highlight.pack.js"></script>
<script src="/libs/superagent/superagent.js"></script>

# Best Buy - API Playground

## Example Queries
Below are some example queries for the products endpoint. This is to illustrate the ways in which queries can be build via the query string. Each result is run live against the local API.

### Get product with ID of 9132294 (sku)
#### [/products/9132294](/products/9132294)

### Get all products
#### [/products](/products)

### Get all products, limit to 1 result
#### [/products?$limit=1](/products?$limit=1)

### Get all products, skip to the 25,001th result
#### [/products?$skip=25000](/products?$skip=25000)

### Get all products, sort by highest price (descending)
#### [/products?$sort[price]=-1](/products?$sort[price]=-1)

### Get all products, sort by lowest price (ascending)
#### [/products?$sort[price]=1](/products?$sort[price]=-1)

### Get all products, but only show the name and price in the result
#### [/products?$select[]=name&amp;$select[]=price](/products?$select[]=name&amp;$select[]=price)

### products of type HardGood
#### [/products?type=HardGood](/products?type=HardGood)

### products less than or equal to $1.00
#### [products?price[$lte]=1](products?price[$lte]=1)

### products that have 'star wars' in the name and are under $30
#### [/products?name[$like]=\*star+wars\*&amp;price[$lt]=30](/products?name[$like]=*star+wars*&amp;price[$lt]=30)

### products that are either $0.99 or $1.99
#### [/products?price[$in]=0.99&amp;price[$in]=1.99](/products?price[$in]=0.99&amp;price[$in]=1.99)

### products that have a shipping price of more than $10
#### [/products?shipping[$gt]=10](/products?shipping[$gt]=10)

### products that are not HardGood or Software
#### [/products?type[$nin][]=HardGood&amp;type[$nin][]=Software](/products?type[$nin][]=HardGood&amp;type[$nin][]=Software)

### products that are in category name "Coffee Pods"
#### [/products?category.name=Coffee Pods](/products?category.name=Coffee Pods)

### products that are in category ID "abcat0106004" (TV Mounts)
#### [/products?category.id=abcat0106004](/products?category.id=abcat0106004)

<script src="process.js"></script>
69 changes: 69 additions & 0 deletions package.json
@@ -0,0 +1,69 @@
{
"name": "apibox",
"description": "Best Buy API Playground",
"version": "1.0.0",
"homepage": "",
"main": "src/",
"keywords": [
"feathers"
],
"license": "MIT",
"private": true,
"repository": {},
"author": {},
"contributors": [],
"bugs": {},
"engines": {
"node": ">= 4.4.7"
},
"scripts": {
"test": "cp dataset.sqlite test/testdb.sqlite && npm run mocha && semistandard",
"start": "node src/",
"mocha": "NODE_ENV=test mocha test/ --recursive",
"dev": "nodemon",
"coverage": "nyc npm test",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"ajv": "^4.8.2",
"body-parser": "^1.15.2",
"compression": "^1.6.2",
"cors": "^2.7.1",
"degrees-radians": "^1.0.3",
"feathers": "^2.0.1",
"feathers-configuration": "^0.2.3",
"feathers-errors": "^2.4.0",
"feathers-hooks": "^1.5.4",
"feathers-rest": "^1.4.3",
"feathers-sequelize": "^1.3.3",
"feathers-socketio": "^1.4.1",
"marked": "^0.3.6",
"passport": "^0.3.2",
"radians-degrees": "^1.0.0",
"sequelize": "^3.24.8",
"serve-favicon": "^2.3.0",
"sqlite3": "^3.1.8",
"superagent": "^2.3.0",
"swagger-ui": "^2.2.6",
"swagger-ui-express": "^1.0.1",
"winston": "^2.2.0"
},
"devDependencies": {
"coveralls": "^2.11.15",
"mocha": "^2.5.3",
"nodemon": "^1.11.0",
"nyc": "^9.0.1",
"request": "^2.73.0",
"semistandard": "^8.0.0",
"supertest": "^2.0.1"
},
"semistandard": {
"env": [
"mocha"
],
"ignore": [
"src/middleware/swagger/swagger-ui",
"public/highlight.pack.js"
]
}
}

0 comments on commit 8400c19

Please sign in to comment.