Skip to content

Commit 8bde463

Browse files
author
Yordy Gelvez
committed
instance improvements
1 parent cb21771 commit 8bde463

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ git+git://github.com/GearPlug/pipedrive-python
77
```
88

99
## Usage
10+
If you are not going to use the authentication flow, just instance the library like this:
1011
```
1112
from pipedrive.client import Client
12-
client = Client('CLIENT_ID', 'CLIENT_SECRET', 'OPTIONAL - access_token')
13+
client = Client()
14+
```
15+
If on the contrary you will use it, send "oauth=True" in the main instance like this:
16+
```
17+
from pipedrive.client import Client
18+
client = Client('CLIENT_ID', 'CLIENT_SECRET', oauth=True)
19+
```
20+
21+
And to make requests send the access token
22+
```
23+
client.set_token(access_token)
1324
```
1425
#### Get authorization url
1526
```
@@ -26,11 +37,6 @@ token = client.exchange_code('REDIRECT_URL', 'CODE')
2637
token = client.refresh_token('REFRESH TOKEN')
2738
```
2839

29-
#### Set token
30-
```
31-
token = client.set_token('TOKEN')
32-
```
33-
3440
#### Get recent changes
3541
```
3642
token = client.get_recent_changes(since_timestamp="YYYY-MM-DD HH:MM:SS")

pipedrive/client.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ class Client:
77
flow_base_url = "https://oauth.pipedrive.com/oauth/"
88
oauth_end = "authorize?"
99
token_end = "token"
10-
api_base_url = ""
11-
example_url = "https://api-proxy.pipedrive.com"
10+
api_base_url = "https://companydomain.pipedrive.com/"
11+
api_version = "v1/"
1212
header = {"Accept": "application/json, */*", "content-type": "application/json"}
1313

14-
def __init__(self, client_id=None, client_secret=None, token=None):
14+
def __init__(self, client_id=None, client_secret=None, oauth=False):
1515
self.client_id = client_id
1616
self.client_secret = client_secret
17-
self.token = token
17+
self.oauth = oauth
18+
self.token = None
1819

1920
def make_request(self, method, endpoint, data=None, json=None, **kwargs):
2021
"""
@@ -26,9 +27,11 @@ def make_request(self, method, endpoint, data=None, json=None, **kwargs):
2627
:return:
2728
"""
2829
if self.token:
29-
self.header["Authorization"] = "Bearer " + self.token
30-
url = '{0}{1}'.format(self.api_base_url, endpoint)
31-
30+
if self.oauth:
31+
self.header["Authorization"] = "Bearer " + self.token
32+
url = '{0}{1}{2}'.format(self.api_base_url, self.api_version, endpoint)
33+
else:
34+
url = '{0}{1}{2}?api_token={3}'.format(self.api_base_url, self.api_version, endpoint, self.token)
3235
if method == "get":
3336
response = requests.request(method, url, headers=self.header, params=kwargs)
3437
else:
@@ -413,7 +416,3 @@ def delete_hook_subscription(self, hook_id):
413416
return self._delete(url)
414417
else:
415418
raise Exception("The attributes necessary to delete the webhook were not obtained.")
416-
417-
418-
419-

setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
import os
12
from setuptools import setup
23

4+
5+
def read(fname):
6+
return open(os.path.join(os.path.dirname(__file__), fname)).read()
7+
8+
39
setup(name='pipedrive',
410
version='0.1',
511
description='API wrapper for Pipedrive written in Python',
12+
long_description=read('README.md'),
613
url='https://github.com/GearPlug/pipedrive-python',
714
author='Yordy Gelvez',
815
author_email='[email protected]',

0 commit comments

Comments
 (0)