igolf-sdk
v1.0.9
Published
SDK for interacting with the iGolf API (JavaScript & TypeScript compatible)
Downloads
27
Maintainers
Readme
igolf-sdk
igolf-sdk is a TypeScript SDK for securely interacting with the iGolf API. It provides a clean, typed interface for making authenticated requests using HMAC-SHA256 signatures.
Features
- HMAC-SHA256-based signature authentication
- Timestamped and signed URL generation
- Easy-to-use HTTP POST interface
- Written in TypeScript with full type support
- Clean, promise-based API
Installation
npm install igolf-sdk🚀 Quick Start
TypeScript
import { IGolfController, IgolfConfig } from "igolf-sdk";
const config: IgolfConfig = {
baseUrl: "https://api.igolf.com",
appKey: "your_app_key",
apiVersion: "1.0",
signVersion: "1.0",
signMethod: "HMAC-SHA256",
appSecret: "your_app_secret",
};
const igolf = new IGolfController(config);
async function fetchUserData() {
const actionCode = "CourseList";
const params = {
referenceLatitude: 40.71,
referenceLongitude: -74.0,
radius: 50,
page: 2,
};
const response = await igolf.requestWithActionCode(actionCode, params);
if (response.stat) {
console.log("Success:", response.data);
} else {
console.error("Error:", response.data);
}
}JavaScript
const { IGolfController } = require("igolf-sdk");
const config = {
baseUrl: "https://api.igolf.com",
appKey: "your_app_key",
apiVersion: "1.0",
signVersion: "1.0",
signMethod: "HMAC-SHA256",
appSecret: "your_app_secret",
};
const igolf = new IGolfController(config);
async function fetchUserData() {
const actionCode = "CourseList";
const params = {
referenceLatitude: 40.71,
referenceLongitude: -74.0,
radius: 50,
page: 2,
};
const response = await igolf.requestWithActionCode(actionCode, params);
if (response.stat) {
console.log("Success:", response.data);
} else {
console.error("Error:", response.data);
}
}
fetchUserData();🧩 API Reference
IGolfController
A class to interact with the iGolf API using signed HTTP POST requests.
Constructor
new IGolfController(config: IgolfConfig)Parameters
config: An object with the following properties:
| Field | Type | Description | | ----------- | ------ | ------------------------------------------------ | | baseUrl | string | Base iGolf API URL (e.g., https://api.igolf.com) | | appKey | string | Your API key | | apiVersion | string | API version, e.g. "1.0" | | signVersion | string | Signature version, e.g. "1.0" | | signMethod | string | Signature method (must be "HMAC-SHA256") | | appSecret | string | Your app's secret key |
Method: requestWithActionCode
Sends a signed request to the iGolf API for a given action.
requestWithActionCode<T>(
actionCode: string,
params: Record<string, any>
): Promise<ApiResponse<T>>controller
.requestWithActionCode("SomeAction", { key: "value" })
.then((response) => {
if (response.stat) {
console.log("Success:", response.data);
} else {
console.error("Error:", response.data);
}
});Parameters
actionCode(string): The specific API action, e.g. "GetUserData"params(object): The request body parameters as key-value pairs
IgolfConfig
Configuration object used to initialize the SDK.
TypeScript Example
interface IgolfConfig {
baseUrl: string;
appKey: string;
apiVersion: string;
signVersion: string;
signMethod: string;
appSecret: string;
}JavaScript Example
const config = {
baseUrl: "https://api.igolf.com",
appKey: "your_app_key",
apiVersion: "1.0",
signVersion: "1.0",
signMethod: "HMAC-SHA256",
appSecret: "your_app_secret",
};ApiResponse
Generic wrapper for API responses.
interface ApiResponse<T> {
stat: boolean;
data: T | string;
}stat: Indicates whether the request was successfuldata: Either the response data or a string error message
🛡 Security
NEVER commit your real app keys or app secret tokens to version control.
Always protect your private keys with file system permissions.
📝 License
MIT
📬 Author & Support
Mayank Anand
Email: [email protected]
