# Copyright (c) 2019, SolutionERP LLC and contributors
# For license information, please see license.txt


import xhiveframework
import requests
from xhiveframework import _
from xhiveframework.model.document import Document


class ExotelSettings(Document):
	def validate(self):
		self.verify_credentials()

	def verify_credentials(self):
		if self.enabled:
			response = requests.get(
				"https://api.exotel.com/v1/Accounts/{sid}".format(sid=self.account_sid),
				auth=(self.api_key, self.api_token),
			)
			if response.status_code != 200:
				xhiveframework.throw(_("Invalid credentials"))
