# glitch-api

> Library for using Glitch API ⚙️

Latest version **3.1.0** (published 2020-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install glitch-api
pnpm add glitch-api
yarn add glitch-api
bun add glitch-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2020-06-10 |
| First published | 2019-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 311 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Maintainers | jarvis394 |
| Keywords | node, glitch, js, api |

## Links

- npm: https://www.npmjs.com/package/glitch-api
- Repository: https://github.com/jarvis394/glitch-api
- Homepage: https://glapi.ml
- Issues: https://github.com/jarvis394/glitch-api/issues
- npm.io page: https://npm.io/package/glitch-api

## Dependencies (2)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.0
- [algoliasearch](https://npm.io/package/algoliasearch.md) ^4.2.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.1.0 (latest) — 2020-06-10
- 3.0.4 — 2020-06-03
- 3.0.3 — 2020-06-03
- 3.0.2 — 2020-06-03
- 3.0.1 — 2020-06-03
- 3.0.0 — 2020-06-03
- 3.0.0-alpha3 — 2019-12-26
- 3.0.0-alpha2 — 2019-12-21
- 3.0.0-alpha1 — 2019-12-21
- 2.4.0 — 2019-12-20
- 2.3.4 — 2019-12-15
- 2.3.3 — 2019-12-15
- 2.3.0 — 2019-12-14
- 2.2.0 — 2019-12-14
- 1.2.1 — 2019-09-24
- … 5 more at https://npm.io/package/glitch-api/versions

## README

## glitch-api

[![GitHub package.json dynamic](https://img.shields.io/github/package-json/version/jarvis394/glitch-api)](https://www.npmjs.com/package/glitch-api)
[![CircleCI](https://circleci.com/gh/jarvis394/glitch-api/tree/master.svg?style=shield)](https://circleci.com/gh/jarvis394/glitch-api/tree/master)
[![npm bundle size](https://img.shields.io/bundlephobia/min/glitch-api?label=size)](https://www.npmjs.com/package/glitch-api)

A Node.js module that allows you to easily interact with the Glitch API

| 📖 [Documentation](https://glapi.ml/globals) | ✨ [Examples](https://github.com/jarvis394/glitch-api/tree/master/docs/examples/) |
| ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |

## Features

- 99% coverage of the **known** Glitch API
- Uses **TypeScript** that provides hints in editor, type checking, etc.
- **Supports WebSocket connection to the Glitch editor**
- Support for authorization
- Only two dependencies: `node-fetch` and `algoliasearch`
- Class abstraction
- Works with both API versions

###### _Warning: this module uses unstable API that hasn't been officially released yet. Described only world-open methods from [this unofficial site](https://glitchapi.glitch.me) and my researches_

## Installation

> **[Node.js](https://nodejs.org/) 8.0.0 or newer is required**

##### NPM

```
npm i glitch-api -s
```

## Example usage

```javascript
// Require using ES6 syntax
import { Glitch } from 'glitch-api'

// Or using old fancy style
const { Glitch } = require('glitch-api')

// Init main class
const glitch = new Glitch({ token: 'xxx' })  // Put here your Glitch token or use glitch.setAnonToken()
const { api } = glitch

// Get a user profile
api.users.get({ id: 1 }).then(user => console.log) // → User
```

## ❗ Migration from 2.x to 3.x

- Any search method now follows the same syntax:
  ```
  .search(s: string) → Algolia result
  ```
- Remixing a project doesn't return `joinLink`. Now it is a `Project` instance. Consider getting project data with token via `api.projects.get()`
- Token is absolutely required. If you don't have a token, consider using `Glitch.setAnonToken()`. For more info, see [examples/anonymous.js](https://github.com/jarvis394/glitch-api/blob/master/docs/examples/anonymous.js)

## Q&A

### How do I get Glitch token?

Paste the following code to the browser's console on the Glitch editor page:

```javascript
(JSON.parse(localStorage.getItem('cachedUser'))).persistentToken
```

Also you can use `Glitch.setAnonToken() → Promise<string>` method to login as an anonymous user and use its token.

___
### Why *\*api-method\** is not implemented?

Because I'm also human and I might not have seen the recent changes in Glitch's API.
Anyway, PRs are open for anyone :)

___
### The *\*api-method\** is not working.

It could be that Glitch devs removed the support for that method. Or it's just a my fault.
Open a new issue and describe what's happend.

## Contribution

Feel free to open new Pull request or an issue!

## Credits

Made by jarvis394 with ♥️

- VK: **[@tarnatovski](https://vk.com/tarnatovski)**
- git: **[@jarvis394](https://github.com/jarvis394)**

---
_Source: https://npm.io/package/glitch-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
