Skip to content

Commit

Permalink
Merge pull request #6 from algrebe/callback-support
Browse files Browse the repository at this point in the history
Callback support
  • Loading branch information
algrebe authored Jan 31, 2017
2 parents ca91297 + a094c31 commit 4df16f3
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 15 deletions.
34 changes: 34 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
language: python
python:
- "2.7"
install:
- "pip install ."
script:
- echo "no tests yet"
before_deploy:
- "wget https://github.com/jgm/pandoc/releases/download/1.19.1/pandoc-1.19.1-1-amd64.deb -O $TRAVIS_BUILD_DIR/pandoc.deb"
- "sudo dpkg -i $TRAVIS_BUILD_DIR/pandoc.deb"
- "rm $TRAVIS_BUILD_DIR/pandoc.deb"
- "pandoc --from=markdown --to=rst --output=$TRAVIS_BUILD_DIR/README.rst README.md"
deploy:
# test pypi
- provider: pypi
distributions: "sdist bdist_wheel"
server: https://testpypi.python.org/pypi
skip_cleanup: true
user: "deepcompute"
password:
secure: "qgwPDfVo/P1n0aQNwOvhQSQt1ikYLpPlVXfStW4FbyPJHA2YTfOjSvlIKhw9M2awHwI6bGZUlsV/po3Vsd8tdn665EjArTPIcuRs7Hf5qplC5XrwDynGzxAQ0JXKEHG3nlZ2/JPEGePgk05jQ1J/n7f7TfuZfG2IoSwkCAsKGcFQi741jowzAnWE2bmY1tGT2aYQSTSY4eARcIOZ6sORQ4Ac9RIM4Fiduyj48+WcSxRfYOWemZPJGLmTq/43CIcPSVpRoKA6zfuHUzegtjiyouqenGZQCa0sylUqZyLBq1MdeRwvR9LoUChisgoYlYVRiTKFMyvJg2ePKhLNqzBMFstnJQFbm8l6SNDZomJcMHImDBNX2zF6tSoN0K7OjMELUTIVhgEbhwr3htpzo31E/ZejpVbz1b0Z+xK4z8zGFxY+TqB0YyKTX7xTDZt6KHUukihLr/m669AsSd2Kh5xfWWbGJQbiA/0zqO8ECVoqPjP6k+9gCUWh96CJ5U+aIa0apL6tphaZ5+XZF5xy0Jhu+HRgwjPYDbl1H1lgtEADQrcIQ95poOZFSld/YXyND7xSP3W9wSg8x2ouascEUHivKR2jFPlxagsTrfOskOzTFNdqt3eoFgjqS/8cwKodDUzIopcSU+GF+juRjz7ty7tU1fasLkYZWIUGSAvO1ZeTrDQ="
on:
branch: master
tags: false
# pypi
- provider: pypi
distributions: "sdist bdist_wheel"
skip_cleanup: true
user: "deepcompute"
password:
secure: "qgwPDfVo/P1n0aQNwOvhQSQt1ikYLpPlVXfStW4FbyPJHA2YTfOjSvlIKhw9M2awHwI6bGZUlsV/po3Vsd8tdn665EjArTPIcuRs7Hf5qplC5XrwDynGzxAQ0JXKEHG3nlZ2/JPEGePgk05jQ1J/n7f7TfuZfG2IoSwkCAsKGcFQi741jowzAnWE2bmY1tGT2aYQSTSY4eARcIOZ6sORQ4Ac9RIM4Fiduyj48+WcSxRfYOWemZPJGLmTq/43CIcPSVpRoKA6zfuHUzegtjiyouqenGZQCa0sylUqZyLBq1MdeRwvR9LoUChisgoYlYVRiTKFMyvJg2ePKhLNqzBMFstnJQFbm8l6SNDZomJcMHImDBNX2zF6tSoN0K7OjMELUTIVhgEbhwr3htpzo31E/ZejpVbz1b0Z+xK4z8zGFxY+TqB0YyKTX7xTDZt6KHUukihLr/m669AsSd2Kh5xfWWbGJQbiA/0zqO8ECVoqPjP6k+9gCUWh96CJ5U+aIa0apL6tphaZ5+XZF5xy0Jhu+HRgwjPYDbl1H1lgtEADQrcIQ95poOZFSld/YXyND7xSP3W9wSg8x2ouascEUHivKR2jFPlxagsTrfOskOzTFNdqt3eoFgjqS/8cwKodDUzIopcSU+GF+juRjz7ty7tU1fasLkYZWIUGSAvO1ZeTrDQ="
on:
branch: master
tags: true
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# peoplegraph-api-client
# peoplegraph-api-client [![Build Status][travis-ci-status-img]][travis-ci-peoplegraph-api-client]

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


