diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-27 13:57:42 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-02-27 13:57:42 +0700 |
| commit | 3b2f11da025094d676b2eea0b32794852dc9f748 (patch) | |
| tree | 22c69c845319dbc23cd0e1acaef5680818e76e50 | |
| parent | ae1c2a5daeffb13cffb010c2b9db062f3baf10e8 (diff) | |
Create Wati API Model
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/wati_api.py | 52 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 |
3 files changed, 54 insertions, 0 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index ebbf2e09..b45cd8c5 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -51,3 +51,4 @@ from . import leads_monitoring from . import midtrans from . import ip_lookup from . import wati +from . import wati_api diff --git a/indoteknik_custom/models/wati_api.py b/indoteknik_custom/models/wati_api.py new file mode 100644 index 00000000..156483f6 --- /dev/null +++ b/indoteknik_custom/models/wati_api.py @@ -0,0 +1,52 @@ +from odoo import models +import requests +import urllib.parse +from odoo.exceptions import UserError +import json + +class WatiApi(models.Model): + _name = 'wati.api' + + def api_header(self): + api_token = self.env['ir.config_parameter'].get_param('wati.api_token') + return { + "Authorization": "Bearer %s" % api_token + } + + def api_url(self): + return self.env['ir.config_parameter'].get_param('wati.api_url') + + def http_get(self, endpoint: str, url_params: dict): + try: + url_params = urllib.parse.urlencode(url_params) + url = "%s/%s?%s" % (self.api_url(), endpoint, url_params) + headers = self.api_header() + response = requests.get(url, headers=headers) + return response.json() + except Exception: + return Exception + + def http_post(self, endpoint: str, data: dict): + try: + url = "%s/%s" % (self.api_url(), endpoint) + headers = self.api_header() + response = requests.post(url, headers=headers, json=data) + return response.json() + except Exception: + return Exception + + def _test(self, method): + res = False + if method == 'GET': + res = self.http_get('v1/getContacts', { + "name": 'Darren', + "pageSize": 10, + "pageNumber": 1 + }) + elif method == 'POST': + res = self.http_post('v1/updateContactAttributes/6281290696017', { + "customParams": [{"name": "name", "value": "Darren"}] + }) + + raise UserError(json.dumps(res, indent=4, sort_keys=True)) +
\ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index d5142381..8109cefe 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -34,5 +34,6 @@ access_midtrans_account,access.midtrans.account,model_midtrans_account,,1,1,1,1 access_ip_lookup,access.ip.lookup,model_ip_lookup,,1,1,1,1 access_ip_lookup_line,access.ip.lookup.line,model_ip_lookup_line,,1,1,1,1 access_wati_notification,access.wati.notification,model_wati_notification,,1,1,1,1 +access_wati_api,access.wati.api,model_wati_api,,1,1,1,1 access_user_company_request,access.user.company.request,model_user_company_request,,1,1,1,1 access_res_partner_company_type,access.res.partner.company_type,model_res_partner_company_type,,1,1,1,1
\ No newline at end of file |
