import axios from 'axios';

if(process.browser)
{
	FormData.prototype.appendObject = function(obj, namespace) 
	{
		let keyName;
		for (var key in obj) 
		{
			if (obj.hasOwnProperty(key)) 
			{
				keyName = [namespace, '[', key, ']'].join('');
				this.append(keyName, obj[key]);
			}
		}
	};	
}

export const getAnnouncements = () => 
{
	return new Promise((resolve, reject) => 
	{
		axios.get(`${ process.env.NEXT_PUBLIC_API_HOST }/api/announcements/`)
		.then((response) => 
		{
			resolve(response.data.announcements);
		})
		.catch((error) => 
		{
			console.error(error);
		});		
	});
}