Skip to content

Commit a31d6d1

Browse files
committed
limoexpress init
1 parent 38dac8f commit a31d6d1

File tree

8 files changed

+504
-4
lines changed

8 files changed

+504
-4
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import limoexpress from "../../limoexpress.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "limoexpress-assign-driver",
6+
name: "Assign Driver",
7+
description: "Assign a driver to a specific ride. [See the documentation](https://api.limoexpress.me/api/docs/v1)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
limoexpress,
12+
bookingId: {
13+
propDefinition: [
14+
limoexpress,
15+
"bookingId",
16+
],
17+
},
18+
driverId: {
19+
propDefinition: [
20+
limoexpress,
21+
"driverId",
22+
],
23+
},
24+
assignmentNotes: {
25+
propDefinition: [
26+
limoexpress,
27+
"assignmentNotes",
28+
],
29+
optional: true,
30+
},
31+
},
32+
async run({ $ }) {
33+
const response = await this.limoexpress.assignDriver({
34+
bookingId: this.bookingId,
35+
driverId: this.driverId,
36+
assignmentNotes: this.assignmentNotes,
37+
});
38+
$.export("$summary", `Successfully assigned driver ID ${this.driverId} to booking ID ${this.bookingId}`);
39+
return response;
40+
},
41+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import limoexpress from "../../limoexpress.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "limoexpress-cancel-booking",
6+
name: "Cancel Booking",
7+
description: "Cancel an existing booking using its ID. [See the documentation](https://api.limoexpress.me/api/docs/v1)",
8+
version: "0.0.1", // Use this due to the lack of template tag functionality
9+
type: "action",
10+
props: {
11+
limoexpress,
12+
bookingId: {
13+
propDefinition: [
14+
limoexpress,
15+
"bookingId",
16+
],
17+
},
18+
cancellationReason: {
19+
propDefinition: [
20+
limoexpress,
21+
"cancellationReason",
22+
],
23+
optional: true,
24+
},
25+
},
26+
async run({ $ }) {
27+
const response = await this.limoexpress.cancelBooking({
28+
bookingId: this.bookingId,
29+
cancellationReason: this.cancellationReason,
30+
});
31+
32+
$.export("$summary", `Successfully canceled booking with ID: ${this.bookingId}`);
33+
return response;
34+
},
35+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import limoexpress from "../../limoexpress.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "limoexpress-create-booking",
6+
name: "Create Limo Booking",
7+
description: "Creates a new limo booking with specified details. [See the documentation](https://api.limoexpress.me/api/docs/v1)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
limoexpress,
12+
bookingTypeId: {
13+
propDefinition: [
14+
limoexpress,
15+
"bookingTypeId",
16+
],
17+
},
18+
bookingStatusId: {
19+
propDefinition: [
20+
limoexpress,
21+
"bookingStatusId",
22+
],
23+
optional: true,
24+
},
25+
fromLocation: {
26+
propDefinition: [
27+
limoexpress,
28+
"fromLocation",
29+
],
30+
},
31+
pickupTime: {
32+
propDefinition: [
33+
limoexpress,
34+
"pickupTime",
35+
],
36+
},
37+
customerId: {
38+
type: "string",
39+
label: "Customer ID",
40+
description: "ID of the customer for the booking.",
41+
},
42+
toLocation: {
43+
type: "string",
44+
label: "To Location",
45+
description: "The dropoff location.",
46+
optional: true,
47+
},
48+
vehicleId: {
49+
type: "string",
50+
label: "Vehicle ID",
51+
description: "ID of the vehicle to be used for the booking.",
52+
optional: true,
53+
},
54+
},
55+
async run({ $ }) {
56+
const response = await this.limoexpress.createBooking({
57+
bookingTypeId: this.bookingTypeId,
58+
fromLocation: this.fromLocation,
59+
pickupTime: this.pickupTime,
60+
additionalFields: {
61+
booking_status_id: this.bookingStatusId,
62+
customer_id: this.customerId,
63+
to_location: this.toLocation,
64+
vehicle_id: this.vehicleId,
65+
},
66+
});
67+
68+
$.export("$summary", `Successfully created booking with ID ${response.id}`);
69+
return response;
70+
},
71+
};
Lines changed: 138 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,146 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "limoexpress",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
bookingTypeId: {
8+
type: "string",
9+
label: "Booking Type ID",
10+
description: "ID of the booking type.",
11+
async options() {
12+
const types = await this.listBookingTypes();
13+
return types.map((type) => ({
14+
label: type.name,
15+
value: type.id,
16+
}));
17+
},
18+
},
19+
bookingStatusId: {
20+
type: "string",
21+
label: "Booking Status ID",
22+
description: "ID of the booking status.",
23+
async options() {
24+
const statuses = await this.listBookingStatuses();
25+
return statuses.map((status) => ({
26+
label: status.name,
27+
value: status.id,
28+
}));
29+
},
30+
},
31+
bookingId: {
32+
type: "string",
33+
label: "Booking ID",
34+
description: "The ID of the booking.",
35+
},
36+
driverId: {
37+
type: "string",
38+
label: "Driver ID",
39+
description: "The ID of the driver to assign to the booking.",
40+
},
41+
fromLocation: {
42+
type: "string",
43+
label: "From Location",
44+
description: "The pickup location.",
45+
},
46+
pickupTime: {
47+
type: "string",
48+
label: "Pickup Time",
49+
description: "The time scheduled for pickup.",
50+
},
51+
cancellationReason: {
52+
type: "string",
53+
label: "Cancellation Reason",
54+
description: "Reason for canceling the booking.",
55+
optional: true,
56+
},
57+
assignmentNotes: {
58+
type: "string",
59+
label: "Assignment Notes",
60+
description: "Additional notes for the driver assignment.",
61+
optional: true,
62+
},
63+
},
564
methods: {
6-
// this.$auth contains connected account data
765
authKeys() {
866
console.log(Object.keys(this.$auth));
967
},
68+
_baseUrl() {
69+
return "https://api.limoexpress.me/api/v1";
70+
},
71+
async _makeRequest(opts = {}) {
72+
const {
73+
$ = this, method = "GET", path = "/", headers, ...otherOpts
74+
} = opts;
75+
return axios($, {
76+
...otherOpts,
77+
method,
78+
url: this._baseUrl() + path,
79+
headers: {
80+
...headers,
81+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
82+
},
83+
});
84+
},
85+
async listBookingTypes(opts = {}) {
86+
return this._makeRequest({
87+
path: "/booking_types",
88+
...opts,
89+
});
90+
},
91+
async listBookingStatuses(opts = {}) {
92+
return this._makeRequest({
93+
path: "/booking_statuses",
94+
...opts,
95+
});
96+
},
97+
async createBooking({
98+
bookingTypeId, fromLocation, pickupTime, ...opts
99+
}) {
100+
return this._makeRequest({
101+
method: "POST",
102+
path: "/bookings",
103+
data: {
104+
booking_type_id: bookingTypeId,
105+
from_location: fromLocation,
106+
pickup_time: pickupTime,
107+
},
108+
...opts,
109+
});
110+
},
111+
async cancelBooking({
112+
bookingId, cancellationReason, ...opts
113+
}) {
114+
return this._makeRequest({
115+
method: "POST",
116+
path: `/bookings/${bookingId}/cancel`,
117+
data: {
118+
cancellation_reason: cancellationReason,
119+
},
120+
...opts,
121+
});
122+
},
123+
async assignDriver({
124+
bookingId, driverId, assignmentNotes, ...opts
125+
}) {
126+
return this._makeRequest({
127+
method: "POST",
128+
path: `/bookings/${bookingId}/assign_driver`,
129+
data: {
130+
driver_id: driverId,
131+
assignment_notes: assignmentNotes,
132+
},
133+
...opts,
134+
});
135+
},
136+
async emitNewBookingEvent() {
137+
// Implementation for emitting new booking event
138+
},
139+
async emitCancelledBookingEvent() {
140+
// Implementation for emitting canceled booking event
141+
},
142+
async emitDriverAssignedEvent() {
143+
// Implementation for emitting driver assigned event
144+
},
10145
},
11-
};
146+
};

