https://github.com/jacxk/sourcebin-wrapper
Create and get bins from https://sourceb.in/
https://github.com/jacxk/sourcebin-wrapper
sourcebin sourcebin-wrapper sourcebinapi wrapper
Last synced: 11 months ago
JSON representation
Create and get bins from https://sourceb.in/
- Host: GitHub
- URL: https://github.com/jacxk/sourcebin-wrapper
- Owner: Jacxk
- License: mit
- Created: 2020-03-17T21:41:23.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-24T03:21:44.000Z (over 5 years ago)
- Last Synced: 2025-03-18T14:05:11.633Z (12 months ago)
- Topics: sourcebin, sourcebin-wrapper, sourcebinapi, wrapper
- Language: TypeScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SourceBin Wrapper
[](https://www.npmjs.com/package/sourcebin-wrapper)
[](https://github.com/Jacxk/Sourcebin-Wrapper/issues)
[](https://www.npmjs.com/package/sourcebin-wrapper)
[](https://www.npmjs.com/package/sourcebin-wrapper)
With this wrapper you can create and get bins from https://sourceb.in/
### Install
`npm i sourcebin-wrapper --save`
### Initialize
```javascript
// typescript
import * as SourceBin from 'sourcebin-wrapper';
// Node/JavaScript
const SourceBin = require('sourcebin-wrapper');
```
# Methods
### create([BinFile], BinOptions?)
```javascript
SourceBin.create([
new SourceBin.BinFile({
name: 'index.js',
content: 'This was created using the wrapper\n\nlanguageId: "js"',
languageId: 'js'
})
], {
title: 'Some test',
description: 'This is awesome'
})
.then(console.log)
.catch(console.error);
```
Language defaults to **Text**, if invalid or no language provided.
### upload(path, BinOptions?)
```js
// Upload single file
SourceBin.upload('path/to/file', { title: 'Upload file' })
.then(console.log)
.catch(console.error);
// Upload entire folder
SourceBin.upload('path/to/folder', { title: 'Upload folder' })
.then(console.log)
.catch(console.error);
```
Language is detected by the file extension, and name as well.
### newBin(contents, lang?, name?, BinOptions?)
```js
SourceBin.newBin('Using wrapper', 'txt', 'wrapper', {
title: 'Some test',
description: 'This is awesome'
})
.then(console.log)
.catch(console.error);
```
### get(url | key)
```javascript
// Get bin using its key
SourceBin.get("d4ad855543").then(console.log);
// Get bin using its url
SourceBin.get("https://sourceb.in/d4ad855543").then(console.log);
```
#### Sample Output
Output for both **create** and **get**
```json
{
"key": "d4ad855543",
"url": "https://sourceb.in/d4ad855543",
"shortened": "https://srcb.in/d4ad855543",
"created": "2020-03-17T21:12:30.549Z",
"files": [
{
"raw": "https://sourceb.in/raw/d4ad855543/0",
"content": "This was created using the wrapper\n\nlanguageId: \"js\"",
"languageId": 183,
"language": {
"name": "JavaScript",
"extension": "js",
"aliases": [
"js",
"node"
],
"aceMode": "javascript"
}
}
]
}
```
# Options
#### BinFileOptions:
This is for creating BinFiles
* `content`: The contents of what you're uploading
* `name` \: The name of the file to be uploaded
* `languageId`\: Language of the contents you're uploading
#### BinOptions:
This is for creating Bins
* `title`\: The title of the bin
* `description`\: The description of the bin
*Note: BinFile is for the contents of each Bin. A Bin can contain multiple BinFiles*