diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/crm_iap_lead_enrich/models/iap_enrich_api.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/crm_iap_lead_enrich/models/iap_enrich_api.py')
| -rw-r--r-- | addons/crm_iap_lead_enrich/models/iap_enrich_api.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/addons/crm_iap_lead_enrich/models/iap_enrich_api.py b/addons/crm_iap_lead_enrich/models/iap_enrich_api.py new file mode 100644 index 00000000..f6a85d28 --- /dev/null +++ b/addons/crm_iap_lead_enrich/models/iap_enrich_api.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, api +from odoo.addons.iap.tools import iap_tools + + +class IapEnrichAPI(models.AbstractModel): + _name = 'iap.enrich.api' + _description = 'IAP Lead Enrichment API' + _DEFAULT_ENDPOINT = 'https://iap-services.odoo.com' + + @api.model + def _contact_iap(self, local_endpoint, params): + account = self.env['iap.account'].get('reveal') + dbuuid = self.env['ir.config_parameter'].sudo().get_param('database.uuid') + params['account_token'] = account.account_token + params['dbuuid'] = dbuuid + base_url = self.env['ir.config_parameter'].sudo().get_param('enrich.endpoint', self._DEFAULT_ENDPOINT) + return iap_tools.iap_jsonrpc(base_url + local_endpoint, params=params, timeout=300) + + @api.model + def _request_enrich(self, lead_emails): + """ Contact endpoint to get enrichment data. + + :param lead_emails: dict{lead_id: email} + :return: dict{lead_id: company data or False} + :raise: several errors, notably + * InsufficientCreditError: { + "credit": 4.0, + "service_name": "reveal", + "base_url": "https://iap.odoo.com/iap/1/credit", + "message": "You don't have enough credits on your account to use this service." + } + """ + params = { + 'domains': lead_emails, + } + return self._contact_iap('/iap/clearbit/1/lead_enrichment_email', params=params) |
