Skip to content
This repository was archived by the owner on Jan 4, 2022. It is now read-only.

Commit 995347f

Browse files
committed
updated client
1 parent 5bc4ca9 commit 995347f

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@code.gov/api-client",
3-
"version": "0.2.9",
3+
"version": "0.2.10",
44
"description": "Client for Interacting with Code.gov API",
55
"main": "dist/bundle.js",
66
"scripts": {

src/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function cleanRepo(repo) {
2727

2828
class CodeGovAPIClient {
2929
constructor(options = {}) {
30-
this.base = options.base || 'https://api.code.gov/'
30+
this._base = options.base || 'https://api.code.gov/'
3131
this.remember = options.remember || false
3232
this.debug = options.debug || false
3333
this.tasksUrl = options.tasksUrl || 'https://raw.githubusercontent.com/GSA/code-gov-data/master/help-wanted.json'
@@ -71,7 +71,7 @@ class CodeGovAPIClient {
7171
* });
7272
*/
7373
getAgencies(size = 10) {
74-
const url = `${this.base}agencies?api_key=${this.api_key}&size=${size}`
74+
const url = `${this._base}agencies?api_key=${this.api_key}&size=${size}`
7575
return get(url).then(response => {
7676
return response.data.agencies.sort((a, b) => {
7777
return (a.name || a.term).toLowerCase() < (b.name || b.term).toLowerCase() ? -1 : 1
@@ -142,10 +142,9 @@ class CodeGovAPIClient {
142142
* });
143143
*/
144144
getRepoById(repoId = '') {
145-
let url = `${this.base}repos/${repoId}`
145+
let url = `${this._base}repos/${repoId}`
146146
if (this.api_key) url += `?api_key=${this.api_key}`
147-
return get(url).then(response => {
148-
const { data } = response
147+
return this.getJSON(url).then(data => {
149148
// if the response is returned as an array
150149
if (some(data)) {
151150
return data[0]
@@ -171,10 +170,11 @@ class CodeGovAPIClient {
171170
*/
172171
suggest(term = '', size = 10) {
173172
if (term && term.length > 2) {
174-
let url = `${this.base}terms?term=${term}&size=${size}`
173+
let url = `${this._base}terms?term=${term}&size=${size}`
175174
if (this.api_key) url += `&api_key=${this.api_key}`
176175
if (this.debug) console.log('url:', url)
177-
return get(url).then(response => response.data.terms)
176+
return this.getJSON(url)
177+
.then(data => data.terms.map(term => term.term))
178178
}
179179
else {
180180
return Promise.resolve([])
@@ -198,7 +198,7 @@ class CodeGovAPIClient {
198198
from = this.from
199199
}
200200

201-
let url = `${this.base}repos?size=${size}&api_key=${this.api_key}`
201+
let url = `${this._base}repos?size=${size}&api_key=${this.api_key}`
202202

203203
if (from && from > 0) {
204204
url += `&from=${from}`
@@ -246,7 +246,6 @@ class CodeGovAPIClient {
246246
if (this.debug) console.log('fetching url:', url)
247247

248248
return this.getJSON(url).then(dirty => {
249-
console.log('dirty:', dirty);
250249
dirty.repos = dirty.repos.map(cleanRepo)
251250
return dirty
252251
})
@@ -272,7 +271,7 @@ class CodeGovAPIClient {
272271
}
273272

274273
getStatus() {
275-
return this.getJSON(`${this.base}status.json`)
274+
return this.getJSON(`${this._base}status.json`)
276275
}
277276

278277

test/test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let CodeGovAPIClient = require("../src/index.js").CodeGovAPIClient;
55
let client = new CodeGovAPIClient({
66
api_key: process.env.CODE_GOV_API_KEY,
77
base: process.env.CODE_GOV_API_BASE,
8-
debug: true
8+
debug: false
99
});
1010

1111
describe('Getting Information', function() {
@@ -70,7 +70,7 @@ describe('Getting Information', function() {
7070
this.timeout(50000);
7171
client.suggest("National").then(searchResults => {
7272
expect(searchResults.length).to.be.above(2);
73-
expect(searchResults[0].term.toLowerCase()).to.have.string('national');
73+
expect(searchResults[0].toLowerCase()).to.have.string('national');
7474
done();
7575
});
7676
});
@@ -89,8 +89,9 @@ describe('Getting Information', function() {
8989
describe("Getting Individual Repositories", function() {
9090
it("should get correct result", function(done) {
9191
this.timeout(50000);
92-
let repoId = "cfpb_new_clouseau_";
93-
client.getRepoById(repoId).then(repo => {
92+
let repoID = "doe_sandia_national_laboratories_snl_water_network_tool_for_resilience_v_1_0";
93+
client.getRepoById(repoID).then(repo => {
94+
expect(repo.repoID).to.equal(repoID)
9495
done();
9596
});
9697
});

0 commit comments

Comments
 (0)