Advertisement
Xzahn

StationsAPI

Oct 26th, 2018
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import objArr from '../res/objArr'
  2.  
  3. class Station {
  4.     constructor({AddressInfo}) {
  5.         let {
  6.             Title: title,
  7.             AddressLine1: address,
  8.             Longitude: lng,
  9.             Latitude: lat
  10.         } = AddressInfo
  11.         this.title = title || 'NA'
  12.         this.address = address || 'NA'
  13.         this.lng = lng || 0
  14.         this.lat = lat || 0
  15.     }
  16.  
  17.     GetAddressInfo() {
  18.         return {
  19.             title: this.title,
  20.             address: this.address,
  21.             lat: this.lat,
  22.             lng: this.lng
  23.         }
  24.     }
  25.  
  26.     LogObject() {
  27.         console.log(
  28.             this.title,
  29.             this.address,
  30.             this.lng,
  31.             this.lat
  32.         )
  33.     }
  34. }
  35.  
  36. const getTest = () => {
  37.     let stations = []
  38.     Array.prototype.forEach.call(objArr, station => {
  39.         station = new Station(station).GetAddressInfo()
  40.  
  41.         stations.push(station)
  42.     })
  43.  
  44.     return stations
  45. }
  46.  
  47. const getAll = () => {
  48.     let stations = []
  49.  
  50.     fetch('URL')
  51.         .then(res => res.json())
  52.         .then(data => Array.prototype.forEach.call(data, station => {
  53.             station = new Station(station).GetAddressInfo()
  54.             stations.push(station)
  55.         }))
  56.    
  57.     return stations
  58. }
  59.  
  60. export { Station, getTest, getAll}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement