Skip to content

Commit

Permalink
Merge pull request #11 from MGalaCyber/master
Browse files Browse the repository at this point in the history
Release v3.1.0
  • Loading branch information
MGalaCyber authored Apr 11, 2024
2 parents 93a1d48 + 6f823fd commit fdad852
Show file tree
Hide file tree
Showing 80 changed files with 1,515 additions and 1,036 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Full API Implementation inside NodeJS Module
- More info at [`Website`](https://api.universebot.space)
- Documentation [`Website`](https://docs.universebot.space)
- Get **API TOKEN** here [`Register`](https://api.universebot.space/auth/login)
- _Free trial **premium** for `3 days`._
- _Free trial **premium** for `3 days` for new user._
- And you can upgrade your api token to premium, you can see more details at [`UPGRADE`](https://api.universebot.space/dashboard/premium)

## Installation
Expand All @@ -17,39 +17,39 @@ yarn:
```bash
$ yarn add @mgalacyber/universeapi
```
pnpm:
```bash
$ pnpm add @mgalacyber/universeapi
```

## Simple to Use
## CommonJs (CJS) syntax
```js
const { universeAPIClient } = require("@mgalacyber/universeapi");
const { UniverseClient } = require("@mgalacyber/universeapi");
const uAPI = new UniverseClient("API-TOKEN");

// Example of an API call
uAPI.V1.AI.OpenAI.GPT.Text({
model: "gpt4", // Type of model used
version: 1, // Model version of rest api
prompt: "What is Galaxy Universe?" // Enter Your prompt here

}).then((result) => console.log(result));
```
## ECMAScript Modules (ESM) syntax
```ts
import { universeAPIClient } from "@mgalacyber/universeapi";
```

## Example
```js
const uAPI = new universeAPIClient("API-TOKEN");

// How to call the API
uAPI.[version].[features].[category](parameter)
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error.message);
});
import { UniverseClient } from "@mgalacyber/universeapi";
const uAPI = new UniverseClient("API-TOKEN");

// Example of an API call
uAPI.V1.Creator.Photooxy.Flaming("Universe API")
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error.message);
});
uAPI.V1.AI.OpenAI.GPT.Text({
model: "gpt4", // Type of model used
version: 1, // Model version of rest api
prompt: "What is Galaxy Universe?" // Enter Your prompt here

}).then((result) => console.log(result));
```


# Feedback
If you have any feedback, please reach out to us at support@universebot.space
If you have any feedback, please reach out to us at `support@universebot.space`
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Check Update
const _checkUpdates = require("./src/checkUpdates");
_checkUpdates();
const packageNotifier = require("@mgalacyber/package-notifier");
const packageFile = require("./package.json");
packageNotifier(packageFile);

// Import api
module.exports = require("./src/main");
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
{
"name": "@mgalacyber/universeapi",
"version": "2.1.10",
"description": "UniverseAPI Scraper package endpoint",
"version": "3.1.0",
"description": "UniverseAPI Wrapper package endpoint",
"main": "index.js",
"typings": "./typings/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/UniverseBot/UniverseAPI-Scraper.git"
"url": "git+https://github.com/UniverseBot/UniverseAPI-Wrapper.git"
},
"keywords": [
"Universe",
"API",
"endpoint",
"rest-api",
"OpenAPI",
"scraper",
"api-scaper",
"apis",
Expand All @@ -26,10 +27,11 @@
"author": "MGalaCyber",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/UniverseBot/UniverseAPI-Scraper/issues"
"url": "https://github.com/UniverseBot/UniverseAPI-Wrapper/issues"
},
"homepage": "https://api.universebot.space",
"dependencies": {
"@mgalacyber/package-notifier": "^1.0.1",
"axios": "^1.6.5",
"form-data": "^4.0.0"
}
Expand Down
29 changes: 0 additions & 29 deletions src/checkUpdates.js

This file was deleted.

44 changes: 30 additions & 14 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
const { Method } = require("./method");

/**
* @class universeAPIClient
* @class UniverseClient
*/
class universeAPIClient {

class UniverseClient {
/**
* @param {string} token provider https://api.universebot.space
* @requires A valid API token is required for accessing the API.
* @param {string} token The API token provided by https://api.universebot.space.
* @description This function initializes the universeAPI client with the provided token.
* @returns {void}
* @example
* const { UniverseClient } = require("@mgalacyber/universeapi");
* const ApiToken = "UniverseAPI.XXXXXXXXXXXXX.XXXXXXXXXXXXX.XXXXXXXXXXXXX.XXXXXXXXXXXXX";
* const uAPI = new UniverseClient(ApiToken);
*
* uAPI.V1.AI.OpenAI.GPT.Text({
* model: "gpt4", // Type of model used (required)
* version: 1, // Model version of rest api (required)
* prompt: "Hello!" // Enter Your prompt here (required)
*
* }).then((result) => console.log(result));
*/
constructor(token) {
this.ApiToken = token ? token : "";
this.BaseUrl = "https://api.universebot.space";
};
async Api() {
if (!this.ApiToken) {
console.error(`Unknown API TOKEN: Please enter your API token or Register first here ${this.BaseUrl}`)
console.error(`Unknown API TOKEN: Please enter your API token or Register first here ${this.BaseUrl}/register`);
};
if (typeof this.ApiToken !== "string") {
console.error("Invalid API TOKEN: Token must be a String")
console.error("Invalid API TOKEN: Token must be a String");
};
return new Method(this.BaseUrl, { token: this.ApiToken });
};
Expand All @@ -29,7 +42,7 @@ class universeAPIClient {
return {
AI: {
Blackbox: require("./v1/AI/Blackbox")(this.Api.bind(this)),
ChatGPT: require("./v1/AI/ChatGPT")(this.Api.bind(this)),
OpenAI: require("./v1/AI/OpenAI")(this.Api.bind(this)),
Google: require("./v1/AI/Google")(this.Api.bind(this)),
Microsoft: require("./v1/AI/Microsoft")(this.Api.bind(this)),
StableDiffusion: require("./v1/AI/StableDiffusion")(this.Api.bind(this)),
Expand All @@ -41,6 +54,9 @@ class universeAPIClient {
Photooxy: require("./v1/Creator/Photooxy")(this.Api.bind(this)),
Textpro: require("./v1/Creator/Textpro")(this.Api.bind(this))
},
Detector: {
NSFW: require("./v1/Detector/NSFW")(this.Api.bind(this))
},
Download: {
AIO: require("./v1/Download/AIO")(this.Api.bind(this)),
Audio: require("./v1/Download/Audio")(this.Api.bind(this)),
Expand All @@ -55,14 +71,14 @@ class universeAPIClient {
Youtube: require("./v1/Download/Youtube")(this.Api.bind(this))
},
Game: {
SusunKata: require("./v1/Game/SusunKata")(this.Api.bind(this)),
Tebakan: require("./v1/Game/Tebakan")(this.Api.bind(this))
SusunKata: require("./v1/Games/SusunKata")(this.Api.bind(this)),
Tebakan: require("./v1/Games/Tebakan")(this.Api.bind(this))
},
Image: {
Pinterest: require("./v1/Image/Pinterest")(this.Api.bind(this)),
Remini: require("./v1/Image/Remini")(this.Api.bind(this)),
Wallpaper: require("./v1/Image/Wallpaper")(this.Api.bind(this)),
Wikipedia: require("./v1/Image/Wikipedia")(this.Api.bind(this))
Pinterest: require("./v1/Images/Pinterest")(this.Api.bind(this)),
Remini: require("./v1/Images/Remini")(this.Api.bind(this)),
Wallpaper: require("./v1/Images/Wallpaper")(this.Api.bind(this)),
Wikipedia: require("./v1/Images/Wikipedia")(this.Api.bind(this))
},
Search: {
Google: require("./v1/Search/Google")(this.Api.bind(this))
Expand All @@ -89,4 +105,4 @@ class universeAPIClient {
};
};

module.exports = { universeAPIClient };
module.exports = { UniverseClient };
22 changes: 11 additions & 11 deletions src/method.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const axios = require("axios");
const Axios = require("axios");
const FormData = require("form-data");

class Method {
Expand All @@ -11,14 +11,14 @@ class Method {
this.token = token;
}

async request(method, path = "", data = null, options = {}) {
async createRequest(method, path = "", data = null, options = {}) {
const headers = {
Authorization: this.token ? `Bearer ${this.token}` : "",
...options.headers,
};

try {
const response = await axios({
const getResponse = await Axios({
method,
url: `${this.URI}/${path}`,
headers,
Expand All @@ -30,34 +30,34 @@ class Method {
...options,
});

return response.data;
return getResponse.data;
} catch (error) {
return error;
return error.response.data;
}
}

async Get(path = "/", query = {}, options = {}) {
return this.request("GET", path, query, options);
return this.createRequest("GET", path, query, options);
}

async Post(path = "", data = {}, options = {}) {
return this.request("POST", path, data, options);
return this.createRequest("POST", path, data, options);
}

async Put(path = "", data = {}, options = {}) {
return this.request("PUT", path, data, options);
return this.createRequest("PUT", path, data, options);
}

async Delete(path = "", options = {}) {
return this.request("DELETE", path, null, options);
return this.createRequest("DELETE", path, null, options);
}

async Patch(path = "", data = {}, options = {}) {
return this.request("PATCH", path, data, options);
return this.createRequest("PATCH", path, data, options);
}

async Options(path = "", options = {}) {
return this.request("OPTIONS", path, null, options);
return this.createRequest("OPTIONS", path, null, options);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/v1/AI/Blackbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module.exports = function(Api) {
return {
Model1: async (prompt) => (await Api()).Get("v1/ai/blackbox/model1", { prompt }),
Model2v4: async (prompt) => (await Api()).Get("v1/ai/blackbox/model2-v4", { prompt }),
Text: async function(options) {
const { version, prompt } = options;

if (version === 1) return (await Api()).Get("v1/ai/blackbox/model1", { prompt });
if (version === 2) return (await Api()).Get("v1/ai/blackbox/model2", { prompt });
}
}
};
17 changes: 0 additions & 17 deletions src/v1/AI/ChatGPT.js

This file was deleted.

31 changes: 25 additions & 6 deletions src/v1/AI/Google.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
module.exports = function(Api) {
return {
Gemini: {
Pro: async (prompt) => (await Api()).Get("v1/ai/google/gemini/pro", { prompt }),
ProVisionModelAttach: async (image, prompt) => (await Api()).Post("v1/ai/google/gemini/pro-vision-attach", { image, prompt }),
ProVisionModelUrl: async (image, prompt) => (await Api()).Get("v1/ai/google/gemini/pro-vision-url", { image, prompt })
Text: async function(options) {
const { model, version, prompt } = options;

if (model === "1.0-pro") {
if (version === 1) return (await Api()).Get("v1/ai/google/gemini/1.0-pro/text/model1", { prompt });
if (version === 2) return (await Api()).Get("v1/ai/google/gemini/1.0-pro/text/model2", { prompt });
if (version === 3) return (await Api()).Get("v1/ai/google/gemini/1.0-pro/text/model3", { prompt });
}
},
Vision: async function(options) {
const { model, type, version, image, prompt } = options;

if (model === "1.0-pro" && type === "attacment") {
if (version === 1) return (await Api()).Post("v1/ai/google/gemini/1.1-pro/vision/attach/model1_deprecated", { image, prompt });
}
if (model === "1.0-pro" && type === "url") {
if (version === 1) return (await Api()).Get("v1/ai/google/gemini/1.1-pro/vision/url/model1_deprecated", { image, prompt });
}
},
},
Bard: {
Model1: async (prompt) => (await Api()).Get("v1/ai/google/bard/model1", { prompt }),
Model2Image: async (url, prompt) => (await Api()).Get("v1/ai/google/bard/model2-img", { url, prompt }),
}
Text: async function(options) {
const { version, prompt } = options;

if (version === 1) return (await Api()).Get("v1/ai/google/bard/text/model1_deprecated", { prompt });
},
},
}
};
Loading

0 comments on commit fdad852

Please sign in to comment.