Skip to content

Commit 4df16f3

Browse files
authored
Merge pull request #6 from algrebe/callback-support
Callback support
2 parents ca91297 + a094c31 commit 4df16f3

File tree

6 files changed

+92
-15
lines changed

6 files changed

+92
-15
lines changed

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
language: python
2+
python:
3+
- "2.7"
4+
install:
5+
- "pip install ."
6+
script:
7+
- echo "no tests yet"
8+
before_deploy:
9+
- "wget https://github.com/jgm/pandoc/releases/download/1.19.1/pandoc-1.19.1-1-amd64.deb -O $TRAVIS_BUILD_DIR/pandoc.deb"
10+
- "sudo dpkg -i $TRAVIS_BUILD_DIR/pandoc.deb"
11+
- "rm $TRAVIS_BUILD_DIR/pandoc.deb"
12+
- "pandoc --from=markdown --to=rst --output=$TRAVIS_BUILD_DIR/README.rst README.md"
13+
deploy:
14+
# test pypi
15+
- provider: pypi
16+
distributions: "sdist bdist_wheel"
17+
server: https://testpypi.python.org/pypi
18+
skip_cleanup: true
19+
user: "deepcompute"
20+
password:
21+
secure: "qgwPDfVo/P1n0aQNwOvhQSQt1ikYLpPlVXfStW4FbyPJHA2YTfOjSvlIKhw9M2awHwI6bGZUlsV/po3Vsd8tdn665EjArTPIcuRs7Hf5qplC5XrwDynGzxAQ0JXKEHG3nlZ2/JPEGePgk05jQ1J/n7f7TfuZfG2IoSwkCAsKGcFQi741jowzAnWE2bmY1tGT2aYQSTSY4eARcIOZ6sORQ4Ac9RIM4Fiduyj48+WcSxRfYOWemZPJGLmTq/43CIcPSVpRoKA6zfuHUzegtjiyouqenGZQCa0sylUqZyLBq1MdeRwvR9LoUChisgoYlYVRiTKFMyvJg2ePKhLNqzBMFstnJQFbm8l6SNDZomJcMHImDBNX2zF6tSoN0K7OjMELUTIVhgEbhwr3htpzo31E/ZejpVbz1b0Z+xK4z8zGFxY+TqB0YyKTX7xTDZt6KHUukihLr/m669AsSd2Kh5xfWWbGJQbiA/0zqO8ECVoqPjP6k+9gCUWh96CJ5U+aIa0apL6tphaZ5+XZF5xy0Jhu+HRgwjPYDbl1H1lgtEADQrcIQ95poOZFSld/YXyND7xSP3W9wSg8x2ouascEUHivKR2jFPlxagsTrfOskOzTFNdqt3eoFgjqS/8cwKodDUzIopcSU+GF+juRjz7ty7tU1fasLkYZWIUGSAvO1ZeTrDQ="
22+
on:
23+
branch: master
24+
tags: false
25+
# pypi
26+
- provider: pypi
27+
distributions: "sdist bdist_wheel"
28+
skip_cleanup: true
29+
user: "deepcompute"
30+
password:
31+
secure: "qgwPDfVo/P1n0aQNwOvhQSQt1ikYLpPlVXfStW4FbyPJHA2YTfOjSvlIKhw9M2awHwI6bGZUlsV/po3Vsd8tdn665EjArTPIcuRs7Hf5qplC5XrwDynGzxAQ0JXKEHG3nlZ2/JPEGePgk05jQ1J/n7f7TfuZfG2IoSwkCAsKGcFQi741jowzAnWE2bmY1tGT2aYQSTSY4eARcIOZ6sORQ4Ac9RIM4Fiduyj48+WcSxRfYOWemZPJGLmTq/43CIcPSVpRoKA6zfuHUzegtjiyouqenGZQCa0sylUqZyLBq1MdeRwvR9LoUChisgoYlYVRiTKFMyvJg2ePKhLNqzBMFstnJQFbm8l6SNDZomJcMHImDBNX2zF6tSoN0K7OjMELUTIVhgEbhwr3htpzo31E/ZejpVbz1b0Z+xK4z8zGFxY+TqB0YyKTX7xTDZt6KHUukihLr/m669AsSd2Kh5xfWWbGJQbiA/0zqO8ECVoqPjP6k+9gCUWh96CJ5U+aIa0apL6tphaZ5+XZF5xy0Jhu+HRgwjPYDbl1H1lgtEADQrcIQ95poOZFSld/YXyND7xSP3W9wSg8x2ouascEUHivKR2jFPlxagsTrfOskOzTFNdqt3eoFgjqS/8cwKodDUzIopcSU+GF+juRjz7ty7tU1fasLkYZWIUGSAvO1ZeTrDQ="
32+
on:
33+
branch: master
34+
tags: true

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# peoplegraph-api-client
1+
# peoplegraph-api-client [![Build Status][travis-ci-status-img]][travis-ci-peoplegraph-api-client]
22

33
API client for deep-compute's peoplegraph product http://www.deepcompute.com/peoplegraph/
44

5-
65
# Installation
76

