Add model

This commit is contained in:
Emmanuel Cazenave 2019-04-07 19:37:02 +02:00
parent c9be406aad
commit e249fd54d2
2 changed files with 94 additions and 0 deletions

View File

View File

@ -0,0 +1,94 @@
# passerelle.contrib.iws
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.db import models
from django.utils.translation import ugettext_lazy as _
from passerelle.base.models import BaseResource
from passerelle.utils.api import endpoint
from passerelle.utils.jsonresponse import APIError
class GithubConnector(BaseResource):
api_url = models.URLField(
max_length=400, verbose_name=_('Github API endpoint'),
help_text=_('Github API endpoint'))
github_user = models.URLField(
max_length=400, verbose_name=_('Github user'))
github_repo = models.CharField(max_length=128, verbose_name=_('Github repo'))
github_token = models.CharField(max_length=128, verbose_name=_('Github token'))
category = _('Business Process Connectors')
class Meta:
verbose_name = _('Github connector')
@endpoint(methods=['get'], perm='can_access')
def getissue(self, request, issue_num):
url = '%s/repos/%s/%s/issues/%s' % (
self.api_url, self.github_user, self.github_repo, issue_num)
response = self.requests(url, auth=(self.github_user, self.github_token))
try:
response.raise_for_status()
except Exception:
raise APIError('Something terrible happened')
data = response.json()
res = {
'title': data['title'],
'state': data['state']
}
return res
# @endpoint(perm='can_access',
# post={
# 'description': _('Blah'),
# 'request_body': {
# 'schema': {
# 'application/json': BOOKDATE_SCHEMA
# }
# }
# })
# def bookdate(self, request, post_data):
# data = post_data
# iws_data = {
# 'NO_APPEL': data['token'],
# 'I_APP_DEMANDEUR': '%s, %s' % (data['lastname'], data['firstname']),
# 'I_AP_DATRDVAGENDA': data['date'],
# 'C_STAPPEL': 'E',
# 'I_AP_SERVICE': 'OFFICE',
# 'I_AP_SOURCE': 'USAGER',
# 'C_ORIGINE': 'TELESERVICE',
# 'C_BLOCAGE': 2,
# 'I_AP_EMAIL': 'NON',
# 'I_AP_ADRESSEMAIL': '',
# 'I_AP_CNIL': 1,
# 'I_AP_SMS': 'NON',
# 'I_AP_TEL_DEMANDEU': '',
# 'DE_SYMPAPPEL': data['description'] or '',
# 'C_QUALIFICATIF': 'INTERVENTION',
# }
# if 'email' in data:
# iws_data['I_AP_ADRESSEMAIL'] = data['email']
# iws_data['I_AP_EMAIL'] = 'OUI' if data['email_notif'] else 'NON'
# if 'tel_number' in data:
# iws_data['I_AP_TEL_DEMANDEU'] = data['tel_number']
# iws_res = self._soap_call(iws_data, 'IsiUpdateAndGetCall')
# self._check_status(iws_res)
# return {'data': iws_res['fields']}