Skip to content

Commit

Permalink
Finished other methods and added json property shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
leetrout committed Nov 13, 2013
1 parent 340a168 commit 639b828
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ That will return a new wrapper object representing a request to list all parties

#### Retrieve results ####

We can retrieve the parsed JSON results easily by using the json method
We can retrieve the parsed JSON results easily by using the json property

results = parties.json()
results = parties.json

All of this could also be written more concisely as

cap.party().json()
cap.party().json

#### Using query string parameters ####

Expand All @@ -82,7 +82,7 @@ Or /api/party/:id/people
TODO
====

+ Add Post/Put/Delete
+ Test with task creation
+ Add full examples to this readme
+ Add tests

53 changes: 31 additions & 22 deletions capsule_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,41 @@ def url(self):
url = self.base_url + '/'.join(map(str, self.path))
return url

@property
def request(self):
args = (self.method, self.url)
kwargs = {
'auth': self.auth,
'headers': self.headers,
}
if self.method == 'get':
kwargs['params'] = self.qs
else:
kwargs['data'] = json.dumps(self.qs)

return requests.request(*args, **kwargs)

def get(self):
return requests.request(
'get',
self.url,
auth=self.auth,
headers=self.headers,
params=self.qs
)
self.method = 'get'
return self.request

def post(self):
return requests.request(
'post',
self.url,
auth=self.auth,
data=json.dumps(self.qs),
headers=self.headers
)
self.method = 'post'
return self.request

def put(self):
return requests.request(
'put',
self.url,
auth=self.auth,
data=json.dumps(self.qs),
headers=self.headers
)
self.method = 'put'
return self.request

def delete(self):
self.method = 'delete'
return self.request

@property
def json(self):
return getattr(self, self.method)().json()
"""Short cut to json. Only works for GET requests.
cap.party().json instead of cap.part().get().json
"""
return getattr(self, self.method)().json
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='capsule_crm',
version='0.1',
version='0.1.1',
description='Capsule CRM Python API wrapper',
long_description=long_description,
author='Lee Trout',
Expand Down

0 comments on commit 639b828

Please sign in to comment.