Skip to content

Commit e691e6f

Browse files
Merge pull request #6 from janrain/v0.3.0
v0.3.0 (requests and Python 3 support)
2 parents 5eabd6b + a710523 commit e691e6f

File tree

14 files changed

+375
-195
lines changed

14 files changed

+375
-195
lines changed

.gitignore

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,60 @@
1-
*.pyc
2-
__pycache__
3-
*.egg-info
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
eggs/
15+
lib/
16+
lib64/
17+
parts/
18+
sdist/
19+
var/
20+
*.egg-info/
21+
.installed.cfg
22+
*.egg
423
distribute-*
5-
build
6-
dist
24+
25+
# PyInstaller
26+
# Usually these files are written by a python script from a template
27+
# before PyInstaller builds the exe, so as to inject date/other infos
28+
# into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.coverage
40+
.cache
41+
nosetests.xml
42+
coverage.xml
743
test.log
44+
45+
# Translations
46+
*.mo
47+
*.pot
48+
49+
# Django stuff:
50+
*.log
51+
52+
# Sphinx documentation
53+
docs/_build/
54+
55+
# PyBuilder
56+
target/
57+
58+
# Virtual Environment
59+
venv
60+

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: python
2+
python:
3+
- "2.7"
4+
- "3.2"
5+
- "3.3"
6+
- "3.4"
7+
# command to install dependencies
8+
install: travis_retry python setup.py install
9+
# command to run tests
10+
script: nosetests --with-doctest

CONTRIBUTING.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Contributing
2+
============
3+
4+
Testing
5+
-------
6+
7+
If you are using a **virtualenv** run the following before running tests::
8+
9+
python setup.py install
10+
11+
To run all tests::
12+
13+
python setup.py nosetests --with-doctest
14+
15+
To run only doctests::
16+
17+
python setup.py nosetests --doctest-tests
18+
19+
To run one specific test suite::
20+
21+
python setup.py nosetests --tests janrain.capture.test.test_api
22+
23+
To run a specific unit test::
24+
25+
python setup.py nosetests \
26+
--tests janrain.capture.test.test_api:TestApi.test_api_encode

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include README.rst MANIFEST.in LICENSE distribute_setup.py
1+
include README.rst LICENSE MANIFEST.in distribute_setup.py

README.rst

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
Janrain Python API
22
==================
33

