all files / src/app/utils/ github.service.js

100% Statements 11/11
100% Branches 0/0
100% Functions 5/5
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31               11×                          
const API_HOST = 'https://api.github.com/';
const SECOND_SEARCH = {
  repos: 'contributors',
  users: 'repos'
};
 
export class GitHubService {
  /** @ngInject */
  constructor($http) {
    this.http = $http;
  }
 
  getResource(type, value) {
    const url = `${API_HOST}${type}/${value}`;
    let result;
    let prop;
 
    return this.http.get(url)
      .then(res => {
        result = res.data;
        prop = SECOND_SEARCH[type];
        return result[`${prop}_url`];
      })
      .then(url => this.http.get(url))
      .then(res => {
        result[prop] = res.data;
        return result;
      });
  }
}