# Installation

```
Expand All @@ -16,3 +15,13 @@ Grab your api secret key from http://www.deepcompute.com/peoplegraph/settings
```bash
peoplegraph -H "http://www.deepcompute.com" -u "<username>" -s "<api-secret-key>" -n "John Doe" --wait
```

If you have a webserver that accepts POST requests, you can give peoplegraph a callback, to which it will
POST the result.

```bash
peoplegraph -H "http://www.deepcompute.com" -u "<username>" -s "<api-secret-key>" -n "John Doe" --callback "http://www.myserver.com"
```

[travis-ci-status-img]: https://travis-ci.org/deep-compute/peoplegraph-api-client.svg?branch=master
[travis-ci-peoplegraph-api-client]: https://travis-ci.org/deep-compute/peoplegraph-api-client
5 changes: 4 additions & 1 deletion peoplegraph_api_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ def __init__(self, host, username, secret):
self.host = host
self.auth = HmacAuth(username, secret)

def get_person(self, name):
def get_person(self, name, callback=None):
"""
queries the server for a person
"""

url = urljoin(self.host, "/peoplegraph/api/lookup")
params = { "name": name }
if callback is not None:
params['callback'] = callback

# TODO add settings
try:
resp = requests.get(url, auth=self.auth, params=params).json()
Expand Down
15 changes: 12 additions & 3 deletions peoplegraph_api_client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ def get_args():
parser.add_argument("-n", "--name", required=True,
help="name to query",
)

parser.add_argument("-H", "--host", default="http://www.deepcompute.com",
help="host server, default is %(default)s",
)
parser.add_argument("--wait", default=False, action="store_true",
help="block until the server gets data",
)

parser.add_argument("--callback", default=None,
help="the results are sent as a POST request to the given callback",
)
return parser.parse_args()

def main():
Expand All @@ -41,7 +42,7 @@ def main():
max_tries = 20
while not data_available:
num_tries += 1
resp = client.get_person(args.name)
resp = client.get_person(args.name, callback=args.callback)
data_available = resp.get('data_available', False)
if data_available:
sys.stdout.write("%s\n" % json.dumps(resp))
Expand All @@ -50,12 +51,20 @@ def main():

if not args.wait:
data = { "data_available": False, "msg": "Lookup in progress. Please try again after some time" }

if args.callback is not None:
data['msg'] = "Lookup in progress. A POST request will be sent to %s on completion" % args.callback

sys.stdout.write("%s\n" % json.dumps(resp))
sys.stdout.flush()
return

if num_tries >= max_tries:
data = { "data_available": False, "msg": "Lookup took too long. Please try again after some time" }
if args.callback is not None:
data['msg'] = "Lookup took too long, not waiting anymore. "\
"However, a POST request will be sent to %s on completion" % args.callback

sys.stdout.write("%s\n" % json.dumps(resp))
sys.stdout.flush()
return
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

38 changes: 31 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
from setuptools import setup, find_packages
import os

HERE = os.path.abspath(os.path.dirname(__file__))
def get_long_description():
dirs = [ HERE ]
if os.getenv("TRAVIS"):
dirs.append(os.getenv("TRAVIS_BUILD_DIR"))

long_description = ""

for d in dirs:
rst_readme = os.path.join(d, "README.rst")
if not os.path.exists(rst_readme):
continue

with open(rst_readme) as fp:
long_description = fp.read()
return long_description

return long_description

long_description = get_long_description()

version='0.1.1'
setup(
name="peoplegraph-api-client",
version="0.1.0",
version=version,
description="Peoplegraph api client",
long_description=long_description,
keywords="peoplegraph",
author="Deep Compute, LLC",
author_email="[email protected]",
url="https://github.com/deep-compute/peoplegraph-api-client",
download_url="https://github.com/deep-compute/peoplegraph-api-client/tarball/%s" % version,
license='MIT License',
packages=["peoplegraph_api_client"],
url="https://github.com/deep-compute/peoplegraph-api-client",
download_url="https://github.com/deep-compute/peoplegraph-api-client/tarball/0.1.0",
install_requires=[
"python-dateutil",
"requests>=2.11",
],
author="Deep-Compute",
author_email="[email protected]",
description="Peoplegraph api client",
keywords=["peoplegraph"],
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Environment :: Console",
Expand Down

0 comments on commit 4df16f3

Please sign in to comment.