snipe-sdk-ts
v1.1.6
Published
Sure, here's the updated README.md markup for your TypeScript code with the new structure:
Downloads
5
Readme
Sure, here's the updated README.md markup for your TypeScript code with the new structure:
# Snipe SDK
The Snipe SDK is a TypeScript library that provides a convenient interface for interacting with the Snipe API. This SDK allows you to perform various actions such as user registration, event tracking, and token management in both development and production environments.
## Installation
To use the Snipe SDK in your TypeScript project, you can install it via npm:
```bash
npm install snipe-sdk-ts
Usage
Initialization
First, you need to initialize the Snipe SDK by providing your API key. The API key determines whether you are using the development or production environment.
import { SnipeSdk } from 'snipe-sdk-ts';
// Initialize with your API key
const apiKey = 'your_api_key';
const snipeSdk = new SnipeSdk(apiKey);
User Registration
You can use the SDK to register users with Snipe. Pass the user's hash as a parameter to the signUp
method.
const hash = 'user_hash';
const registrationResponse = await snipeSdk.signUp(hash);
console.log('User Registration Response:', registrationResponse);
Event Tracking
Track events using the trackEvent
method. You can specify various event parameters like eventId
, transactionAmount
, partialPercentage
, and debitTokens
.
const eventOptions = {
eventId: 'event_id',
snipeUserId: 'user_snipe_id',
// Optional parameters
transactionAmount: 100,
partialPercentage: 50,
debitTokens: { token1: 10, token2: 20 },
};
const eventResponse = await snipeSdk.trackEvent(eventOptions);
console.log('Event Tracking Response:', eventResponse);
Token Management
Retrieve token history and details using the getTokenHistory
and getTokenDetails
methods.
const tokenHistoryOptions = {
snipeUserId: 'user_snipe_id',
};
const tokenHistoryResponse = await snipeSdk.getTokenHistory(tokenHistoryOptions);
console.log('Token History Response:', tokenHistoryResponse);
const tokenDetailsOptions = {
snipeUserId: 'user_snipe_id',
};
const tokenDetailsResponse = await snipeSdk.getTokenDetails(tokenDetailsOptions);
console.log('Token Details Response:', tokenDetailsResponse);
Coin Data Retrieval
Fetch coin data for a user using the getCoinData
method.
const coinDataOptions = {
snipeUserId: 'user_snipe_id',
};
const coinDataResponse = await snipeSdk.getCoinData(coinDataOptions);
console.log('Coin Data Response:', coinDataResponse);
API Key Configuration
The SDK automatically detects whether your API key is for the development or production environment. If your API key is not valid, you will receive an "Invalid API key" response.
Error Handling
Make sure to handle errors appropriately in your code, as network errors or API failures may occur during requests. The SDK will throw errors in case of failures.
try {
// Your SDK method calls here
} catch (error) {
console.error('An error occurred:', error);
}
License
This SDK is provided under the MIT License. See the LICENSE file for details.
Please replace `'your_api_key'`, `'user_hash'`, `'event_id'`, `'user_snipe_id'`, and other placeholders with actual values when using the SDK.