import request from 'superagent'
require('dotenv').config()
import queryString from 'query-string'



export default (lat = -41.2865, long = 174.7762, radius = 1000) => {
	let query = queryString.stringify({		
			location: lat + '\,' + long,
			radius: radius,
			types: 'cafe|restaurant|food|bakery',
			key: process.env.GOOGLE_API_KEY,

		},false)
	
console.log(query, "this is query")
console.log("----------------------")


	return new Promise ((resolve, rej) => {
		request
		  .get('https://maps.googleapis.com/maps/api/place/nearbysearch/json?' + query )
		  .end(function(err, res){
		  	if(err) {
		  		console.log('there has been an error in superagent', err)
		  		rej(err)
		  	} else {
		  		
					resolve(res)	      
		    }
	   })	

		
	})
}



@@ -227,9 +227,8 @@
  + '
-%5C
 ,' +
@@ -346,85 +346,8 @@
 se)%0A
-%09%0Aconsole.log(query, %22this is query%22)%0Aconsole.log(%22----------------------%22)%0A%0A
 %0A%09re
@@ -485,163 +485,1229 @@
 %09%09  
-.end(function(err, res)%7B%0A%09%09  %09if(err) %7B%0A%09%09  %09%09console.log('there has been an error in superagent', err)%0A%09%09  %09%09rej(err)%0A%09%09  %09%7D else %7B%0A%09%09  %09%09%0A%09%09%09%09%09resolve(re
+// .then((res) =%3E %7B%0A%09%09  %09// let restArray = res.body.results%0A%09%09  %09// let nextPageToken = res.body.next_page_token%0A%09%09  %09// let cleanRestaurants = restArray.map( function ( restObj ) %7B%0A%09%09  %09// %09console.log(%22in map function%22, restObj)%0A%09%09  %09%09%0A%09%09  %09// %09return %7B%0A%09%09  %09// %09%09%22id%22: restObj.id,%0A%09%09  %09// %09%09%22name%22: restObj.name,%0A%09%09  %09// %09%09%22open_now%22: restObj.opening_hours.open_now,%0A%09%09  %09// %09%7D%0A%09%09  %09// %7D)%0A%09%09  %09// console.log(cleanRestaurants, %22please be a nice clean object %22)%0A%09%09  %09// console.log(%22------------------------------------------------%22)%0A%0A%09%09  // %7D)%0A%09%09  .end(function(err, res)%7B%0A%09%09  %09if(err) %7B%0A%09%09  %09%09console.log('there has been an error in superagent', err)%0A%09%09  %09%09rej(err)%0A%09%09  %09%7D else %7B%0A%09%09  %09%09let restArray = res.body.results%0A%09%09  %09let nextPageToken = res.body.next_page_token%0A%09%09  %09let cleanRestaurants = restArray.map( function ( restObj ) %7B%0A%09%09  %09%09console.log(%22in map function%22, restObj.geometry)%0A%09%09  %09%09%0A%09%09  %09%09return %7B%0A%09%09  %09%09%09%22id%22: restObj.id,%0A%09%09  %09%09%09%22name%22: restObj.name//,%0A%09%09  %09%09%09// %22open_now%22: restObj%5B%22opening_hours%22%5D%5B%22open_now%22%5D%0A%09%09  %09%09%7D%0A%09%09  %09%7D)%0A%09%09  %09console.log(cleanRestaurants, %22please be a nice clean object %22)%0A%09%09  %09console.log(%22------------------------------------------------%22)%0A%09%09  %09%09%0A%09%09%09%09%09resolve(cleanRestaurant
 s)%09 

remove open_hours and opening_hours