From 5fcb4952f1be4b83271bf266f5e13a25ee96d5ad Mon Sep 17 00:00:00 2001 From: Miguel Ferrer Date: Thu, 5 Sep 2019 16:14:43 -0500 Subject: [PATCH 1/3] Rework library Drop support for basic authentication --- pipedrive/activities.py | 22 ++ pipedrive/client.py | 572 +++++++------------------------------ pipedrive/deals.py | 76 +++++ pipedrive/exceptions.py | 52 ++++ pipedrive/filters.py | 22 ++ pipedrive/notes.py | 22 ++ pipedrive/organizations.py | 22 ++ pipedrive/persons.py | 30 ++ pipedrive/pipelines.py | 14 + pipedrive/products.py | 30 ++ pipedrive/recents.py | 7 + pipedrive/test.py | 3 - pipedrive/users.py | 14 + pipedrive/webhooks.py | 21 ++ setup.py | 9 +- 15 files changed, 437 insertions(+), 479 deletions(-) create mode 100644 pipedrive/activities.py create mode 100644 pipedrive/deals.py create mode 100644 pipedrive/exceptions.py create mode 100644 pipedrive/filters.py create mode 100644 pipedrive/notes.py create mode 100644 pipedrive/organizations.py create mode 100644 pipedrive/persons.py create mode 100644 pipedrive/pipelines.py create mode 100644 pipedrive/products.py create mode 100644 pipedrive/recents.py delete mode 100644 pipedrive/test.py create mode 100644 pipedrive/users.py create mode 100644 pipedrive/webhooks.py diff --git a/pipedrive/activities.py b/pipedrive/activities.py new file mode 100644 index 0000000..c7208a1 --- /dev/null +++ b/pipedrive/activities.py @@ -0,0 +1,22 @@ +class Activities(object): + def __init__(self, client): + self._client = client + + def get_activities(self, activity_id=None, **kwargs): + if activity_id is not None: + url = 'activities/{}'.format(activity_id) + else: + url = 'activities' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_activity(self, data, **kwargs): + url = 'activities' + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_activity(self, activity_id, data, **kwargs): + url = 'activities/{}'.format(activity_id) + return self._client._put(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_activity(self, activity_id, **kwargs): + url = 'activities/{}'.format(activity_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/client.py b/pipedrive/client.py index 462d51e..8c32dd8 100644 --- a/pipedrive/client.py +++ b/pipedrive/client.py @@ -1,494 +1,122 @@ -from base64 import b64encode from urllib.parse import urlencode import requests +from pipedrive import exceptions +from pipedrive.activities import Activities +from pipedrive.deals import Deals +from pipedrive.filters import Filters +from pipedrive.notes import Notes +from pipedrive.organizations import Organizations +from pipedrive.persons import Persons +from pipedrive.pipelines import Pipelines +from pipedrive.products import Products +from pipedrive.recents import Recents +from pipedrive.users import Users +from pipedrive.webhooks import Webhooks + class Client: - oauth_flow_base_url = "https://oauth.pipedrive.com/oauth/" - oauth_api_base_url = "https://api-proxy.pipedrive.com/" - oauth_end = "authorize?" - token_end = "token" - api_version = "v1/" - header = {"Accept": "application/json, */*", "content-type": "application/json"} + BASE_URL = 'https://api-proxy.pipedrive.com/' + OAUTH_BASE_URL = 'https://oauth.pipedrive.com/oauth/' - def __init__(self, api_base_url, client_id=None, client_secret=None, oauth=False): + def __init__(self, client_id=None, client_secret=None): self.client_id = client_id self.client_secret = client_secret - self.oauth = oauth - self.api_base_url = api_base_url - self.token = None - - def make_request(self, method, endpoint, data=None, json=None, **kwargs): - """ - this method do the request petition, receive the different methods (post, delete, patch, get) that the api allow - :param method: - :param endpoint: - :param data: - :param kwargs: - :return: - """ - if self.token: - if self.oauth: - self.header["Authorization"] = "Bearer " + self.token - url = '{0}{1}'.format(self.oauth_api_base_url, endpoint) - else: - url = '{0}{1}{2}?api_token={3}'.format(self.api_base_url, self.api_version, endpoint, self.token) - if method == "get": - response = requests.request(method, url, headers=self.header, params=kwargs) - else: - response = requests.request(method, url, headers=self.header, data=data, json=json) - return self.parse_response(response) - else: - raise Exception("To make petitions the token is necessary") - - def _get(self, endpoint, data=None, **kwargs): - return self.make_request('get', endpoint, data=data, **kwargs) - - def _post(self, endpoint, data=None, json=None, **kwargs): - return self.make_request('post', endpoint, data=data, json=json, **kwargs) - - def _delete(self, endpoint, **kwargs): - return self.make_request('delete', endpoint, **kwargs) - - def _put(self, endpoint, json=None, **kwargs): - return self.make_request('put', endpoint, json=json, **kwargs) - - def parse_response(self, response): - """ - This method get the response request and returns json data or raise exceptions - :param response: - :return: - """ - if response.status_code == 204 or response.status_code == 201: - return True - elif response.status_code == 400: - raise Exception( - "The URL {0} retrieved an {1} error. Please check your request body and try again.\nRaw message: {2}".format( - response.url, response.status_code, response.text)) - elif response.status_code == 401: - raise Exception( - "The URL {0} retrieved and {1} error. Please check your credentials, make sure you have permission to perform this action and try again.".format( - response.url, response.status_code)) - elif response.status_code == 403: - raise Exception( - "The URL {0} retrieved and {1} error. Please check your credentials, make sure you have permission to perform this action and try again.".format( - response.url, response.status_code)) - elif response.status_code == 404: - raise Exception( - "The URL {0} retrieved an {1} error. Please check the URL and try again.\nRaw message: {2}".format( - response.url, response.status_code, response.text)) - elif response.status_code == 410: - raise Exception( - "The URL {0} retrieved an {1} error. Please check the URL and try again.\nRaw message: {2}".format( - response.url, response.status_code, response.text)) - elif response.status_code == 422: - raise Exception( - "The URL {0} retrieved an {1} error. Please check the URL and try again.\nRaw message: {2}".format( - response.url, response.status_code, response.text)) - elif response.status_code == 429: - raise Exception( - "The URL {0} retrieved an {1} error. Please check the URL and try again.\nRaw message: {2}".format( - response.url, response.status_code, response.text)) - elif response.status_code == 500: - raise Exception( - "The URL {0} retrieved an {1} error. Please check the URL and try again.\nRaw message: {2}".format( - response.url, response.status_code, response.text)) - elif response.status_code == 501: - raise Exception( - "The URL {0} retrieved an {1} error. Please check the URL and try again.\nRaw message: {2}".format( - response.url, response.status_code, response.text)) - return response.json() - - def get_oauth_uri(self, redirect_uri, state=None): - if redirect_uri is not None: - params = { - 'client_id': self.client_id, - 'redirect_uri': redirect_uri, - # 'scope': ' '.join(scope), - } - if state is not None: - params['state'] = state - url = self.oauth_flow_base_url + self.oauth_end + urlencode(params) - print(url) - return url - else: - raise Exception("The attributes necessary to get the url were not obtained.") + self.access_token = None + self.activities = Activities(self) + self.deals = Deals(self) + self.filters = Filters(self) + self.notes = Notes(self) + self.organizations = Organizations(self) + self.persons = Persons(self) + self.pipelines = Pipelines(self) + self.products = Products(self) + self.recents = Recents(self) + self.users = Users(self) + self.webhooks = Webhooks(self) + + def authorization_url(self, redirect_uri, state=None): + params = { + 'client_id': self.client_id, + 'redirect_uri': redirect_uri, + } + + if state is not None: + params['state'] = state + + return self.OAUTH_BASE_URL + 'authorize?' + urlencode(params) def exchange_code(self, redirect_uri, code): - if redirect_uri is not None and code is not None: - url = self.oauth_flow_base_url + self.token_end - authorization = '{0}:{1}'.format(self.client_id, self.client_secret) - header = {'content-type': 'application/x-www-form-urlencoded', - 'Authorization': 'Basic {0}'.format(b64encode(authorization.encode('UTF-8')).decode('UTF-8'))} - args = {'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri} - response = requests.post(url, headers=header, data=args) - return self.parse_response(response) - else: - raise Exception("The attributes necessary to exchange the code were not obtained.") + data = { + 'grant_type': 'authorization_code', + 'code': code, + 'redirect_uri': redirect_uri + } + return self._post(self.OAUTH_BASE_URL + 'token', data=data, auth=(self.client_id, self.client_secret)) def refresh_token(self, refresh_token): - if refresh_token is not None: - url = self.oauth_flow_base_url + self.token_end - authorization = '{0}:{1}'.format(self.client_id, self.client_secret) - header = {'content-type': 'application/x-www-form-urlencoded', - 'Authorization': 'Basic {0}'.format(b64encode(authorization.encode('UTF-8')).decode('UTF-8'))} - data = { - 'client_id': self.client_id, - 'client_secret': self.client_secret, - 'grant_type': "refresh_token", - 'refresh_token': refresh_token, - } - response = requests.post(url, headers=header, data=data) - return self.parse_response(response) - else: - raise Exception("The attributes necessary to refresh the token were not obtained.") + data = { + 'grant_type': 'refresh_token', + 'refresh_token': refresh_token, + } + return self._post(self.OAUTH_BASE_URL + 'token', data=data, auth=(self.client_id, self.client_secret)) - def set_token(self, token): - """ - Sets the Token for its use in this library. - :param token: - :return: - """ - if token: - self.token = token + def set_access_token(self, access_token): + self.access_token = access_token - def get_recent_changes(self, **kwargs): - """ - This method Returns data about all recent changes occured after given timestamp. in kwarg must to send "since_timestamp" with this format: YYYY-MM-DD HH:MM:SS - :param kwargs: - :return: - """ - if kwargs is not None: - url = "recents" - return self._get(url, **kwargs) + def _get(self, url, **kwargs): + return self._request('get', url, **kwargs) - def get_data(self, endpoint, **kwargs): - if endpoint != "": - return self._get(endpoint, **kwargs) + def _post(self, url, **kwargs): + return self._request('post', url, **kwargs) - def get_specific_data(self, endpoint, data_id, **kwargs): - if endpoint != "": - url = "{0}/{1}".format(endpoint, data_id) - return self._get(url, **kwargs) + def _put(self, url, **kwargs): + return self._request('put', url, **kwargs) - def create_data(self, endpoint, **kwargs): - if endpoint != "" and kwargs is not None: - params = {} - params.update(kwargs) - return self._post(endpoint, json=params) + def _delete(self, url, **kwargs): + return self._request('delete', url, **kwargs) - # Filter section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Filters - def get_filters(self, filter_id=None, **kwargs): - if filter_id is not None: - url = "filters/{0}".format(filter_id) - else: - url = "filters" - return self._get(url, **kwargs) + def _request(self, method, url, headers=None, **kwargs): + _headers = {'Authorization': 'Bearer {}'.format(self.access_token)} + if headers: + _headers.update(headers) + return self._parse(requests.request(method, url, headers=_headers, **kwargs)) - def create_filter(self, **kwargs): - if kwargs is not None: - url = "filters" - params = {} - params.update(kwargs) - return self._post(url, json=params) - - def update_filter(self, filter_id, **kwargs): - if filter_id is not None and kwargs is not None: - url = "filters/{0}".format(filter_id) - params = {} - params.update(kwargs) - return self._put(url, json=params) - - def delete_filter(self, filter_id): - if filter_id is not None: - url = "filters/{0}".format(filter_id) - return self._delete(url) - - # Pipeline section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Pipelines - def get_pipelines(self, pipeline_id=None, **kwargs): - if pipeline_id is not None: - url = "pipelines/{0}".format(pipeline_id) + def _parse(self, response): + status_code = response.status_code + if 'Content-Type' in response.headers and 'application/json' in response.headers['Content-Type']: + r = response.json() else: - url = "pipelines" - return self._get(url, **kwargs) - - def get_pipeline_deals(self, pipeline_id, **kwargs): - if pipeline_id is not None: - url = "pipelines/{0}/deals".format(pipeline_id) - return self._get(url, **kwargs) - - # Deals section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Deals - def get_deals(self, deal_id=None, **kwargs): - if deal_id is not None: - url = "deals/{0}".format(deal_id) - else: - url = "deals" - return self._get(url, **kwargs) - - def create_deal(self, **kwargs): - url = "deals" - if kwargs is not None: - params = {} - params.update(kwargs) - return self._post(url, json=params) - - def update_deal(self, deal_id, **kwargs): - if deal_id is not None and kwargs is not None: - url = "deals/{0}".format(deal_id) - params = {} - params.update(kwargs) - return self._put(url, json=params) - - def delete_deal(self, deal_id): - if deal_id is not None: - url = "deals/{0}".format(deal_id) - return self._delete(url) - - def duplicate_deal(self, deal_id): - if deal_id is not None: - url = "deals/{0}/duplicate".format(deal_id) - return self._post(url) - - def get_deal_details(self, deal_id): - if deal_id is not None: - url = "deals/{0}".format(deal_id) - return self._get(url) - - def get_deals_by_name(self, **kwargs): - if kwargs is not None: - url = "deals/find" - return self._get(url, **kwargs) - - def get_deal_followers(self, deal_id): - if deal_id is not None: - url = "deals/{0}/followers".format(deal_id) - return self._get(url) - - def add_follower_to_deal(self, deal_id, user_id): - if deal_id is not None and user_id is not None: - url = "deals/{0}/followers".format(deal_id) - return self._post(url, json=user_id) - - def delete_follower_to_deal(self, deal_id, follower_id): - if deal_id is not None and follower_id is not None: - url = "deals/{0}/followers/{1}".format(deal_id, follower_id) - return self._delete(url) - - def get_deal_participants(self, deal_id, **kwargs): - if deal_id is not None: - url = "deals/{0}/participants".format(deal_id) - return self._get(url, **kwargs) - - def add_participants_to_deal(self, deal_id, person_id): - if deal_id is not None and person_id is not None: - url = "deals/{0}/participants".format(deal_id) - return self._post(url, json=person_id) - - def delete_participant_to_deal(self, deal_id, participant_id): - if deal_id is not None and participant_id is not None: - url = "deals/{0}/participants/{1}".format(deal_id, participant_id) - return self._delete(url) - - def get_deal_activities(self, deal_id, **kwargs): - if deal_id is not None: - url = "deals/{0}/activities".format(deal_id) - return self._get(url, **kwargs) - - def get_deal_mail_messages(self, deal_id, **kwargs): - if deal_id is not None: - url = "deals/{0}/mailMessages".format(deal_id) - return self._get(url, **kwargs) - - def get_deal_products(self, deal_id, **kwargs): - if deal_id is not None: - url = "deals/{0}/products".format(deal_id) - return self._get(url, **kwargs) - - # Notes section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Notes - def get_notes(self, note_id=None, **kwargs): - if note_id is not None: - url = "notes/{0}".format(note_id) - else: - url = "notes" - return self._get(url, **kwargs) - - def create_note(self, **kwargs): - if kwargs is not None: - url = "notes" - params = {} - params.update(kwargs) - return self._post(url, json=params) - - def update_note(self, note_id, **kwargs): - if note_id is not None and kwargs is not None: - url = "notes/{0}".format(note_id) - params = {} - params.update(kwargs) - return self._put(url, json=params) - - def delete_note(self, note_id): - if note_id is not None: - url = "notes/{0}".format(note_id) - return self._delete(url) - - # Organizations section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Organizations - def get_organizations(self, org_id=None, **kwargs): - if org_id is not None: - url = "organizations/{0}".format(org_id) - else: - url = "organizations" - return self._get(url, **kwargs) - - def create_organization(self, **kwargs): - if kwargs is not None: - url = "organizations" - params = {} - params.update(kwargs) - return self._post(url, json=params) - - def update_organization(self, data_id, **kwargs): - if data_id is not None: - url = "organizations/{0}".format(data_id) - params = {} - params.update(kwargs) - return self._put(url, json=params) - - def delete_organization(self, data_id): - if data_id is not None: - url = "organizations/{0}".format(data_id) - return self._delete(url) - - # Persons section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Persons - def get_persons(self, person_id=None, **kwargs): - if person_id is not None: - url = "persons/{0}".format(person_id) - else: - url = "persons" - return self._get(url, **kwargs) - - def get_persons_by_name(self, params=None): - if params is not None: - url = "persons/find" - return self._get(url, params=params) - - def create_person(self, **kwargs): - if kwargs is not None: - url = "persons" - params = {} - params.update(kwargs) - return self._post(url, json=params) - - def update_person(self, data_id, **kwargs): - if data_id is not None and kwargs is not None: - url = "persons/{0}".format(data_id) - params = {} - params.update(kwargs) - return self._put(url, json=params) - - def delete_person(self, data_id): - if data_id is not None: - url = "persons/{0}".format(data_id) - return self._delete(url) - - def get_person_deals(self, person_id, **kwargs): - if person_id is not None: - url = "persons/{0}/deals".format(person_id) - return self._get(url, **kwargs) - - # Products section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Products - def get_products(self, product_id=None, **kwargs): - if product_id is not None: - url = "products/{0}".format(product_id) - else: - url = "products" - return self._get(url, **kwargs) - - def get_product_by_name(self, params=None): - if params is not None: - url = "products/find" - return self._get(url, params=params) - - def create_product(self, **kwargs): - if kwargs is not None: - url = "products" - params = {} - params.update(kwargs) - return self._post(url, json=params) - - def update_product(self, product_id, **kwargs): - if product_id is not None and kwargs is not None: - url = "products/{0}".format(product_id) - params = {} - params.update(kwargs) - return self._put(url, json=params) - - def delete_product(self, product_id): - if product_id is not None: - url = "products/{0}".format(product_id) - return self._delete(url) - - def get_product_deal(self, product_id, **kwargs): - if product_id is not None: - url = "products/{0}/deals".format(product_id) - return self._get(url, **kwargs) - - # Activities section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Activities - def get_activities(self, activity_id=None, **kwargs): - if activity_id is not None: - url = "activities/{0}".format(activity_id) - else: - url = "activities" - return self._get(url, **kwargs) - - def create_activity(self, **kwargs): - if kwargs is not None: - url = "activities" - params = {} - params.update(kwargs) - return self._post(url, json=params) - - def update_activity(self, activity_id, **kwargs): - if activity_id is not None: - url = "activities/{0}".format(activity_id) - params = {} - params.update(kwargs) - return self._put(url, json=params) - - def delete_activity(self, activity_id): - if activity_id is not None: - url = "activities/{0}".format(activity_id) - return self._delete(url) - - # Webhook section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Webhooks - def get_hooks_subscription(self): - url = "webhooks" - return self._get(url) - - def create_hook_subscription(self, subscription_url, event_action, event_object, **kwargs): - if subscription_url is not None and event_action is not None and event_object is not None: - args = {"subscription_url": subscription_url, "event_action": event_action, "event_object": event_object} - if kwargs is not None: - args.update(kwargs) - return self._post(endpoint='webhooks', json=args) - else: - raise Exception("The attributes necessary to create the webhook were not obtained.") - - def delete_hook_subscription(self, hook_id): - if hook_id is not None: - url = "webhooks/{0}".format(hook_id) - return self._delete(url) - else: - raise Exception("The attributes necessary to delete the webhook were not obtained.") - - # Users section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Users - def get_users(self, user_id=None, **kwargs): - if user_id is not None: - url = "users/{}".format(user_id) - else: - url = "users" - return self._get(url, **kwargs) + return response.text + + if not response.ok: + error = None + if 'error' in r: + error = r['error'] + if status_code == 400: + raise exceptions.BadRequestError(error, response) + elif status_code == 401: + raise exceptions.UnauthorizedError(error, response) + elif status_code == 403: + raise exceptions.ForbiddenError(error, response) + elif status_code == 404: + raise exceptions.NotFoundError(error, response) + elif status_code == 410: + raise exceptions.GoneError(error, response) + elif status_code == 415: + raise exceptions.UnsupportedMediaTypeError(error, response) + elif status_code == 422: + raise exceptions.UnprocessableEntityError(error, response) + elif status_code == 429: + raise exceptions.TooManyRequestsError(error, response) + elif status_code == 500: + raise exceptions.InternalServerError(error, response) + elif status_code == 501: + raise exceptions.NotImplementedError(error, response) + elif status_code == 503: + raise exceptions.ServiceUnavailableError(error, response) + else: + raise exceptions.UnknownError(error, response) - def get_me(self, **kwargs): - url = "users/me" - return self._get(url, **kwargs) + return r diff --git a/pipedrive/deals.py b/pipedrive/deals.py new file mode 100644 index 0000000..cad735a --- /dev/null +++ b/pipedrive/deals.py @@ -0,0 +1,76 @@ +class Deals(object): + def __init__(self, client): + self._client = client + + def get_deals(self, deal_id=None, **kwargs): + if deal_id is not None: + url = 'deals/{}'.format(deal_id) + else: + url = 'deals' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_deal(self, data, **kwargs): + url = 'deals' + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_deal(self, deal_id, data, **kwargs): + url = 'deals/{}'.format(deal_id) + return self._client._put(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_deal(self, deal_id, **kwargs): + url = 'deals/{}'.format(deal_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def duplicate_deal(self, deal_id, **kwargs): + url = 'deals/{}/duplicate'.format(deal_id) + return self._client._post(self._client.BASE_URL + url, **kwargs) + + def get_deal_details(self, deal_id, **kwargs): + url = 'deals/{}'.format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_deals_by_name(self, **kwargs): + url = 'deals/find' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_deal_followers(self, deal_id, **kwargs): + url = 'deals/{}/followers'.format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def add_follower_to_deal(self, deal_id, user_id, **kwargs): + url = 'deals/{}/followers'.format(deal_id) + data = { + 'user_id': user_id + } + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_follower_to_deal(self, deal_id, follower_id, **kwargs): + url = 'deals/{}/followers/{}'.format(deal_id, follower_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def get_deal_participants(self, deal_id, **kwargs): + url = 'deals/{}/participants'.format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def add_participants_to_deal(self, deal_id, person_id, **kwargs): + url = 'deals/{}/participants'.format(deal_id) + data = { + 'person_id': person_id + } + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_participant_to_deal(self, deal_id, participant_id, **kwargs): + url = 'deals/{}/participants/{}'.format(deal_id, participant_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def get_deal_activities(self, deal_id, **kwargs): + url = 'deals/{}/activities'.format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_deal_mail_messages(self, deal_id, **kwargs): + url = 'deals/{}/mailMessages'.format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_deal_products(self, deal_id, **kwargs): + url = 'deals/{}/products'.format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/exceptions.py b/pipedrive/exceptions.py new file mode 100644 index 0000000..61ae5bf --- /dev/null +++ b/pipedrive/exceptions.py @@ -0,0 +1,52 @@ +class BaseError(Exception): + def __init__(self, message, response, *args, **kwargs): + super().__init__(message, *args, **kwargs) + self.response = response + + +class BadRequestError(BaseError): + pass + + +class UnauthorizedError(BaseError): + pass + + +class ForbiddenError(BaseError): + pass + + +class NotFoundError(BaseError): + pass + + +class GoneError(BaseError): + pass + + +class UnsupportedMediaTypeError(BaseError): + pass + + +class UnprocessableEntityError(BaseError): + pass + + +class TooManyRequestsError(BaseError): + pass + + +class InternalServerError(BaseError): + pass + + +class NotImplementedError(BaseError): + pass + + +class ServiceUnavailableError(BaseError): + pass + + +class UnknownError(BaseError): + pass diff --git a/pipedrive/filters.py b/pipedrive/filters.py new file mode 100644 index 0000000..62fd150 --- /dev/null +++ b/pipedrive/filters.py @@ -0,0 +1,22 @@ +class Filters(object): + def __init__(self, client): + self._client = client + + def get_filters(self, filter_id=None, **kwargs): + if filter_id is not None: + url = 'filters/{}'.format(filter_id) + else: + url = 'filters' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_filter(self, data, **kwargs): + url = 'filters' + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_filter(self, filter_id, data, **kwargs): + url = 'filters/{}'.format(filter_id) + return self._client._put(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_filter(self, filter_id, **kwargs): + url = 'filters/{}'.format(filter_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/notes.py b/pipedrive/notes.py new file mode 100644 index 0000000..448563f --- /dev/null +++ b/pipedrive/notes.py @@ -0,0 +1,22 @@ +class Notes(object): + def __init__(self, client): + self._client = client + + def get_notes(self, note_id=None, **kwargs): + if note_id is not None: + url = 'notes/{}'.format(note_id) + else: + url = 'notes' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_note(self, data, **kwargs): + url = 'notes' + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_note(self, note_id, data, **kwargs): + url = 'notes/{}'.format(note_id) + return self._client._put(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_note(self, note_id, **kwargs): + url = 'notes/{}'.format(note_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/organizations.py b/pipedrive/organizations.py new file mode 100644 index 0000000..ddbf1fe --- /dev/null +++ b/pipedrive/organizations.py @@ -0,0 +1,22 @@ +class Organizations(object): + def __init__(self, client): + self._client = client + + def get_organizations(self, org_id=None, **kwargs): + if org_id is not None: + url = 'organizations/{}'.format(org_id) + else: + url = 'organizations' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_organization(self, data, **kwargs): + url = 'organizations' + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_organization(self, organization_id, data, **kwargs): + url = 'organizations/{}'.format(organization_id) + return self._client._put(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_organization(self, organization_id, **kwargs): + url = 'organizations/{}'.format(organization_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/persons.py b/pipedrive/persons.py new file mode 100644 index 0000000..7e68716 --- /dev/null +++ b/pipedrive/persons.py @@ -0,0 +1,30 @@ +class Persons(object): + def __init__(self, client): + self._client = client + + def get_persons(self, person_id=None, **kwargs): + if person_id is not None: + url = 'persons/{}'.format(person_id) + else: + url = 'persons' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_persons_by_name(self, **kwargs): + url = 'persons/find' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_person(self, data, **kwargs): + url = 'persons' + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_person(self, person_id, data, **kwargs): + url = 'persons/{}'.format(person_id) + return self._client._put(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_person(self, person_id, **kwargs): + url = 'persons/{}'.format(person_id) + return self._client._delete(url, **kwargs) + + def get_person_deals(self, person_id, **kwargs): + url = 'persons/{}/deals'.format(person_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/pipelines.py b/pipedrive/pipelines.py new file mode 100644 index 0000000..0969648 --- /dev/null +++ b/pipedrive/pipelines.py @@ -0,0 +1,14 @@ +class Pipelines(object): + def __init__(self, client): + self._client = client + + def get_pipelines(self, pipeline_id=None, **kwargs): + if pipeline_id is not None: + url = 'pipelines/{}'.format(pipeline_id) + else: + url = 'pipelines' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_pipeline_deals(self, pipeline_id, **kwargs): + url = 'pipelines/{}/deals'.format(pipeline_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/products.py b/pipedrive/products.py new file mode 100644 index 0000000..3631237 --- /dev/null +++ b/pipedrive/products.py @@ -0,0 +1,30 @@ +class Products(object): + def __init__(self, client): + self._client = client + + def get_products(self, product_id=None, **kwargs): + if product_id is not None: + url = 'products/{}'.format(product_id) + else: + url = 'products' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_product_by_name(self, **kwargs): + url = 'products/find' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_product(self, data, **kwargs): + url = 'products' + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_product(self, product_id, data, **kwargs): + url = 'products/{}'.format(product_id) + return self._client._put(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_product(self, product_id, **kwargs): + url = 'products/{}'.format(product_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def get_product_deal(self, product_id, **kwargs): + url = 'products/{}/deals'.format(product_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/recents.py b/pipedrive/recents.py new file mode 100644 index 0000000..5135e80 --- /dev/null +++ b/pipedrive/recents.py @@ -0,0 +1,7 @@ +class Recents(object): + def __init__(self, client): + self._client = client + + def get_recent_changes(self, **kwargs): + url = 'recents' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/test.py b/pipedrive/test.py deleted file mode 100644 index e18d17f..0000000 --- a/pipedrive/test.py +++ /dev/null @@ -1,3 +0,0 @@ -from pipedrive.client import Client - -client = Client(api_base_url="https://companydomain.pipedrive.com/") diff --git a/pipedrive/users.py b/pipedrive/users.py new file mode 100644 index 0000000..3b0b6da --- /dev/null +++ b/pipedrive/users.py @@ -0,0 +1,14 @@ +class Users(object): + def __init__(self, client): + self._client = client + + def get_users(self, user_id=None, **kwargs): + if user_id is not None: + url = 'users/{}'.format(user_id) + else: + url = 'users' + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_me(self, **kwargs): + url = 'users/me' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/webhooks.py b/pipedrive/webhooks.py new file mode 100644 index 0000000..47f0264 --- /dev/null +++ b/pipedrive/webhooks.py @@ -0,0 +1,21 @@ +class Webhooks(object): + def __init__(self, client): + self._client = client + + def get_hooks_subscription(self, **kwargs): + url = 'webhooks' + return self._client._get(url, **kwargs) + + def create_hook_subscription(self, subscription_url, event_action, event_object, **kwargs): + url = 'webhooks' + data = { + 'subscription_url': + subscription_url, + 'event_action': event_action, + 'event_object': event_object + } + return self._client._post(url, json=data, **kwargs) + + def delete_hook_subscription(self, hook_id, **kwargs): + url = 'webhooks/{}'.format(hook_id) + return self._client._delete(url, **kwargs) diff --git a/setup.py b/setup.py index 9ad9fee..174e5e5 100644 --- a/setup.py +++ b/setup.py @@ -7,13 +7,14 @@ def read(fname): setup(name='pipedrive-python-lib', - version='0.1.3', + version='1.0.0', description='API wrapper for Pipedrive written in Python', long_description=read('README.md'), + long_description_content_type="text/markdown", url='https://github.com/GearPlug/pipedrive-python', - author='Yordy Gelvez', - author_email='yordy.gelvez@gmail.com', - license='GPL', + author='Miguel Ferrer', + author_email='ingferrermiguel@gmail.com', + license='MIT', packages=['pipedrive'], install_requires=[ 'requests', From 7812ece6fbcdd9a010728ac5c88a45b838c2f15d Mon Sep 17 00:00:00 2001 From: Miguel Ferrer Date: Fri, 6 Sep 2019 11:24:35 -0500 Subject: [PATCH 2/3] Add field endpoints Add improvements --- pipedrive/activities.py | 15 ++++++++++----- pipedrive/client.py | 2 +- pipedrive/deals.py | 15 ++++++++++----- pipedrive/filters.py | 11 ++++++----- pipedrive/notes.py | 15 ++++++++++----- pipedrive/organizations.py | 15 ++++++++++----- pipedrive/persons.py | 15 ++++++++++----- pipedrive/pipelines.py | 11 ++++++----- pipedrive/products.py | 15 ++++++++++----- pipedrive/users.py | 11 ++++++----- 10 files changed, 79 insertions(+), 46 deletions(-) diff --git a/pipedrive/activities.py b/pipedrive/activities.py index c7208a1..c09c832 100644 --- a/pipedrive/activities.py +++ b/pipedrive/activities.py @@ -2,11 +2,12 @@ class Activities(object): def __init__(self, client): self._client = client - def get_activities(self, activity_id=None, **kwargs): - if activity_id is not None: - url = 'activities/{}'.format(activity_id) - else: - url = 'activities' + def get_activity(self, activity_id, **kwargs): + url = 'activities/{}'.format(activity_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_activities(self, **kwargs): + url = 'activities' return self._client._get(self._client.BASE_URL + url, **kwargs) def create_activity(self, data, **kwargs): @@ -20,3 +21,7 @@ def update_activity(self, activity_id, data, **kwargs): def delete_activity(self, activity_id, **kwargs): url = 'activities/{}'.format(activity_id) return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def get_activity_fields(self, **kwargs): + url = 'activityFields' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/client.py b/pipedrive/client.py index 8c32dd8..a93d979 100644 --- a/pipedrive/client.py +++ b/pipedrive/client.py @@ -20,7 +20,7 @@ class Client: BASE_URL = 'https://api-proxy.pipedrive.com/' OAUTH_BASE_URL = 'https://oauth.pipedrive.com/oauth/' - def __init__(self, client_id=None, client_secret=None): + def __init__(self, client_id, client_secret): self.client_id = client_id self.client_secret = client_secret self.access_token = None diff --git a/pipedrive/deals.py b/pipedrive/deals.py index cad735a..2d5964a 100644 --- a/pipedrive/deals.py +++ b/pipedrive/deals.py @@ -2,11 +2,12 @@ class Deals(object): def __init__(self, client): self._client = client - def get_deals(self, deal_id=None, **kwargs): - if deal_id is not None: - url = 'deals/{}'.format(deal_id) - else: - url = 'deals' + def get_deal(self, deal_id, **kwargs): + url = 'deals/{}'.format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_deals(self, **kwargs): + url = 'deals' return self._client._get(self._client.BASE_URL + url, **kwargs) def create_deal(self, data, **kwargs): @@ -74,3 +75,7 @@ def get_deal_mail_messages(self, deal_id, **kwargs): def get_deal_products(self, deal_id, **kwargs): url = 'deals/{}/products'.format(deal_id) return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_deal_fields(self, **kwargs): + url = 'dealFields' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/filters.py b/pipedrive/filters.py index 62fd150..d7dcb11 100644 --- a/pipedrive/filters.py +++ b/pipedrive/filters.py @@ -2,11 +2,12 @@ class Filters(object): def __init__(self, client): self._client = client - def get_filters(self, filter_id=None, **kwargs): - if filter_id is not None: - url = 'filters/{}'.format(filter_id) - else: - url = 'filters' + def get_filter(self, filter_id, **kwargs): + url = 'filters/{}'.format(filter_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_filters(self, **kwargs): + url = 'filters' return self._client._get(self._client.BASE_URL + url, **kwargs) def create_filter(self, data, **kwargs): diff --git a/pipedrive/notes.py b/pipedrive/notes.py index 448563f..159ac98 100644 --- a/pipedrive/notes.py +++ b/pipedrive/notes.py @@ -2,11 +2,12 @@ class Notes(object): def __init__(self, client): self._client = client - def get_notes(self, note_id=None, **kwargs): - if note_id is not None: - url = 'notes/{}'.format(note_id) - else: - url = 'notes' + def get_note(self, note_id, **kwargs): + url = 'notes/{}'.format(note_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_notes(self, **kwargs): + url = 'notes' return self._client._get(self._client.BASE_URL + url, **kwargs) def create_note(self, data, **kwargs): @@ -20,3 +21,7 @@ def update_note(self, note_id, data, **kwargs): def delete_note(self, note_id, **kwargs): url = 'notes/{}'.format(note_id) return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def get_note_fields(self, **kwargs): + url = 'noteFields' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/organizations.py b/pipedrive/organizations.py index ddbf1fe..35970d6 100644 --- a/pipedrive/organizations.py +++ b/pipedrive/organizations.py @@ -2,11 +2,12 @@ class Organizations(object): def __init__(self, client): self._client = client - def get_organizations(self, org_id=None, **kwargs): - if org_id is not None: - url = 'organizations/{}'.format(org_id) - else: - url = 'organizations' + def get_organization(self, organization_id, **kwargs): + url = 'organizations/{}'.format(organization_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_organizations(self, **kwargs): + url = 'organizations' return self._client._get(self._client.BASE_URL + url, **kwargs) def create_organization(self, data, **kwargs): @@ -20,3 +21,7 @@ def update_organization(self, organization_id, data, **kwargs): def delete_organization(self, organization_id, **kwargs): url = 'organizations/{}'.format(organization_id) return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def get_organization_fields(self, **kwargs): + url = 'organizationFields' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/persons.py b/pipedrive/persons.py index 7e68716..b803f32 100644 --- a/pipedrive/persons.py +++ b/pipedrive/persons.py @@ -2,11 +2,12 @@ class Persons(object): def __init__(self, client): self._client = client - def get_persons(self, person_id=None, **kwargs): - if person_id is not None: - url = 'persons/{}'.format(person_id) - else: - url = 'persons' + def get_person(self, person_id, **kwargs): + url = 'persons/{}'.format(person_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_persons(self, **kwargs): + url = 'persons' return self._client._get(self._client.BASE_URL + url, **kwargs) def get_persons_by_name(self, **kwargs): @@ -28,3 +29,7 @@ def delete_person(self, person_id, **kwargs): def get_person_deals(self, person_id, **kwargs): url = 'persons/{}/deals'.format(person_id) return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_person_fields(self, **kwargs): + url = 'personFields' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/pipelines.py b/pipedrive/pipelines.py index 0969648..46c44f9 100644 --- a/pipedrive/pipelines.py +++ b/pipedrive/pipelines.py @@ -2,11 +2,12 @@ class Pipelines(object): def __init__(self, client): self._client = client - def get_pipelines(self, pipeline_id=None, **kwargs): - if pipeline_id is not None: - url = 'pipelines/{}'.format(pipeline_id) - else: - url = 'pipelines' + def get_pipeline(self, pipeline_id, **kwargs): + url = 'pipelines/{}'.format(pipeline_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_pipelines(self, **kwargs): + url = 'pipelines' return self._client._get(self._client.BASE_URL + url, **kwargs) def get_pipeline_deals(self, pipeline_id, **kwargs): diff --git a/pipedrive/products.py b/pipedrive/products.py index 3631237..49870c5 100644 --- a/pipedrive/products.py +++ b/pipedrive/products.py @@ -2,11 +2,12 @@ class Products(object): def __init__(self, client): self._client = client - def get_products(self, product_id=None, **kwargs): - if product_id is not None: - url = 'products/{}'.format(product_id) - else: - url = 'products' + def get_product(self, product_id, **kwargs): + url = 'products/{}'.format(product_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_products(self, **kwargs): + url = 'products' return self._client._get(self._client.BASE_URL + url, **kwargs) def get_product_by_name(self, **kwargs): @@ -28,3 +29,7 @@ def delete_product(self, product_id, **kwargs): def get_product_deal(self, product_id, **kwargs): url = 'products/{}/deals'.format(product_id) return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_product_fields(self, **kwargs): + url = 'productFields' + return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/users.py b/pipedrive/users.py index 3b0b6da..a7d52bf 100644 --- a/pipedrive/users.py +++ b/pipedrive/users.py @@ -2,11 +2,12 @@ class Users(object): def __init__(self, client): self._client = client - def get_users(self, user_id=None, **kwargs): - if user_id is not None: - url = 'users/{}'.format(user_id) - else: - url = 'users' + def get_user(self, user_id, **kwargs): + url = 'users/{}'.format(user_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_users(self, **kwargs): + url = 'users' return self._client._get(self._client.BASE_URL + url, **kwargs) def get_me(self, **kwargs): From c11d7a5df9b0979144a9a69ae4726217557869e9 Mon Sep 17 00:00:00 2001 From: Miguel Ferrer Date: Fri, 6 Sep 2019 14:48:35 -0500 Subject: [PATCH 3/3] Updates README --- README.md | 370 ++++++++++++++++++++++++++++++++------------- pipedrive/users.py | 2 +- 2 files changed, 264 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index e033558..4dc1887 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # pipedrive-python -Pipedrive API wrapper for Pypedrive written in Python. + +pipedrive-python is an API wrapper for Pipedrive written in Python. ## Installing ``` @@ -7,27 +8,19 @@ pip install pipedrive-python-lib ``` ## Usage -- If you are not going to use the authentication flow, just send the "pipedrive company domain" and instance the library like this: -``` -from pipedrive.client import Client -client = Client(api_base_url='https://companydomain.pipedrive.com/') -``` -- If on the contrary you will use it, send the "pipedrive company domain", the "client_id", the "client secret" and the parameter "oauth=True" in the main instance like this: +#### Client instantiation ``` from pipedrive.client import Client -client = Client(api_base_url='https://companydomain.pipedrive.com/', 'CLIENT_ID', 'CLIENT_SECRET', oauth=True) -``` -#### Set token -And to make requests send the access token -``` -client.set_token(access_token) +client = Client('CLIENT_ID', 'CLIENT_SECRET') ``` +### OAuth 2.0 + #### Get authorization url ``` -url = client.get_oauth_uri("REDIRECT_URL", "OPTIONAL - state") +url = client.authorization_url('REDIRECT_URL') ``` #### Exchange the code for an access token @@ -35,293 +28,456 @@ url = client.get_oauth_uri("REDIRECT_URL", "OPTIONAL - state") token = client.exchange_code('REDIRECT_URL', 'CODE') ``` +#### Set access token in the library +``` +client.set_access_token('ACCESS_TOKEN') +``` + #### Refresh token ``` -token = client.refresh_token('REFRESH TOKEN') +token = client.refresh_token('REFRESH_TOKEN') ``` -#### Get recent changes +### Activities + +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Activities + +#### Get an activity ``` -token = client.get_recent_changes(since_timestamp="YYYY-MM-DD HH:MM:SS") +response = client.activities.get_activity('ACTIVITY_ID') ``` -### Filters section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Filters -#### Get deals -If you need a specific filter send the filter id, if you don't just call the method +#### Get all activities +``` +response = client.activities.get_all_activities() ``` -get_specific_filter = client.get_filters(filter_id="") -get_filters = client.get_filters() +#### Create an activity +``` +data = { + 'subject': '', + 'type': '' +} +response = client.activities.create_activity(data) ``` -#### Create filter +#### Update an activity ``` -create_filter = client.create_filter(name="", conditions={}, type="") +data = { + 'subject': '', + 'type': '' +} +response = client.activities.update_activity('ACTIVITY_ID', data) ``` -#### Update filter +#### Delete an activity ``` -update_filter = client.update_filter(filter_id="", name="", conditions={}, type="") +response = client.activities.delete_activity('ACTIVITY_ID') ``` -#### Delete filter +#### Get activity fields ``` -delete_filter = client.delete_filter(filter_id="") +response = client.activities.get_activity_fields() ``` -### Deals section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Deals +### Deals -#### Get deals -If you need a specific deal send the deal id, if you don't just call the method +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Deals + +#### Get a deal +``` +response = client.deals.get_deal('DEAL_ID') ``` -get_specific_deal = client.get_deals(deal_id="") -get_deals = client.get_deals() +#### Get all deals +``` +response = client.deals.get_all_deals() ``` #### Create deal ``` -create_deal = client.create_deal(title="") +data = { + 'title': '' +} +response = client.deals.create_deal(data) ``` #### Update deal ``` -update_deal = client.update_deal(deal_id="") +data = { + 'title': '' +} +response = client.deals.update_deal('DEAL_ID', data) ``` #### Delete deal ``` -delete_deal = client.delete_deal(deal_id="") +response = client.deals.delete_deal('DEAL_ID') ``` #### Duplicate deal ``` -duplicate_deal = client.duplicate_deal(deal_id="") +response = client.deals.duplicate_deal('DEAL_ID') ``` #### Get details of a deal ``` -details_deal = client.get_deal_details(deal_id="") +response = client.deals.get_deal_details('DEAL_ID') ``` #### Find deals by name ``` -find_deal = client.get_deals_by_name(term="") +params = { + 'term': '' +} +response = client.deals.get_deals_by_name(params=params) ``` #### Get followers of a deal ``` -followers_deal = client.get_deal_followers(deal_id="") +response = client.deals.get_deal_followers('DEAL_ID') ``` #### Add a follower to a deal ``` -add_follower_deal = client.add_follower_to_deal(deal_id="", user_id="") +response = client.deals.add_follower_to_deal('DEAL_ID', 'USER_ID') ``` #### Delete a follower from a deal ``` -delete_followers_deal = client.delete_follower_to_deal(deal_id="", follower_id="") +response = client.deals.delete_follower_to_deal('DEAL_ID', 'FOLLOWER_ID') ``` #### Get participants of a deal ``` -get_participants_deal = client.get_deal_participants(deal_id="") +response = client.deals.get_deal_participants('DEAL_ID') ``` #### Add a participant to a deal ``` -add_participants_deal = client.add_participants_to_deal(deal_id="", person_id="") +response = client.deals.add_participants_to_deal('DEAL_ID', 'PERSON_ID') ``` #### Delete a participant from a deal ``` -delete_participants_deal = client.delete_participant_to_deal(deal_id="", participant_id="") +response = client.deals.delete_participant_to_deal('DEAL_ID', 'PARTICIPANT_ID') ``` #### Get activities associated with a deal ``` -get_activities_deal = client.get_deal_activities(deal_id="") +response = client.deals.get_deal_activities('DEAL_ID') ``` #### Get mail messages associated with a deal ``` -get_messages_deal = client.get_deal_mail_messages(deal_id="") +response = client.deals.get_deal_mail_messages('DEAL_ID') ``` #### Get products attached to a deal ``` -get_products_deal = client.get_deal_products(deal_id="") +response = client.deals.get_deal_products('DEAL_ID') ``` -### Notes section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Notes +#### Get deal fields +``` +response = client.deals.get_deal_fields() +``` + +### Filters + +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Filters + +#### Get a filter +``` +response = client.filters.get_filter('FILTER_ID') +``` + +#### Get all filters +``` +response = client.filters.get_all_filters() +``` -#### Get notes -If you need a specific note send the note id, if you don't just call the method +#### Create filter +``` +data = { + 'name': '', + 'conditions': {}, + 'type': '' +} +response = client.filters.create_filter(data) ``` -get_specific_note = client.get_notes(note_id="") -get_notes = client.get_notes() +#### Update filter +``` +data = { + 'name': '', + 'conditions': {}, + 'type': '' +} +response = client.filters.update_filter('FILTER_ID', data) +``` + +#### Delete filter +``` +response = client.filters.delete_filter('FILTER_ID') +``` + +### Notes + +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Notes + +#### Get a note +``` +response = client.notes.get_note('NOTE_ID') +``` + +#### Get all notes +``` +response = client.notes.get_all_notes() ``` #### Add a note ``` -add_note = client.create_note(content="", org_id="") +data = { + 'content': '' +} +response = client.notes.create_note(data) ``` #### Update a note ``` -update_note = client.update_note(note_id="", content="") +data = { + 'content': '' +} +response = client.notes.update_note('NOTE_ID', data) ``` #### Delete a note ``` -delete_note = client.delete_note(note_id="") +response = client.notes.delete_note('NOTE_ID') +``` + +#### Get note fields +``` +response = client.notes.get_note_fields() ``` -### Organizations section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Organizations +### Organizations -#### Get organizations -If you need a specific organization send the organization id, if you don't just call the method +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Organizations + +#### Get an organization +``` +response = client.organizations.get_organization('ORGANIZATION_ID') ``` -get_specific_organization = client.get_organizations(org_id="") -get_organizations = client.get_organizations() +#### Get all organizations +``` +response = client.organizations.get_all_organizations() ``` #### Add organization ``` -add_organization = client.create_organization(name="") +data = { + 'name': '' +} +response = client.organizations.create_organization(data) ``` #### Update organization ``` -update_organization = client.update_organization(data_id="", name="") +data = { + 'name': '' +} +response = client.organizations.update_organization('ORGANIZATION_ID', data) ``` #### Delete an organization ``` -delete_organization = client.delete_organization(data_id="") +response = client.organizations.delete_organization('ORGANIZATION_ID') +``` + +#### Get organization fields +``` +response = client.organizations.get_organization_fields() ``` -### Persons section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Persons +### Persons -#### Get persons -If you need the details of a person send the person id, if you don't just call the method +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Persons + +#### Get a person +``` +response = client.persons.get_person('PERSON_ID') ``` -get_details_person = client.get_persons(person_id="") -get_persons = client.get_persons() +#### Get all persons +``` +response = client.persons.get_all_persons() ``` #### Get persons by name ``` -find_persons = client.get_persons_by_name(term="") +params = { + 'term': '' +} +response = client.persons.get_persons_by_name(params=params) ``` #### Create person ``` -add_persons = client.create_person(name="") +data = { + 'name': '' +} +response = client.persons.create_person(data) ``` #### Update person ``` -update_persons = client.update_person(data_id="", name="") +data = { + 'name': '' +} +response = client.persons.update_person('PERSON_ID', data) ``` #### Delete person ``` -delete_persons = client.delete_person(data_id="") +response = client.persons.delete_person('PERSON_ID') ``` #### Get deals associated with a person ``` -get_persons_deals = client.get_person_deals(person_id="") +response = client.persons.get_person_deals('PERSON_ID') +``` + +#### Get person fields +``` +response = client.persons.get_person_fields() +``` + +### Pipelines + +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Pipelines + +#### Get a pipeline +``` +response = client.pipelines.get_pipeline('PIPELINE_ID') ``` +#### Get all pipelines +``` +response = client.pipelines.get_all_pipelines() +``` + +#### Get deals attached to a pipeline +``` +response = client.pipelines.get_pipeline_deals() +``` + +### Products -### Products section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Products +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Products -#### Get products -If you need a specific product send the product id, if you don't just call the method +#### Get a product +``` +response = client.products.get_product('PRODUCT_ID') ``` -get_specific_product = client.get_products(product_id="") -get_products = client.get_products() +#### Get all products +``` +response = client.products.get_all_products() ``` #### Get products by name ``` -find_product = client.get_product_by_name(term="") +params = { + 'term': '' +} +response = client.products.get_product_by_name(params=params) ``` #### Create a product ``` -add_product = client.create_product(name="") +data = { + 'name': '' +} +response = client.products.create_product(data) ``` #### Update a product ``` -update_product = client.update_product(product_id="", name="") +data = { + 'name': '' +} +response = client.products.update_product('PRODUCT_ID', data) ``` #### Delete a product ``` -delete_product = client.delete_product(product_id="") +response = client.products.delete_product('PRODUCT_ID') ``` #### Get deals where a product is attached to ``` -get_product_deal = client.get_product_deal(product_id="") +response = client.products.get_product_deal('PRODUCT_ID') ``` -### Activities section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Activities - -#### Get activities -If you need the activity details send the activity id, if you don't just call the method +#### Get product fields ``` -get_details_activity = client.get_activities(activity_id="") +response = client.products.get_product_fields() +``` + +### Recents -get_activities = client.get_activities() +#### Get recent changes +``` +params = { + 'since_timestamp': 'YYYY-MM-DD HH:MM:SS' +} +response = client.recents.get_recent_changes(params=params) ``` -#### Create an activity +### Users + +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users + +#### Get an user ``` -add_activity = client.create_activity(subject="", type="") +response = client.users.get_users('USER_ID') ``` -#### Update an activity +#### Get all users ``` -edit_activity = client.update_activity(activity_id="") +response = client.users.get_all_users() ``` -#### Delete an activity +#### Get me ``` -delete_activity = client.delete_activity(activity_id="") +response = client.users.get_me() ``` -### Webhook section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Webhooks +### Webhook + +API docs: https://developers.pipedrive.com/docs/api/v1/#!/Webhooks #### Get webhooks ``` -get_hooks = client.get_hooks_subscription() +response = client.webhooks.get_hooks_subscription() ``` #### Add webhook ``` -add_hook = client.create_hook_subscription(subscription_url="", event_action="", event_object="") +data = { + 'subscription_url': '', + 'event_action': '', + 'event_object': '' +} +response = client.webhooks.create_hook_subscription(data) ``` #### Delete webhook ``` -delete_hooks = client.delete_hook_subscription(hook_id="") -``` - -### Users section, see the api documentation: https://developers.pipedrive.com/docs/api/v1/#!/Users - -#### Get users -``` -users = client.get_users(user_id="") +response = client.webhooks.delete_hook_subscription('HOOK_ID') ``` ## Requirements diff --git a/pipedrive/users.py b/pipedrive/users.py index a7d52bf..3eb7ee4 100644 --- a/pipedrive/users.py +++ b/pipedrive/users.py @@ -6,7 +6,7 @@ def get_user(self, user_id, **kwargs): url = 'users/{}'.format(user_id) return self._client._get(self._client.BASE_URL + url, **kwargs) - def get_users(self, **kwargs): + def get_all_users(self, **kwargs): url = 'users' return self._client._get(self._client.BASE_URL + url, **kwargs)