const axios = require('axios');
const wrapAPIKey = require('./wrap-api-key');
const classifier = require('ammobin-classifier');

module.exports = function (type) {
  function fn(ammotype) {
    return axios({
      url: "https://wrapapi.com/use/meta-ammo-ca/theammosource/theammosource/latest",
      method: 'post',
      data: {
        ammotype,
        wrapAPIKey
      }
    }).then(d => {
      if(!d.data.data.items){
        console.warn('no items found for theammosource '+type);
        return [];
      }
      
      return d.data.data.items;
    });
  }


  switch (type) {
    case 'rimfire':
      return fn('1_9').then(classifier.classifyRimfire);
    case 'shotgun':
      return fn('1_48').then(classifier.classifyShotgun);
    case 'centerfire':
      return Promise.all([
        fn('1_33'), // pistol
        fn('1_40') // rifle
      ])
        .then(results => results.reduce((final, r) => final.concat(r), []))
        .then(classifier.classifyCenterFire);

    default:
      return Promise.reject(new Error('unknown type: ' + type));
  }
}

@@ -122,16 +122,524 @@
 ier');%0A%0A
+%0Afunction classifyRimfire(items) %7B%0A  return items.map(i =%3E %7B%0A    i.calibre = classifier.classifyRimfire(i.calibre %7C%7C i.name %7C%7C '').toUpperCase()%0A    return i;%0A  %7D);%0A%7D%0A%0Afunction classifyCenterfire(items) %7B%0A  return items.map(i =%3E %7B%0A    i.calibre = classifier.classifyCenterFire(i.calibre %7C%7C i.name %7C%7C '').toUpperCase()%0A    return i;%0A  %7D);%0A%7D%0A%0Afunction classifyShotgun(items) %7B%0A  return items.map(i =%3E %7B%0A    i.calibre = classifier.classifyShotgun(i.calibre %7C%7C i.name %7C%7C '').toUpperCase()%0A    return i;%0A  %7D);%0A%7D%0A%0A
 module.e
@@ -1132,35 +1132,24 @@
 '1_9').then(
-classifier.
 classifyRimf
@@ -1199,35 +1199,24 @@
 1_48').then(
-classifier.
 classifyShot

Update the-ammo-source.js (#8)