# 4shared

> This is small lib, for using 4shared resorces in nodejs

Latest version **1.0.1** (published 2015-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install 4shared
pnpm add 4shared
yarn add 4shared
bun add 4shared
```

## 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 | 1.0.1 |
| Published | 2015-01-22 |
| First published | 2015-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | sathish kumar |
| Maintainers | bboysathish |
| Keywords | 4shared, shared |

## Links

- npm: https://www.npmjs.com/package/4shared
- Repository: https://bboysathish@bitbucket.org/bboysathish/4shared
- npm.io page: https://npm.io/package/4shared

## Dependencies (2)

- [oauth](https://npm.io/package/oauth.md) ^0.9.12
- [request](https://npm.io/package/request.md) ^2.51.0

## Recent versions

- 1.0.1 (latest) — 2015-01-22
- 1.0.0 — 2015-01-22

## README

# 4Shared-API / fourShared API (www.4shared.com)

This is API Wrapper Library for Consuming 4Shared API usin NodeJS.Please visit the below link for more info [4Shared_Docs]

  - All API's implemented.
  - All API's are only for Authenticated, Except FileSearch.
  
##### Search, Filter & Sorting:
Categories:
    - Music -1 
    - Video - 2
    - Photo - 3
    - Archieves - 4
    - Books/Office - 5
    - Programs - 6
    - Web - 7
    - Mobile - 8
    - Android - 10

Sample use of Libarary is also, in the examples [folder].
Just Replace your keys there, to start testing the application.

### Version
1.0.0

### Tech

4Shared Uses OAuth Library for Authentication & Authorization

* [OAuth] - Authentication & Authorization
* [Grunt] - for JS Hint & Testing 
* [Express] - for Sample use of Lib Functionality

### Installation

You need npm installed globally:

```sh
$ npm install -g npm
```
After that install the module as below,
```sh
$ npm install 4shared
```

### Example

First Tab:
```sh
var fourSharedApi = require('../index');
var express = require('express');
var app = express();
var fs = require('fs');


var fileId = "";
var rootFolder = "";
var folderID = "";
var userID= "";

var client = new fourSharedApi({
	"oauth_consumer_key": "xxxx",
	"oauth_secret_key": "xxxx",
	"callback": "http://localhost:8080/callback",
	"access_token": "optional",
	"access_secret": "optional",
	"authorized": true
});

client.on('error', function(err) {
	console.log(err);
});

client.on('connected', function(is) {
	console.log(is);
});

app.get('/start', function(req, res) {
	client.authenticate(function(err, data) {
		if (err) throw err;
		res.redirect('https://api.4shared.com/v0/oauth/authorize?oauth_token=' + data.token);
	});
});

app.get('/callback', function(req, res) {
	client.callback(function(err, data) {
		if (err) throw err;
		res.json(data);
	});
});

app.get('/filesearch', function(req, res) {
	client.fileSearch(function(err, resp, body) {
		console.log(err);
		res.send(body)
	});
});

app.get('/filesearchparams', function(req, res) {
	var queryOpts = {
		category: "2",
		query: "Sky"
	};
	client.fileSearch(queryOpts, function(err, resp, body) {
		console.log(err);
		res.send(body)
	});
});

app.get('/userinfo', function(req, res) {
	client.userInfo(function(err, resp, body) {
		console.log(err);
		rootFolder = JSON.parse(body).rootFolderId;
		userID = JSON.parse(body).id;
		res.send(body);
	});
});

app.get('/uploadFile', function(req, res) {
	var formData = {
		folderId: "2iVI6yt1",
		description: "testing",
		tags: "test",
		file: fs.createReadStream(__dirname + '/origin.js')
	};

	client.uploadFile(formData, function(err, resp, body) {
		console.log(err);
		fileId = JSON.parse(body).id;
		res.send(body);
	});
});

app.get('/updateFile', function(req, res) {
	var formData2 = {
		file: fs.createReadStream(__dirname + '/replacement.js')
	}
	console.log(fileId);
	client.updateFile(fileId, formData2, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/updateFileInfo', function(req, res) {
	var dad = {
		name: "nameisChanged"
	}
	console.log(fileId);
	client.updateFileInfo(fileId, dad, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/fileinfo', function(req, res) {
	client.getfileInfo(fileId, false, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
})

app.get('/updateUserInfo', function(req, res) {
	var data = {
		firstName: "UpdateUser",
		description: "Hi How Are Yu!!"
	};
	client.updateUserInfo(data, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/userfiles', function(req, res) {
	client.userFiles(function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/getOwnerInfo', function(req, res) {
	client.getOwnerInfo(userID, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/foldersInfo', function(req, res) {
	console.log(rootFolder);
	client.foldersInfo(rootFolder, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/childrenFolderInfo', function(req, res) {
	client.childrenFolderInfo(rootFolder, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/listFilesInFolder', function(req, res) {
	client.listFilesInFolder(rootFolder, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/createFolder', function(req, res) {
	var foldata = {
		parentId: "2iVI6yt1",
		name: "testFolder",
		description: "test Folder.."
	}
	client.createFolder(foldata, function(err, resp, body) {
		console.log(err);
		folderID = JSON.parse(body).id;
		res.send(body);
	});
});

app.get('/updateFolderInfo', function(req, res) {
	var foldata = {
		name: "testFolderUpdated",
		description: "test Folder.."
	}
	client.updateFolderInfo(folderID, foldata, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});


app.get('/deleteFolder', function(req, res) {
	client.deleteFolder(folderID, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

app.get('/deleteFile', function(req, res) {
	client.deleteFile(fileId, function(err, resp, body) {
		console.log(err);
		res.send(body);
	});
});

var server = app.listen(8080,function(){
	console.log("Server Started");
});
```

### Todo's

 - Write Tests
 - Add Code Comments

License
----

MIT

[4Shared_Docs]:http://www.4shared.com/developer/docs/
[folder]:https://bitbucket.org/bboysathish/4shared/src/7a1c9427dc4d6bf326a6254c5bf9c7f60aacdc1d/examples/all.js?at=master
[Grunt]:http://gruntjs.com/
[express]:http://expressjs.com
[OAuth]:https://www.npmjs.com/package/oauth

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