components/limoexpress/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import limoexpress from "../../limoexpress.app.mjs";
2+
import {
3+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
4+
} from "@pipedream/platform";
5+
6+
export default {
7+
key: "limoexpress-new-booking-instant",
8+
name: "New Limo Booking Created",
9+
description: "Emit new event when a customer creates a new limo booking. [See the documentation](https://api.limoexpress.me/api/docs/v1)",
10+
version: "0.0.{{ts}}",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
limoexpress,
15+
db: "$.service.db",
16+
timer: {
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
},
23+
methods: {
24+
_getLastBookingTime() {
25+
return this.db.get("lastBookingTime");
26+
},
27+
_setLastBookingTime(time) {
28+
this.db.set("lastBookingTime", time);
29+
},
30+
async fetchNewBookings(since) {
31+
return await this.limoexpress._makeRequest({
32+
path: "/bookings",
33+
params: {
34+
created_after: since,
35+
},
36+
});
37+
},
38+
},
39+
hooks: {
40+
async deploy() {
41+
const { results } = await this.limoexpress._makeRequest({
42+
path: "/bookings",
43+
});
44+
45+
results.slice(0, 50).forEach((booking) => {
46+
this.$emit(booking, {
47+
id: booking.id,
48+
summary: `New Booking: ${booking.id}`,
49+
ts: new Date(booking.created_at).getTime(),
50+
});
51+
});
52+
53+
if (results.length) {
54+
this._setLastBookingTime(results[0].created_at);
55+
}
56+
},
57+
},
58+
async run() {
59+
const lastBookingTime = this._getLastBookingTime();
60+
const { results: newBookings } = await this.fetchNewBookings(lastBookingTime);
61+
62+
newBookings.forEach((booking) => {
63+
const ts = new Date(booking.created_at).getTime();
64+
if (ts > new Date(lastBookingTime).getTime()) {
65+
this.$emit(booking, {
66+
id: booking.id,
67+
summary: `New Booking: ${booking.id}`,
68+
ts,
69+
});
70+
}
71+
});
72+
73+
if (newBookings.length) {
74+
this._setLastBookingTime(newBookings[0].created_at);
75+
}
76+
},
77+
};

0 commit comments

Comments
 (0)