@@ -27,7 +27,7 @@ function cleanRepo(repo) {
2727
2828class 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
0 commit comments