this method do the request petition, receive the different methods (post, delete, patch, get) that the api allow, see the documentation to check how to use the filters https://msdn.microsoft.com/en-us/library/gg309461(v=crm.7).aspx :param method: :par
(self, method, endpoint, expand=None, filter=None, orderby=None, select=None, skip=None, top=None,
data=None, json=None, **kwargs)
| 13 | self.token = token |
| 14 | |
| 15 | def make_request(self, method, endpoint, expand=None, filter=None, orderby=None, select=None, skip=None, top=None, |
| 16 | data=None, json=None, **kwargs): |
| 17 | """ |
| 18 | this method do the request petition, receive the different methods (post, delete, patch, get) that the api allow, see the documentation to check how to use the filters |
| 19 | https://msdn.microsoft.com/en-us/library/gg309461(v=crm.7).aspx |
| 20 | :param method: |
| 21 | :param endpoint: |
| 22 | :param expand: |
| 23 | :param filter: |
| 24 | :param orderby: |
| 25 | :param select: |
| 26 | :param skip: |
| 27 | :param top: |
| 28 | :param data: |
| 29 | :param json: |
| 30 | :param kwargs: |
| 31 | :return: |
| 32 | """ |
| 33 | extra = {} |
| 34 | if expand is not None and isinstance(expand, str): |
| 35 | extra['$expand'] = str(expand) |
| 36 | if filter is not None and isinstance(filter, str): |
| 37 | extra['$filter'] = filter |
| 38 | if orderby is not None and isinstance(orderby, str): |
| 39 | extra['$orderby'] = orderby |
| 40 | if select is not None and isinstance(select, str): |
| 41 | extra['$select'] = select |
| 42 | if skip is not None and isinstance(skip, str): |
| 43 | extra['$skip'] = skip |
| 44 | if top is not None and isinstance(top, str): |
| 45 | extra['$top'] = str(top) |
| 46 | |
| 47 | extra = '&'.join(['{0}={1}'.format(k, v) for k, v in extra.items()]) |
| 48 | url = '{0}/{1}?{2}'.format(self.api_base_url, endpoint, extra) |
| 49 | if self.token: |
| 50 | self.header["Authorization"] = "Bearer " + self.token |
| 51 | |
| 52 | if method == "get": |
| 53 | response = requests.request(method, url, headers=self.header, params=kwargs) |
| 54 | else: |
| 55 | response = requests.request(method, url, headers=self.header, data=data, json=json) |
| 56 | return self.parse_response(response) |
| 57 | else: |
| 58 | raise Exception("To make petitions the token is necessary") |
| 59 | |
| 60 | def _get(self, endpoint, data=None, **kwargs): |
| 61 | return self.make_request('get', endpoint, data=data, **kwargs) |
no test coverage detected