summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosue Kouka <jkouka@entrouvert.com>2016-02-24 15:41:22 (GMT)
committerJosue Kouka <jkouka@entrouvert.com>2016-02-25 13:47:38 (GMT)
commitf4ce873eb2648862edc4f9bf81d805a93fffb31e (patch)
tree9a705fa1b17708b9bcc5cacfddb217af40761c94
parentb4e06be793de0caa67fcf42af7127be48a241f41 (diff)
downloadpasserelle-paris-poc-gru-f4ce873eb2648862edc4f9bf81d805a93fffb31e.zip
passerelle-paris-poc-gru-f4ce873eb2648862edc4f9bf81d805a93fffb31e.tar.gz
passerelle-paris-poc-gru-f4ce873eb2648862edc4f9bf81d805a93fffb31e.tar.bz2
update paris poc gru connector model (#10073)
-rw-r--r--passerelle_paris_poc_gru/migrations/0002_auto_20160225_0743.py32
-rw-r--r--passerelle_paris_poc_gru/models.py32
2 files changed, 64 insertions, 0 deletions
diff --git a/passerelle_paris_poc_gru/migrations/0002_auto_20160225_0743.py b/passerelle_paris_poc_gru/migrations/0002_auto_20160225_0743.py
new file mode 100644
index 0000000..c8fc37c
--- /dev/null
+++ b/passerelle_paris_poc_gru/migrations/0002_auto_20160225_0743.py
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('passerelle_paris_poc_gru', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='parispocgru',
+ name='consumer_key',
+ field=models.CharField(default=b'not provided', max_length=128, verbose_name='Consumer Key'),
+ preserve_default=True,
+ ),
+ migrations.AddField(
+ model_name='parispocgru',
+ name='consumer_secret',
+ field=models.CharField(default=b'not provided', max_length=128, verbose_name='Consumer Secret'),
+ preserve_default=True,
+ ),
+ migrations.AddField(
+ model_name='parispocgru',
+ name='url',
+ field=models.CharField(default=b'not provided', max_length=128, verbose_name='WebService Base Url'),
+ preserve_default=True,
+ ),
+ ]
diff --git a/passerelle_paris_poc_gru/models.py b/passerelle_paris_poc_gru/models.py
index 61088dd..15f1bdf 100644
--- a/passerelle_paris_poc_gru/models.py
+++ b/passerelle_paris_poc_gru/models.py
@@ -13,7 +13,10 @@
#
# 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/>.
+import base64
+import requests
+from django.db import models
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
@@ -21,6 +24,18 @@ from passerelle.base.models import BaseResource
class ParisPocGru(BaseResource):
+ url = models.CharField(max_length=128, blank=False,
+ default="not provided", verbose_name=_('WebService Base Url')
+ )
+
+ consumer_key = models.CharField(max_length=128, blank=False,
+ default="not provided", verbose_name=_('Consumer Key')
+ )
+
+ consumer_secret = models.CharField(max_length=128, blank=False,
+ default="not provided", verbose_name=_('Consumer Secret')
+ )
+
category = _('Business Process Connectors')
class Meta:
@@ -40,3 +55,20 @@ class ParisPocGru(BaseResource):
@classmethod
def get_icon_class(cls):
return 'ressources'
+
+ def get_access_token(self):
+ cred = base64.b64encode('%s:%s' %(self.consumer_key, self.consumer_secret))
+ response = requests.post(
+ self.url+'/token',
+ headers = {
+ 'Authorization': 'Basic %s' %cred,
+ 'Content-Type': 'application/x-www-form-urlencoded'
+ },
+ data = {'grant_type': 'client_credentials'}
+ )
+
+ self.access_token = response.json()['access_token']
+ self.headers = {'Authorization': 'Bearer %s' %(self.access_token)}
+
+ return self.access_token
+