87
```
@@ -16,3 +15,13 @@ Grab your api secret key from http://www.deepcompute.com/peoplegraph/settings
1615
```bash
1716
peoplegraph -H "http://www.deepcompute.com" -u "<username>" -s "<api-secret-key>" -n "John Doe" --wait
1817
```
18+
19+
If you have a webserver that accepts POST requests, you can give peoplegraph a callback, to which it will
20+
POST the result.
21+
22+
```bash
23+
peoplegraph -H "http://www.deepcompute.com" -u "<username>" -s "<api-secret-key>" -n "John Doe" --callback "http://www.myserver.com"
24+
```
25+
26+
[travis-ci-status-img]: https://travis-ci.org/deep-compute/peoplegraph-api-client.svg?branch=master
27+
[travis-ci-peoplegraph-api-client]: https://travis-ci.org/deep-compute/peoplegraph-api-client

peoplegraph_api_client/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ def __init__(self, host, username, secret):
7272
self.host = host
7373
self.auth = HmacAuth(username, secret)
7474

75-
def get_person(self, name):
75+
def get_person(self, name, callback=None):
7676
"""
7777
queries the server for a person
7878
"""
7979

8080
url = urljoin(self.host, "/peoplegraph/api/lookup")
8181
params = { "name": name }
82+
if callback is not None:
83+
params['callback'] = callback
84+
8285
# TODO add settings
8386
try:
8487
resp = requests.get(url, auth=self.auth, params=params).json()

peoplegraph_api_client/main.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ def get_args():
2222
parser.add_argument("-n", "--name", required=True,
2323
help="name to query",
2424
)
25-
2625
parser.add_argument("-H", "--host", default="http://www.deepcompute.com",
2726
help="host server, default is %(default)s",
2827
)
2928
parser.add_argument("--wait", default=False, action="store_true",
3029
help="block until the server gets data",
3130
)
32-
31+
parser.add_argument("--callback", default=None,
32+
help="the results are sent as a POST request to the given callback",
33+
)
3334
return parser.parse_args()
3435

3536
def main():
@@ -41,7 +42,7 @@ def main():
4142
max_tries = 20
4243
while not data_available:
4344
num_tries += 1
44-
resp = client.get_person(args.name)
45+
resp = client.get_person(args.name, callback=args.callback)
4546
data_available = resp.get('data_available', False)
4647
if data_available:
4748
sys.stdout.write("%s\n" % json.dumps(resp))
@@ -50,12 +51,20 @@ def main():
5051

5152
if not args.wait:
5253
data = { "data_available": False, "msg": "Lookup in progress. Please try again after some time" }
54+
55+
if args.callback is not None:
56+
data['msg'] = "Lookup in progress. A POST request will be sent to %s on completion" % args.callback
57+
5358
sys.stdout.write("%s\n" % json.dumps(resp))
5459
sys.stdout.flush()
5560
return
5661

5762
if num_tries >= max_tries:
5863
data = { "data_available": False, "msg": "Lookup took too long. Please try again after some time" }
64+
if args.callback is not None:
65+
data['msg'] = "Lookup took too long, not waiting anymore. "\
66+
"However, a POST request will be sent to %s on completion" % args.callback
67+
5968
sys.stdout.write("%s\n" % json.dumps(resp))
6069
sys.stdout.flush()
6170
return

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,44 @@
11
from setuptools import setup, find_packages
2+
import os
23

4+
HERE = os.path.abspath(os.path.dirname(__file__))
5+
def get_long_description():
6+
dirs = [ HERE ]
7+
if os.getenv("TRAVIS"):
8+
dirs.append(os.getenv("TRAVIS_BUILD_DIR"))
9+
10+
long_description = ""
11+
12+
for d in dirs:
13+
rst_readme = os.path.join(d, "README.rst")
14+
if not os.path.exists(rst_readme):
15+
continue
16+
17+
with open(rst_readme) as fp:
18+
long_description = fp.read()
19+
return long_description
20+
21+
return long_description
22+
23+
long_description = get_long_description()
24+
25+
version='0.1.1'
326
setup(
427
name="peoplegraph-api-client",
5-
version="0.1.0",
28+
version=version,
29+
description="Peoplegraph api client",
30+
long_description=long_description,
31+
keywords="peoplegraph",
32+
author="Deep Compute, LLC",
33+
author_email="[email protected]",
34+
url="https://github.com/deep-compute/peoplegraph-api-client",
35+
download_url="https://github.com/deep-compute/peoplegraph-api-client/tarball/%s" % version,
636
license='MIT License',
737
packages=["peoplegraph_api_client"],
8-
url="https://github.com/deep-compute/peoplegraph-api-client",
9-
download_url="https://github.com/deep-compute/peoplegraph-api-client/tarball/0.1.0",
1038
install_requires=[
1139
"python-dateutil",
1240
"requests>=2.11",
1341
],
14-
author="Deep-Compute",
15-
author_email="[email protected]",
16-
description="Peoplegraph api client",
17-
keywords=["peoplegraph"],
1842
classifiers=[
1943
"Development Status :: 2 - Pre-Alpha",
2044
"Environment :: Console",

0 commit comments

Comments
 (0)