File tree Expand file tree Collapse file tree 3 files changed +34
-23
lines changed
Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ export function loadProjects(searchTerm) {
1515 api : projectService ,
1616 method : 'getProjects' ,
1717 args : { searchTerm} ,
18- success : ( ) => { console . log ( 'dispatch success action' ) } ,
18+ success : ( resp ) => {
19+ console . log ( 'dispatch success action' )
20+ console . log ( resp )
21+ } ,
1922 failure : ( ) => { console . log ( 'dispatch failure action' ) }
2023 }
2124 }
@@ -53,4 +56,4 @@ export function projectSuggestions(searchTerm) {
5356 } )
5457
5558 } )
56- }
59+ }
Original file line number Diff line number Diff line change 1+ class BaseService {
2+ constructor ( ) {
3+ this . token = null
4+ }
5+
6+ setToken ( token ) {
7+ this . token = token
8+ }
9+
10+ getToken ( ) {
11+ return this . token
12+ }
13+
14+ getOptions ( requiresAuth ) {
15+ const options = { }
16+ const myHeaders = new Headers ( )
17+ if ( requiresAuth ) {
18+ myHeaders . append ( 'Authorization' , 'Basic ' + this . token ) //TODO use constants
19+ }
20+ options . headers = myHeaders
21+ return options
22+ }
23+ }
24+
25+ export default BaseService
Original file line number Diff line number Diff line change 1- // import _ from 'lodash '
1+ import BaseService from './baseService '
22import { fetchJSON } from '../helpers'
33
4- class ProjectService {
4+ class ProjectService extends BaseService {
55 constructor ( ) {
6- this . token = null
6+ super ( )
77 this . getProjects = this . getProjects . bind ( this )
88 this . getOptions = this . getOptions . bind ( this )
99 }
@@ -15,29 +15,12 @@ class ProjectService {
1515 return false
1616 }
1717
18- setToken ( token ) {
19- this . token = token
20- }
21-
22- getToken ( ) {
23- return this . token
24- }
25-
2618 getProjects ( searchTerm ) {
19+ console . log ( searchTerm )
2720 const options = this . getOptions ( true )
2821 options . method = 'GET' //TODO use constants
2922 return fetchJSON ( 'https://api.topcoder-dev.com/v3/challenges/' , options )
3023 }
31-
32- getOptions ( requiresAuth ) {
33- const options = { }
34- const myHeaders = new Headers ( )
35- if ( requiresAuth ) {
36- myHeaders . append ( 'Authorization' , 'Basic ' + this . token ) //TODO use constants
37- }
38- options . headers = myHeaders
39- return options
40- }
4124}
4225
4326export default new ProjectService ( )
You can’t perform that action at this time.
0 commit comments