Skip to content

Commit

Permalink
making token optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Angamanga committed May 12, 2020
1 parent 365ea09 commit c1470ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ushahidi-platform-sdk",
"version": "0.1.4",
"version": "0.1.5",
"description": "An SDK for the Ushahidi Platform - V3+ compatible",
"engines": {
"node": ">= 10 <13"
Expand Down
14 changes: 6 additions & 8 deletions src/surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ export class Surveys {
backendUrl:string;
token:string;

constructor (backendUrl:string, token:string) {
constructor (backendUrl:string, token?:string) {
this.backendUrl = backendUrl;
this.token = token;
}

async getSurveys(id?:string):Promise<unknown> {
try {
const url = id ? `${this.backendUrl}/api/v4/surveys/${id}` : `${this.backendUrl}/api/v4/surveys/`;
const response = await axios.get(url, {
headers: {
"Authorization": `Bearer ${this.token}`
}
});

const config = this.token ? {
headers: {"Authorization": `Bearer ${this.token}`}
} : {}
const response = await axios.get(url, config);
return response.data.result || response.data.results;
}
catch(err) {
Expand All @@ -41,4 +39,4 @@ export class Surveys {
});
return res;
}
}
}

0 comments on commit c1470ab

Please sign in to comment.