diff --git a/README.md b/README.md index d597ded..f6b5ebe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pipedrive-python - -pipedrive-python is an API wrapper for Pipedrive written in Python. +![](https://img.shields.io/badge/version-1.2.3-success) ![](https://img.shields.io/badge/Python-3.8%20|%203.9%20|%203.10%20|%203.11-4B8BBE?logo=python&logoColor=white) +*pipedrive-python* is an API wrapper for [Pipedrive](https://www.pipedrive.com/) written in Python. ## Installing ``` @@ -12,62 +12,62 @@ pip install pipedrive-python-lib ### Using this library with OAuth 2.0 #### Client instantiation -``` +```python from pipedrive.client import Client client = Client('CLIENT_ID', 'CLIENT_SECRET') ``` #### Get authorization url -``` +```python url = client.authorization_url('REDIRECT_URL') ``` #### Exchange the code for an access token -``` +```python token = client.exchange_code('REDIRECT_URL', 'CODE') ``` #### Set access token in the library -``` +```python client.set_access_token('ACCESS_TOKEN') ``` #### Refresh token -``` +```python token = client.refresh_token('REFRESH_TOKEN') ``` ### Using this library with API Token #### Client instantiation -``` +```python from pipedrive.client import Client client = Client(domain='https://companydomain.pipedrive.com/') ``` #### Set API token in the library -``` +```python client.set_api_token('API_TOKEN') ``` ### Activities -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Activities +API docs: https://developers.pipedrive.com/docs/api/v1/Activities #### Get an activity -``` +```python response = client.activities.get_activity('ACTIVITY_ID') ``` #### Get all activities -``` +```python response = client.activities.get_all_activities() ``` #### Create an activity -``` +```python data = { 'subject': '', 'type': '' @@ -76,7 +76,7 @@ response = client.activities.create_activity(data) ``` #### Update an activity -``` +```python data = { 'subject': '', 'type': '' @@ -85,36 +85,36 @@ response = client.activities.update_activity('ACTIVITY_ID', data) ``` #### Delete an activity -``` +```python response = client.activities.delete_activity('ACTIVITY_ID') ``` #### Get activity fields -``` +```python response = client.activities.get_activity_fields() ``` ### Deals -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Deals +API docs: https://developers.pipedrive.com/docs/api/v1/Deals #### Get a deal -``` +```python response = client.deals.get_deal('DEAL_ID') ``` #### Get all deals -``` +```python response = client.deals.get_all_deals() ``` #### Get all deals based on filter -``` +```python response = client.deals.get_all_deals_with_filter('FILTER_ID') ``` #### Create deal -``` +```python data = { 'title': '' } @@ -122,7 +122,7 @@ response = client.deals.create_deal(data) ``` #### Update deal -``` +```python data = { 'title': '' } @@ -130,94 +130,99 @@ response = client.deals.update_deal('DEAL_ID', data) ``` #### Delete deal -``` +```python response = client.deals.delete_deal('DEAL_ID') ``` #### Duplicate deal -``` +```python response = client.deals.duplicate_deal('DEAL_ID') ``` #### Get details of a deal -``` +```python response = client.deals.get_deal_details('DEAL_ID') ``` -#### Find deals by name -``` +#### Search deals +```python params = { 'term': '' } -response = client.deals.get_deals_by_name(params=params) +response = client.deals.search_deals(params=params) ``` #### Get followers of a deal -``` +```python response = client.deals.get_deal_followers('DEAL_ID') ``` #### Add a follower to a deal -``` +```python response = client.deals.add_follower_to_deal('DEAL_ID', 'USER_ID') ``` #### Delete a follower from a deal -``` +```python response = client.deals.delete_follower_to_deal('DEAL_ID', 'FOLLOWER_ID') ``` #### Get participants of a deal -``` +```python response = client.deals.get_deal_participants('DEAL_ID') ``` #### Add a participant to a deal -``` +```python response = client.deals.add_participants_to_deal('DEAL_ID', 'PERSON_ID') ``` #### Delete a participant from a deal -``` +```python response = client.deals.delete_participant_to_deal('DEAL_ID', 'PARTICIPANT_ID') ``` #### Get activities associated with a deal -``` +```python response = client.deals.get_deal_activities('DEAL_ID') ``` #### Get mail messages associated with a deal -``` +```python response = client.deals.get_deal_mail_messages('DEAL_ID') ``` #### Get products attached to a deal -``` +```python response = client.deals.get_deal_products('DEAL_ID') ``` #### Get deal fields -``` +```python response = client.deals.get_deal_fields() ``` +#### Get updates of a deal +```python +response = client.deals.get_deal_updates('DEAL_ID') +``` + ### Filters -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Filters +API docs: https://developers.pipedrive.com/docs/api/v1/Filters #### Get a filter -``` +```python response = client.filters.get_filter('FILTER_ID') ``` #### Get all filters -``` +```python response = client.filters.get_all_filters() ``` #### Create filter -``` +```python data = { 'name': '', 'conditions': {}, @@ -227,7 +232,7 @@ response = client.filters.create_filter(data) ``` #### Update filter -``` +```python data = { 'name': '', 'conditions': {}, @@ -237,26 +242,26 @@ response = client.filters.update_filter('FILTER_ID', data) ``` #### Delete filter -``` +```python response = client.filters.delete_filter('FILTER_ID') ``` ### Notes -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Notes +API docs: https://developers.pipedrive.com/docs/api/v1/Notes #### Get a note -``` +```python response = client.notes.get_note('NOTE_ID') ``` #### Get all notes -``` +```python response = client.notes.get_all_notes() ``` #### Add a note -``` +```python data = { 'content': '' } @@ -264,7 +269,7 @@ response = client.notes.create_note(data) ``` #### Update a note -``` +```python data = { 'content': '' } @@ -272,31 +277,39 @@ response = client.notes.update_note('NOTE_ID', data) ``` #### Delete a note -``` +```python response = client.notes.delete_note('NOTE_ID') ``` #### Get note fields -``` +```python response = client.notes.get_note_fields() ``` ### Organizations -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Organizations +API docs: https://developers.pipedrive.com/docs/api/v1/Organizations #### Get an organization -``` +```python response = client.organizations.get_organization('ORGANIZATION_ID') ``` #### Get all organizations -``` +```python response = client.organizations.get_all_organizations() ``` -#### Add organization +#### Search organizations +```python +params = { + 'term': '' +} +response = client.products.search_organizations(params=params) ``` + +#### Add organization +```python data = { 'name': '' } @@ -304,7 +317,7 @@ response = client.organizations.create_organization(data) ``` #### Update organization -``` +```python data = { 'name': '' } @@ -312,39 +325,39 @@ response = client.organizations.update_organization('ORGANIZATION_ID', data) ``` #### Delete an organization -``` +```python response = client.organizations.delete_organization('ORGANIZATION_ID') ``` #### Get organization fields -``` +```python response = client.organizations.get_organization_fields() ``` ### Persons -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Persons +API docs: https://developers.pipedrive.com/docs/api/v1/Persons #### Get a person -``` +```python response = client.persons.get_person('PERSON_ID') ``` #### Get all persons -``` +```python response = client.persons.get_all_persons() ``` -#### Get persons by name -``` +#### Search persons +```python params = { 'term': '' } -response = client.persons.get_persons_by_name(params=params) +response = client.persons.search_persons(params=params) ``` #### Create person -``` +```python data = { 'name': '' } @@ -352,7 +365,7 @@ response = client.persons.create_person(data) ``` #### Update person -``` +```python data = { 'name': '' } @@ -360,63 +373,63 @@ response = client.persons.update_person('PERSON_ID', data) ``` #### Delete person -``` +```python response = client.persons.delete_person('PERSON_ID') ``` #### Get deals associated with a person -``` +```python response = client.persons.get_person_deals('PERSON_ID') ``` #### Get person fields -``` +```python response = client.persons.get_person_fields() ``` ### Pipelines -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Pipelines +API docs: https://developers.pipedrive.com/docs/api/v1/Pipelines #### Get a pipeline -``` +```python response = client.pipelines.get_pipeline('PIPELINE_ID') ``` #### Get all pipelines -``` +```python response = client.pipelines.get_all_pipelines() ``` #### Get deals attached to a pipeline -``` +```python response = client.pipelines.get_pipeline_deals() ``` ### Products -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Products +API docs: https://developers.pipedrive.com/docs/api/v1/Products #### Get a product -``` +```python response = client.products.get_product('PRODUCT_ID') ``` #### Get all products -``` +```python response = client.products.get_all_products() ``` -#### Get products by name -``` +#### Search products +```python params = { 'term': '' } -response = client.products.get_product_by_name(params=params) +response = client.products.search_products(params=params) ``` #### Create a product -``` +```python data = { 'name': '' } @@ -424,7 +437,7 @@ response = client.products.create_product(data) ``` #### Update a product -``` +```python data = { 'name': '' } @@ -432,33 +445,46 @@ response = client.products.update_product('PRODUCT_ID', data) ``` #### Delete a product -``` +```python response = client.products.delete_product('PRODUCT_ID') ``` #### Get deals where a product is attached to -``` +```python response = client.products.get_product_deal('PRODUCT_ID') ``` #### Get product fields -``` +```python response = client.products.get_product_fields() ``` ### Recents #### Get recent changes -``` +```python params = { 'since_timestamp': 'YYYY-MM-DD HH:MM:SS' } response = client.recents.get_recent_changes(params=params) ``` +### Leads +API docs: https://developers.pipedrive.com/docs/api/v1/Leads +#### Get a lead +```python +response = client.leads.get_lead('LEAD_ID') +``` +#### Search leads +```python +params = { + 'term': '' +} +response = client.leads.search_leads(params=params) +``` ### Users -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Users +API docs: https://developers.pipedrive.com/docs/api/v1/Users #### Get an user ``` @@ -477,7 +503,7 @@ response = client.users.get_me() ### Webhook -API docs: https://developers.pipedrive.com/docs/api/v1/#!/Webhooks +API docs: https://developers.pipedrive.com/docs/api/v1/Webhooks #### Get webhooks ``` diff --git a/pipedrive/activities.py b/pipedrive/activities.py index c09c832..5b41c6f 100644 --- a/pipedrive/activities.py +++ b/pipedrive/activities.py @@ -3,25 +3,25 @@ def __init__(self, client): self._client = client def get_activity(self, activity_id, **kwargs): - url = 'activities/{}'.format(activity_id) + 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 get_all_activities(self, params=None, **kwargs): + url = "activities" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def create_activity(self, data, **kwargs): - url = 'activities' + 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) + 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) + 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) + def get_activity_fields(self, params=None, **kwargs): + url = "activityFields" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) diff --git a/pipedrive/client.py b/pipedrive/client.py index a219105..856db91 100644 --- a/pipedrive/client.py +++ b/pipedrive/client.py @@ -6,19 +6,23 @@ from pipedrive.activities import Activities from pipedrive.deals import Deals from pipedrive.filters import Filters +from pipedrive.leads import Leads +from pipedrive.items import Items 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.stages import Stages from pipedrive.recents import Recents +from pipedrive.subscriptions import Subscriptions from pipedrive.users import Users from pipedrive.webhooks import Webhooks class Client: - BASE_URL = 'https://api-proxy.pipedrive.com/' - OAUTH_BASE_URL = 'https://oauth.pipedrive.com/oauth/' + BASE_URL = "https://api.pipedrive.com/" + OAUTH_BASE_URL = "https://oauth.pipedrive.com/oauth/" def __init__(self, client_id=None, client_secret=None, domain=None): self.client_id = client_id @@ -28,45 +32,57 @@ def __init__(self, client_id=None, client_secret=None, domain=None): self.activities = Activities(self) self.deals = Deals(self) self.filters = Filters(self) + self.leads = Leads(self) + self.items = Items(self) self.notes = Notes(self) self.organizations = Organizations(self) self.persons = Persons(self) self.pipelines = Pipelines(self) self.products = Products(self) + self.subscriptions = Subscriptions(self) self.recents = Recents(self) + self.stages = Stages(self) self.users = Users(self) self.webhooks = Webhooks(self) if domain: - if not domain.endswith('/'): - domain += '/' - self.BASE_URL = domain + 'v1/' + if not domain.endswith("/"): + domain += "/" + self.BASE_URL = domain + "v1/" def authorization_url(self, redirect_uri, state=None): params = { - 'client_id': self.client_id, - 'redirect_uri': redirect_uri, + "client_id": self.client_id, + "redirect_uri": redirect_uri, } if state is not None: - params['state'] = state + params["state"] = state - return self.OAUTH_BASE_URL + 'authorize?' + urlencode(params) + return self.OAUTH_BASE_URL + "authorize?" + urlencode(params) def exchange_code(self, redirect_uri, code): data = { - 'grant_type': 'authorization_code', - 'code': code, - 'redirect_uri': redirect_uri + "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)) + return self._post( + self.OAUTH_BASE_URL + "token", + data=data, + auth=(self.client_id, self.client_secret), + ) def refresh_token(self, refresh_token): data = { - 'grant_type': 'refresh_token', - 'refresh_token': refresh_token, + "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)) + return self._post( + self.OAUTH_BASE_URL + "token", + data=data, + auth=(self.client_id, self.client_secret), + ) def set_access_token(self, access_token): self.access_token = access_token @@ -74,25 +90,28 @@ def set_access_token(self, access_token): def set_api_token(self, api_token): self.api_token = api_token - def _get(self, url, **kwargs): - return self._request('get', url, **kwargs) + def _get(self, url, params=None, **kwargs): + return self._request("get", url, params=params, **kwargs) def _post(self, url, **kwargs): - return self._request('post', url, **kwargs) + return self._request("post", url, **kwargs) def _put(self, url, **kwargs): - return self._request('put', url, **kwargs) + return self._request("put", url, **kwargs) + + def _patch(self, url, **kwargs): + return self._request("patch", url, **kwargs) def _delete(self, url, **kwargs): - return self._request('delete', url, **kwargs) + return self._request("delete", url, **kwargs) def _request(self, method, url, headers=None, params=None, **kwargs): _headers = {} _params = {} if self.access_token: - _headers['Authorization'] = 'Bearer {}'.format(self.access_token) + _headers["Authorization"] = "Bearer {}".format(self.access_token) if self.api_token: - _params['api_token'] = self.api_token + _params["api_token"] = self.api_token if headers: _headers.update(headers) if params: @@ -101,15 +120,15 @@ def _request(self, method, url, headers=None, params=None, **kwargs): def _parse(self, response): status_code = response.status_code - if 'Content-Type' in response.headers and 'application/json' in response.headers['Content-Type']: + if "Content-Type" in response.headers and "application/json" in response.headers["Content-Type"]: r = response.json() else: return response.text if not response.ok: error = None - if 'error' in r: - error = r['error'] + if "error" in r: + error = r["error"] if status_code == 400: raise exceptions.BadRequestError(error, response) elif status_code == 401: diff --git a/pipedrive/deals.py b/pipedrive/deals.py index f966d17..d634fdd 100644 --- a/pipedrive/deals.py +++ b/pipedrive/deals.py @@ -3,83 +3,87 @@ def __init__(self, client): self._client = client def get_deal(self, deal_id, **kwargs): - url = 'deals/{}'.format(deal_id) + 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 get_all_deals(self, params=None, **kwargs): + url = "deals" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) - def get_all_deals_with_filter(self, filter_id, **kwargs): - url = 'deals?filter_id={}'.format(filter_id) - return self._client._get(self._client.BASE_URL + url, **kwargs) + def get_all_deals_with_filter(self, filter_id, params=None, **kwargs): + url = "deals?filter_id={}".format(filter_id) + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def create_deal(self, data, **kwargs): - url = 'deals' + 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) + 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) + 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) + 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) + 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 search_deals(self, params=None, **kwargs): + url = "deals/search" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def get_deal_followers(self, deal_id, **kwargs): - url = 'deals/{}/followers'.format(deal_id) + 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 - } + 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) + 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) + 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 - } + 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) + 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) + 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) + 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) + url = "deals/{}/products".format(deal_id) return self._client._get(self._client.BASE_URL + url, **kwargs) - def get_deal_fields(self, **kwargs): - url = 'dealFields' + def get_deal_fields(self, params=None, **kwargs): + url = "dealFields" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) + + def add_product_to_deal(self, deal_id, data, **kwargs): + url = "deals/{}/products".format(deal_id) + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def get_deal_updates(self, deal_id, **kwargs): + url = "deals/{}/flow".format(deal_id) return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/filters.py b/pipedrive/filters.py index d7dcb11..8d3d338 100644 --- a/pipedrive/filters.py +++ b/pipedrive/filters.py @@ -3,21 +3,21 @@ def __init__(self, client): self._client = client def get_filter(self, filter_id, **kwargs): - url = 'filters/{}'.format(filter_id) + 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 get_all_filters(self, params=None, **kwargs): + url = "filters" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def create_filter(self, data, **kwargs): - url = 'filters' + 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) + 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) + url = "filters/{}".format(filter_id) return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/items.py b/pipedrive/items.py new file mode 100644 index 0000000..124a0a7 --- /dev/null +++ b/pipedrive/items.py @@ -0,0 +1,7 @@ +class Items(object): + def __init__(self, client): + self._client = client + + def get_item_search(self, params=None, **kwargs): + url = "itemSearch" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) diff --git a/pipedrive/leads.py b/pipedrive/leads.py new file mode 100644 index 0000000..2efe4f2 --- /dev/null +++ b/pipedrive/leads.py @@ -0,0 +1,31 @@ +class Leads(object): + def __init__(self, client): + self._client = client + + def get_lead(self, lead_id, **kwargs): + url = "leads/{}".format(lead_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_leads(self, **kwargs): + url = "leads" + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_lead(self, data, **kwargs): + url = "leads" + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) + + def update_lead(self, lead_id, data, **kwargs): + url = "leads/{}".format(lead_id) + return self._client._patch(self._client.BASE_URL + url, json=data, **kwargs) + + def delete_lead(self, lead_id, **kwargs): + url = "leads/{}".format(lead_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) + + def get_lead_details(self, lead_id, **kwargs): + url = "leads/{}".format(lead_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def search_leads(self, params=None, **kwargs): + url = "leads/search" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) diff --git a/pipedrive/notes.py b/pipedrive/notes.py index 159ac98..362686d 100644 --- a/pipedrive/notes.py +++ b/pipedrive/notes.py @@ -3,25 +3,25 @@ def __init__(self, client): self._client = client def get_note(self, note_id, **kwargs): - url = 'notes/{}'.format(note_id) + 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 get_all_notes(self, params=None, **kwargs): + url = "notes" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def create_note(self, data, **kwargs): - url = 'notes' + 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) + 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) + 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) + def get_note_fields(self, params=None, **kwargs): + url = "noteFields" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) diff --git a/pipedrive/organizations.py b/pipedrive/organizations.py index 35970d6..193d491 100644 --- a/pipedrive/organizations.py +++ b/pipedrive/organizations.py @@ -3,25 +3,38 @@ def __init__(self, client): self._client = client def get_organization(self, organization_id, **kwargs): - url = 'organizations/{}'.format(organization_id) + 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 get_all_organizations(self, params=None, **kwargs): + url = "organizations" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def create_organization(self, data, **kwargs): - url = 'organizations' + 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) + 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) + 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) + def get_organization_fields(self, params=None, **kwargs): + url = "organizationFields" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) + + def search_organizations(self, params=None, **kwargs): + url = "organizations/search" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) + + def get_organization_persons(self, organization_id, params=None, **kwargs): + url = "organizations/{}/persons".format(organization_id) + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) + + def add_follower_to_organization(self, org_id, user_id, **kwargs): + url = "organizations/{}/followers".format(org_id) + data = {"user_id": user_id} + return self._post(self.BASE_URL+url, json=data, **kwargs) diff --git a/pipedrive/persons.py b/pipedrive/persons.py index b803f32..5d7f615 100644 --- a/pipedrive/persons.py +++ b/pipedrive/persons.py @@ -3,33 +3,42 @@ def __init__(self, client): self._client = client def get_person(self, person_id, **kwargs): - url = 'persons/{}'.format(person_id) + 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_all_persons(self, params=None, **kwargs): + url = "persons" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) - def get_persons_by_name(self, **kwargs): - url = 'persons/find' - return self._client._get(self._client.BASE_URL + url, **kwargs) + def search_persons(self, params=None, **kwargs): + url = "persons/search" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def create_person(self, data, **kwargs): - url = 'persons' + 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) + 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) + url = "persons/{}".format(person_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) def get_person_deals(self, person_id, **kwargs): - url = 'persons/{}/deals'.format(person_id) + url = "persons/{}/deals".format(person_id) return self._client._get(self._client.BASE_URL + url, **kwargs) - def get_person_fields(self, **kwargs): - url = 'personFields' + def get_person_fields(self, params=None, **kwargs): + url = "personFields" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) + + def get_person_activities(self, person_id, **kwargs): + url = "persons/{}/activities".format(person_id) return self._client._get(self._client.BASE_URL + url, **kwargs) + + def add_follower_to_person(self, person_id, user_id, **kwargs): + url = "persons/{}/followers".format(person_id) + data = {"user_id": user_id} + return self.client._post(self.BASE_URL+url, json=data, **kwargs) diff --git a/pipedrive/pipelines.py b/pipedrive/pipelines.py index 46c44f9..d22b177 100644 --- a/pipedrive/pipelines.py +++ b/pipedrive/pipelines.py @@ -3,13 +3,13 @@ def __init__(self, client): self._client = client def get_pipeline(self, pipeline_id, **kwargs): - url = 'pipelines/{}'.format(pipeline_id) + url = "pipelines/{}".format(pipeline_id) return self._client._get(self._client.BASE_URL + url, **kwargs) def get_all_pipelines(self, **kwargs): - url = 'pipelines' + 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) + 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 index 49870c5..1eff025 100644 --- a/pipedrive/products.py +++ b/pipedrive/products.py @@ -3,33 +3,33 @@ def __init__(self, client): self._client = client def get_product(self, product_id, **kwargs): - url = 'products/{}'.format(product_id) + url = "products/{}".format(product_id) return self._client._get(self._client.BASE_URL + url, **kwargs) def get_all_products(self, **kwargs): - url = 'products' + 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 search_products(self, params=None, **kwargs): + url = "products/search" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) def create_product(self, data, **kwargs): - url = 'products' + 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) + 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) + 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) + url = "products/{}/deals".format(product_id) return self._client._get(self._client.BASE_URL + url, **kwargs) def get_product_fields(self, **kwargs): - url = 'productFields' + url = "productFields" return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/recents.py b/pipedrive/recents.py index 5135e80..3de33b7 100644 --- a/pipedrive/recents.py +++ b/pipedrive/recents.py @@ -2,6 +2,6 @@ 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) + def get_recent_changes(self, params=None, **kwargs): + url = "recents" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) diff --git a/pipedrive/stages.py b/pipedrive/stages.py new file mode 100644 index 0000000..57ae854 --- /dev/null +++ b/pipedrive/stages.py @@ -0,0 +1,27 @@ +class Stages(object): + def __init__(self, client): + self._client = client + + def get_stage(self, stage_id, **kwargs): + url = "stages/{}".format(stage_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_stages(self, params=None, **kwargs): + url = "stages" + return self._client._get(self._client.BASE_URL + url, params=params, **kwargs) + + def get_stage_deals(self, stage_id, **kwargs): + url = "stages/{}/deals".format(stage_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def create_stage(self, data, **kwargs): + url = "stages" + return self._client._post(self._client.BASE_URL + url, data, **kwargs) + + def update_stage(self, stage_id, data, **kwargs): + url = "stages/{}".format(stage_id) + return self._client._put(self._client.BASE_URL + url, data, **kwargs) + + def delete_stage(self, stage_id, **kwargs): + url = "stages/{}".format(stage_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/subscriptions.py b/pipedrive/subscriptions.py new file mode 100644 index 0000000..d368f1d --- /dev/null +++ b/pipedrive/subscriptions.py @@ -0,0 +1,39 @@ +class Subscriptions(object): + def __init__(self, client): + self._client = client + + def get_subscription(self, subscription_id, **kwargs): + url = "subscriptions/{}".format(subscription_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_deal_subscription(self, deal_id, **kwargs): + url = "subscriptions/find/{}".format(deal_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def get_all_payments(self, subscription_id, **kwargs): + url = "subscriptions/{}/payments".format(subscription_id) + return self._client._get(self._client.BASE_URL + url, **kwargs) + + def add_recurring_subscription(self, data, **kwargs): + url = "subscriptions/recurring" + return self._client._post(self._client.BASE_URL + url, data, **kwargs) + + def add_installment_subscription(self, data, **kwargs): + url = "subscriptions/installment" + return self._client._post(self._client.BASE_URL + url, data, **kwargs) + + def update_recurring_subscription(self, subscription_id, data, **kwargs): + url = "subscriptions/recurring/{}".format(subscription_id) + return self._client._put(self._client.base_url + url, data, **kwargs) + + def update_installment_subscription(self, subscription_id, data, **kwargs): + url = "subscriptions/installment/{}".format(subscription_id) + return self._client._put(self._client.base_url + url, data, **kwargs) + + def cancel_recurring_subscription(self, subscription_id, data, **kwargs): + url = "subscriptions/recurring/{}/cancel".format(subscription_id) + return self._client._put(self._client.base_url + url, data, **kwargs) + + def delete_subscription(self, subscription_id, **kwargs): + url = "subscriptions/{}".format(subscription_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/users.py b/pipedrive/users.py index 3eb7ee4..fee6b79 100644 --- a/pipedrive/users.py +++ b/pipedrive/users.py @@ -3,13 +3,13 @@ def __init__(self, client): self._client = client def get_user(self, user_id, **kwargs): - url = 'users/{}'.format(user_id) + url = "users/{}".format(user_id) return self._client._get(self._client.BASE_URL + url, **kwargs) def get_all_users(self, **kwargs): - url = 'users' + url = "users" return self._client._get(self._client.BASE_URL + url, **kwargs) def get_me(self, **kwargs): - url = 'users/me' + url = "users/me" return self._client._get(self._client.BASE_URL + url, **kwargs) diff --git a/pipedrive/webhooks.py b/pipedrive/webhooks.py index 47f0264..bdf9c07 100644 --- a/pipedrive/webhooks.py +++ b/pipedrive/webhooks.py @@ -3,19 +3,18 @@ def __init__(self, client): self._client = client def get_hooks_subscription(self, **kwargs): - url = 'webhooks' - return self._client._get(url, **kwargs) + url = "webhooks" + return self._client._get(self._client.BASE_URL + url, **kwargs) def create_hook_subscription(self, subscription_url, event_action, event_object, **kwargs): - url = 'webhooks' + url = "webhooks" data = { - 'subscription_url': - subscription_url, - 'event_action': event_action, - 'event_object': event_object + "subscription_url": subscription_url, + "event_action": event_action, + "event_object": event_object, } - return self._client._post(url, json=data, **kwargs) + return self._client._post(self._client.BASE_URL + url, json=data, **kwargs) def delete_hook_subscription(self, hook_id, **kwargs): - url = 'webhooks/{}'.format(hook_id) - return self._client._delete(url, **kwargs) + url = "webhooks/{}".format(hook_id) + return self._client._delete(self._client.BASE_URL + url, **kwargs) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0eab7cd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "pipedrive-python-lib" +version = "1.2.3" +description = "API wrapper for Pipedrive written in Python" +authors = ["Miguel Ferrer "] +license = "MIT" +readme = "README.md" +packages = [{include = "pipedrive"}] + +[tool.poetry.dependencies] +python = "^3.7" +requests = "^2.26.0" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + diff --git a/setup.py b/setup.py deleted file mode 100644 index c11ddb0..0000000 --- a/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -from setuptools import setup - - -def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() - - -setup(name='pipedrive-python-lib', - version='1.1.1', - 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='Miguel Ferrer', - author_email='ingferrermiguel@gmail.com', - license='MIT', - packages=['pipedrive'], - install_requires=[ - 'requests', - ], - zip_safe=False)