https://github.com/make-software/make-traffic-integration-lib
https://github.com/make-software/make-traffic-integration-lib
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/make-software/make-traffic-integration-lib
- Owner: make-software
- Created: 2025-02-28T19:12:07.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-24T11:07:05.000Z (about 1 year ago)
- Last Synced: 2025-03-24T12:25:54.438Z (about 1 year ago)
- Language: TypeScript
- Size: 196 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Make Traffic Integration JS Library
The project contains modular JavaScript libraries designed for managing tasks in a traffic exchange system.
It consists of a [core npm package](https://www.npmjs.com/package/make-traffic-integration-core) and framework-specific
wrappers for popular frameworks.
The core library is framework-agnostic, written in TypeScript, and compiled to JavaScript.
---
## **Installation**
```bash
npm install make-traffic-integration-core
```
---
### **Initialization**
To use the library, initialize the `TaskManagerApp` instance with your app's configuration:
```javascript
import { TaskManagerApp } from "make-traffic-integration-core";
const appConfig = {
apiUrl: 'https://make-traffic-integration.dev.make.services',
appKey: '',
};
const taskManager = new TaskManagerApp(appConfig);
taskManager.init(); // Initialize the library
```
---
### Example
```typescript
const onCampaignClaimed = (task: Campaign) => {
console.log('Campaign claimed:', task);
};
taskManager.subscribe(Events.CampaignClaimSucceed, onCampaignClaimed);
taskManager.getCampaigns('user123').then(campaigns => {
console.log('Campaigns:', campaigns);
});
```
### **React Example with wrapper library **
```bash
npm install make-traffic-integration-react-wrapper
```
Check [React Example](./examples/react-app/README.md)
#### Code Example
```tsx
import React from "react";
import { TaskManagerProvider } from "make-traffic-integration-react-wrapper";
import {TaskManagerApp} from "make-traffic-integration-core";
const taskManagerApp = TaskManagerApp({
apiUrl: "https://api.example.com",
appKey: "your-app-key",
});
const MyCustomTemplate = (campaign, actions) => (
{campaign.name}
Go
Claim
);
const App = () => (
);
export default App;
```
## Core Methods
### `async init(): Promise`
Initializes the task manager. Should be run once before using other methods.
### `async getCampaigns(userID: string): Promise`
Fetches the list of campaigns available for the specified user.
### `async goProcess(userID: string, task: Campaign): Promise`
Processes the specified campaign task.
### `async claimProcess(userID: string, task: Campaign): Promise`
Claims the specified campaign task for the user.
### `subscribe(event: Events, callback: (task: Campaign) => void): void`
Subscribes to a specific event related to campaign tasks.
### `unsubscribe(event: Events, callback: (task: Campaign) => void): void`
Unsubscribes from a previously subscribed event.
## Events
### `Events.CampaignClaimSucceed`
Triggered when a campaign is successfully claimed.
### `Events.CampaignClaimFailed`
Triggered when claiming a campaign fails.
### `Events.CampaignProcessed`
Triggered when a campaign has been successfully processed.
## License
MIT