11Janrain Python API
22================== 
33
4- Python interface to the 
4+ [](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
810Install
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
2018To 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
2725Basic Usage
2826----------- 
2927
3028Low-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"  
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
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
5452that 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"  
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+ 
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+ 
93+ 
94+     python myscript.py  --api-url=[YOUR_CAPTURE_URL] \ 
95+                         --client-id=[YOUR_CLIENT_ID] \ 
96+                         --client-secret=[YOUR_CLIENT_SECRET] \ 
6697
6798
6899Command-Line Utility
69100-------------------- 
70101
71102The 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 ``,
75106and ``--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
78109Examples
79110~~~~~~~~ 
@@ -95,12 +126,18 @@ Enclose JSON values in single outer-quotes and double inner-quotes::
95126
96127Enclose 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+ 
106143Copyright © 2014 Janrain, Inc. All Rights Reserved.
0 commit comments