4-
Python interface to the
4+
[![Build Status](https://travis-ci.org/janrain/janrain-python-api.png?branch=master)](https://travis-ci.org/janrain/janrain-python-api)
5+
6+
Python interface to the
57
`Janrain Capture <http://janrain.com/products/capture/>`_ API.
68

79

810
Install
911
-------
1012

11-
Download and install the most recent stable version using ``pip`` (preferred)::
13+
Download and install the most recent stable version using ``pip``::
1214

1315
pip install janrain-python-api
1416

15-
... or using (``easy_install``)::
16-
17-
easy_install janrain-python-api
18-
1917

2018
To use the unstable developement version, download the package by cloning the git repository::
2119

2220
git clone https://github.com/janrain/janrain-python-api.git
2321
cd janrain-python-api
2422
python setup.py install
25-
23+
2624

2725
Basic Usage
2826
-----------
2927

3028
Low-Level API Calls
3129
~~~~~~~~~~~~~~~~~~~
3230

33-
Use ``janrain.capture.Api`` to make low-level calls to the API.
31+
Use ``janrain.capture.Api`` to make low-level calls to the API.
3432

3533
.. code-block:: python
3634
37-
from janrain.capture import api as Api
38-
35+
from janrain.capture import Api
36+
3937
defaults = {
40-
'client_id': "YOUR_CLIENT_ID",
38+
'client_id': "YOUR_CLIENT_ID",
4139
'client_secret': "YOUR_CLIENT_SECRET"
4240
}
43-
41+
4442
api = Api("https://YOUR_APP.janraincapture.com", defaults)
4543
result = api.call("entity.count", type_name="user")
4644
print(result)
@@ -49,31 +47,64 @@ Use ``janrain.capture.Api`` to make low-level calls to the API.
4947
Exceptions
5048
~~~~~~~~~~
5149

52-
Exceptions are derived from ``JanrainApiException`` which includes error
53-
responses from the API. A try/catch bock should wrap any functions or methods
50+
Exceptions are derived from ``JanrainApiException`` which includes error
51+
responses from the API. A try/catch bock should wrap any functions or methods
5452
that call the Janrain API.
5553

5654
.. code-block:: python
5755
56+
from janrain.capture import Api, ApiResponseError
57+
from requests import HTTPError
58+
59+
defaults = {
60+
'client_id': "YOUR_CLIENT_ID",
61+
'client_secret': "YOUR_CLIENT_SECRET"
62+
}
63+
64+
api = Api("https://YOUR_APP.janraincapture.com", defaults)
65+
5866
try:
5967
result = api.call("entity.find", type_name="user")
60-
except janrain.capture.InvalidApiCallError as error:
61-
# 404 error
62-
sys.exit("Invalid API Endpoint: " + error.message)
6368
except janrain.capture.ApiResponseError as error:
64-
# API returned an error response
65-
sys.exit("API Error: " + error.message)
69+
# Janrain API returned an error response
70+
sys.exit(str(error))
71+
except HTTPError as error:
72+
# Python 'requests' library returned an error
73+
sys.exit(str(error))
74+
75+
76+
Argument Parser
77+
~~~~~~~~~~~~~~~
78+
79+
The library includes a subclass of the Python
80+
`argparse <https://docs.python.org/dev/library/argparse.html>`_ configured to
81+
accept credentials for authenticating with the Janrain API. This can be used to
82+
simplify passing in credentials in custom command-line scripts.
83+
84+
.. code-block:: python
85+
86+
from janrain.capture import cli
87+
88+
parser = cli.ApiArgumentParser()
89+
args = parser.parse_args()
90+
api = parser.init_api()
91+
92+
Which can then invoke from the command-line as follows::
93+
94+
python myscript.py --api-url=[YOUR_CAPTURE_URL] \
95+
--client-id=[YOUR_CLIENT_ID] \
96+
--client-secret=[YOUR_CLIENT_SECRET] \
6697

6798

6899
Command-Line Utility
69100
--------------------
70101

71102
The package installs an executable named ``capture-api`` for making
72-
API calls from the command-line.
103+
API calls from the command-line.
73104

74-
Authenticate with the API by passing ``--api-url``, ``--client-id``,
105+
Authenticate with the API by passing ``--api-url``, ``--client-id``,
75106
and ``--client-secret``, then pass the API call, and then any parameters to
76-
send to the API as key=value pairs after the ``--parameters`` argument.
107+
send to the API as key=value pairs after the ``--parameters`` argument.
77108

78109
Examples
79110
~~~~~~~~
@@ -95,12 +126,18 @@ Enclose JSON values in single outer-quotes and double inner-quotes::
95126

96127
Enclose filters in double outer-quotes and single inner-quotes::
97128

98-
capture-api --api-url=[YOUR_CAPTURE_URL] \
129+
capture-api --api-url=[YOUR_CAPTURE_URL] \
99130
--client-id=[YOUR_CLIENT_ID] \
100131
--client-secret=[YOUR_CLIENT_SECRET] \
101132
entity.find --parameters type_name=user \
102133
filter="email = 'demo@janrain.com' and birthday is null"
103134

104135
----
105136

137+
Versioning
138+
----------
139+
This software follows Semantic Versioning convention.
140+
http://semver.org/
141+
142+
106143
Copyright © 2014 Janrain, Inc. All Rights Reserved.

janrain/capture/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from janrain.capture.api import Api
22
from janrain.capture.exceptions import *
33

4-
VERSION = (0, 2, 4)
4+
VERSION = (0, 3, 0)
55

66
def get_version():
77
return "%s.%s.%s" % (VERSION[0], VERSION[1], VERSION[2])

0 commit comments

Comments
 (0)