Skip to content

Enable public api #10

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updated Urls for workschedule APIs, these will possibly be deprecated…
… soon when v3 APIs are release
  • Loading branch information
tkla committed Jun 7, 2022
commit f768af5c0f3629cfd460d3934db70fcad0c445ca
44 changes: 37 additions & 7 deletions lib/EnvoyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,41 @@ class EnvoyAPI {
})

// Currently the route returns only a status code 204 for success. For now just return object indicating success.
return { "message" : "Success" };
return { "message": "Success" };
}

/**
* Fetches a WorkSchedule.
* @param { number | string } workSchedule Id.
*/
async workSchedule(workScheduleId) {
var options = {
method: 'GET',
url: `https://api.envoy.com/v1/work-schedules/${workScheduleId}`,
headers: {
Authorization: 'Bearer ' + this.token
},
json: true,
};

const body = await request(options, function (error, response) {
if (error) throw new Error(error);
response.body;
});

return EnvoyAPI.getDataFromBody(body);
}

/**
* Fetches a list of WorkSchedules.
* @param {{}} workSchedule object.
*/
async workSchedules(workSchedule) {
var options = {
'method': 'GET',
'url': 'https://api.envoy.com/v1/work-schedules',
'headers': {
'Authorization': 'Bearer ' + this.token
method: 'GET',
url: 'https://api.envoy.com/v1/work-schedules',
headers: {
Authorization: 'Bearer ' + this.token
},
body: workSchedule,
json: true,
Expand All @@ -384,10 +405,19 @@ class EnvoyAPI {
* @param {{}} workSchedule - Work object with locationId, email, expectedArrivalAt (UTC date time format)
*/
async createWorkSchedule(workSchedule) {
const body = await this.request({
var options = {
method: 'POST',
url: `/api/v1/work-schedules`,
url: `https://api.envoy.com/v1/work-schedules`,
headers: {
Authorization: 'Bearer ' + this.token
},
body: workSchedule,
json: true,
};

const body = await request(options, function (error, response) {
if (error) throw new Error(error);
response.body;
});

return EnvoyAPI.getDataFromBody(body);
Expand Down