import requests


def send_request(origin_addresses, dest_addresses, API_key):
	""" Build and send request for the given origin and destination addresses."""
	def build_address_str(addresses):
		# Build a pipe-separated string of addresses
		address_str = ''
		for i in range(len(addresses) - 1):
			address_str += addresses[i] + '|'
		address_str += addresses[-1]
		return address_str
	request = 'https://maps.googleapis.com/maps/api/distancematrix/json?units=metric'
	origin_address_str = build_address_str(origin_addresses)
	dest_address_str = build_address_str(dest_addresses)
	request += '&origins=' + origin_address_str + '&destinations=' + dest_address_str + '&key=' + API_key
	json_result = requests.get(request)
	response = json_result.json()
	return response