Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Create README.md

Initial request working

Refactor for cleaner and more modular architecture

adding more resoures file, and some code fixes

Finished Implementing Requests

util

Moving package contents

Unit tests and clean up

Tests and README

README

Release Notes, and README fixes

Version bump, for npm

Cleanup

Cleanup
  • Loading branch information
asbeane committed Jul 17, 2019
1 parent 69a617c commit 94c2d61
Show file tree
Hide file tree
Showing 29 changed files with 1,771 additions and 16 deletions.
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

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

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Andy Beane

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.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# mlb-stats-api

Node.js Library for calling the MLB Stats API

[![npm](https://img.shields.io/npm/dt/mlb-stats-api.svg)](https://www.npmjs.com/package/mlb-stats-api)
[![npm](https://img.shields.io/npm/v/mlb-stats-api.svg)](https://www.npmjs.com/package/mlb-stats-api)
[![License](https://img.shields.io/github/license/asbeane/mlb-stats-api.svg)](https://www.npmjs.com/package/mlb-stats-api)

## Install

``` npm install mlb-stats-api --save ```

## Dependencies

Currently powered by Axios! This decision was made largely due to the deprecation of the popular request library, and because axios is a well supported library for making HTTP requests using promises.

## How to use

In your project import the module like so:
```
const MLBStatsAPI = require('mlb-stats-api');
const mlbStats = new MLBStatsAPI();```
```

Optional arguments can be passed to the constructor, which include:
* host - defaults to the mlb-stats-api production host
* version - defaults to v1, the current live version of the API

## Making requests

Each callable function takes a single argument, which is an object.
The object can have one or two top level properties, which is how the query parameters, and the path parameters
are passed to the library.

Example:

```
const response = await mlbStats.getAttendance({params: { teamId: 111, leagueId: 103, leagueListid: 103 }});
```

The ```params``` property represents an object describing the query parameters.

Example:

```
const response = await mlbStats.getGame({ pathParams: { gamePk: 12345 }});
```

The ```pathParams``` property represents an object describing the name path parameters.

Both the pathParams and params can be passed in the object passed to any given request (where applicable to the specific request).

```
const response = await mlbStats.getGame(params: { ...... }, { pathParams: { ...... }});
```

## Supported Requests and their corresponding functions:
## Note: There are currently more requests supported, but the docs are a Work In Progress

* /attendance - mlbStats.getAttendance()
* /awards - mlbStats.getAwards()
* /conferences - mlbStats.getConferences()
* /divisions - mlbStats.getDivisions()
* /draft - mlbStats.getDraft()
* /game
* /game/{gamePk}/feed/live - mlbStats.getGame()
* /game/{gamePk}/feed/live/diffPatch - mlbStats.getGameDiffPatch()
* /game/{gamePk}/feed/live/timestamps - mlbStats.getGameTimestamps()
* /game/changes - mlbStats.getGameChanges()
* /game/{gamePk}/contextMetrics - mlbStats.getGameContextMetrics()
* /game/{gamePk}/winProbability - mlbStats.getGameWinProbability()
* /game/{gamePk}/boxscore - mlbStats.getGameBoxscore()
* /game/{gamePk}/content - mlbStats.getGameContent()
* /game/{gamePk}/feed/color - mlbStats.getGameColor()
* /game/{gamePk}/feed/color/diffPatch - mlbStats.getGameColorDiff()
* /game/{gamePk}/feed/color/timestamps - mlbStats.getGameColorTimestamps()
* /game/{gamePk}/linescore - mlbStats.getGameLinescore()
* /game/{gamePk}/playByPlay = mlbStats.getGamePlayByPlay()
* /gamePace - mlbStats.getGamePace()
* /highLow/{orgType} - mlbStats.getHighLow()
9 changes: 9 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Release Notes

## v1.0.6
Date: 2019-07-16
What's In this release?
This is the first complete release! It contains the working implementation of most of tbe known
API requests supported by the mlb-stats-api, only excluding the metadata API which is requestable by
type.
This tests includes a function testsuite, with a reasonable level of code coverage.
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';
const resources = require('./src/resources');
const axios = require('axios');

class MLBStatsAPI {
constructor(host = 'https://statsapi.mlb.com/api/', version = 'v1' ) {
this.host = host;
this.version = version
this.apiHost = host + version + '/';
this.request = axios;

/* All functions assume first argument are the query parameters named params, and the second argument is an object containing
* named path parameters, pathParams (ie {pathParams: {teamId: 111, leagueId: 103}})
*/
for (const resource in resources) {
for (const func of Object.getOwnPropertyNames(resources[resource].prototype)) {
if (func !== 'constructor') {
this[func] = resources[resource].prototype[func].bind(this);
}
}
}
}
}

module.exports = MLBStatsAPI;
Loading

0 comments on commit 94c2d61

Please sign in to comment.