Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated nodejs examples #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
node_modules
152 changes: 152 additions & 0 deletions nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# CurriClientService Documentation

The `CurriClientService` class enables interaction with the Curri API, facilitating operations such as fetching delivery quotes, booking deliveries, managing deliveries with multiple stops, retrieving delivery information, estimating delivery times, and canceling deliveries. This README details how to install, configure, and utilize this service in your projects.

## Installation

Ensure Node.js is installed on your system. Include this library in your project using npm or yarn if lib on public registry:

### Using npm

```bash
npm install @your-namespace/curri --save
```

### Using yarn

```bash
yarn add @your-namespace/curri
```

## Configuration

If not on public registry require file manually. Obtain your user ID and API key from your Curri API account. Initialize the `CurriClientService` with these credentials:

```javascript
const { CurriClientService } = require('./dist');
const curri = new CurriClientService({ userID: "********", apiKey: "********" });
```

## Methods

`CurriClientService` provides methods for:

- Booking deliveries
- Booking deliveries with multiple stops
- Fetching delivery quotes
- Fetching quotes for deliveries with multiple stops
- Retrieving delivery information
- Estimating delivery times
- Canceling deliveries
- Updating a delivery
- Listing deliveries
- Get current API User

### Examples

#### Booking a Delivery

```javascript
async function bookDelivery() {
const booking = await curri.book(req.body);
console.log(booking);
}
```

#### Booking a Delivery with Multiple Stops

```javascript
async function bookMultiDelivery() {
const bookingMulti = await curri.bookMulti(req.body);
console.log(bookingMulti);
}
```

#### Fetching a Quote for a Delivery with Multiple Stops

```javascript
async function fetchMultistopQuote() {
const quoteMulti = await curri.quoteMultistop(req.query);
console.log(quoteMulti);
}
```

#### Retrieving Delivery Information

```javascript
async function retrieveDelivery() {
const delivery = await curri.getDelivery(req.query.delivery_id);
console.log(delivery);
}
```

#### Estimating Delivery Times

```javascript
async function estimateDelivery() {
const originLocation = {/* Define origin location */};
const selectedDeliveryMethod = "MethodHere"; // Define delivery method
const derivedDeliveryEstimate = await curri.deliveryDerivedEstimate(originLocation, selectedDeliveryMethod);
console.log(derivedDeliveryEstimate);
}
```

#### Canceling a Delivery

```javascript
async function cancelDeliveryAction() {
const delivery_id = "YourDeliveryIDHere"; // Define delivery ID
const reason = "YourReasonHere"; // Define cancellation reason
const cancelDelivery = await curri.cancelDelivery(delivery_id, `Cancel Delivery Reason: ${reason}`);
console.log(cancelDelivery);
}
```

#### Fetching a Delivery Quote

```javascript
async function fetchQuote() {
const quote = await curri.quote(req.query);
console.log(quote);
}
```

#### Updating a Delivery

```javascript
async function updateDelivery() {
const updatedDelivery = await curri.updateDelivery(req.body);
console.log(updatedDelivery);
}
```

#### List Deliveries

```javascript
async function listDeliveries() {
const deliveries = await curri.listDeliveries();
console.log(deliveries);
}
```

#### Delivery Estimates

```javascript
async function deliveryEstimates() {
const deliveryEstimates = await curri.deliveryEstimates(delivery_id);
console.log(deliveryEstimates);
}
```

#### Get Current User

```javascript
async function currentUser() {
const currentUser = await curri.getCurrentUser();
console.log(currentUser);
}
```

## Support

For any issues, questions, or contributions, refer to the project's GitHub repository or directly contact the project maintainers.
Loading