GithubHelp home page GithubHelp logo

janrain-python-api's Introduction

Janrain Python API

BuildStatus

Python interface to the Janrain Capture API.

Requirements

Supports Python versions 2.7 & 3.3-3.4

Install

Download and install the most recent stable version using pip:

pip install janrain-python-api

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

git clone https://github.com/janrain/janrain-python-api.git
cd janrain-python-api
python setup.py install

Basic Usage

Low-Level API Calls

Use janrain.capture.Api to make low-level calls to the API.

from janrain.capture import Api

defaults = {
    'client_id': "YOUR_CLIENT_ID",
    'client_secret': "YOUR_CLIENT_SECRET"
}

api = Api("https://YOUR_APP.janraincapture.com", defaults)
result = api.call("entity.count", type_name="user")
print(result)

Exceptions

Exceptions are derived from JanrainApiException which includes error responses from the API. A try/catch bock should wrap any functions or methods that call the Janrain API.

import sys
from janrain.capture import Api, ApiResponseError
from requests import HTTPError

defaults = {
    'client_id': "YOUR_CLIENT_ID",
    'client_secret': "YOUR_CLIENT_SECRET"
}

api = Api("https://YOUR_APP.janraincapture.com", defaults)

try:
    result = api.call("entity.find", type_name="user")
except ApiResponseError as error:
    # Janrain API returned an error response
    sys.exit(str(error))
except HTTPError as error:
    # Python 'requests' library returned an error
    sys.exit(str(error))

Argument Parser

The library includes a subclass of the Python argparse configured to accept credentials for authenticating with the Janrain API. This can be used to simplify passing in credentials in custom command-line scripts.

from janrain.capture import cli

parser = cli.ApiArgumentParser()
args = parser.parse_args()
api = parser.init_api()

Which can then invoke from the command-line as follows:

python myscript.py  --api-url=[YOUR_CAPTURE_URL] \
                    --client-id=[YOUR_CLIENT_ID] \
                    --client-secret=[YOUR_CLIENT_SECRET] \

Command-Line Utility

The package installs an executable named capture-api for making API calls from the command-line.

Authenticate with the API by passing --api-url, --client-id, and --client-secret, then pass the API call, and then any parameters to send to the API as key=value pairs after the --parameters argument.

Examples

Passing the authentication credentials:

capture-api --apid-uri=[YOUR_CAPTURE_URL] \
            --client-id=[YOUR_CLIENT_ID] \
            --client-secret=[YOUR_CLIENT_SECRET] \
            entity.count --parameters type_name=user

Enclose JSON values in single outer-quotes and double inner-quotes:

capture-api --apid-uri=[YOUR_CAPTURE_URL] \
            --client-id=[YOUR_CLIENT_ID] \
            --client-secret=[YOUR_CLIENT_SECRET] \
            entity.find --parameters type_name=user \
            attributes='["displayName","email"]'

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

capture-api --apid-uri=[YOUR_CAPTURE_URL] \
            --client-id=[YOUR_CLIENT_ID] \
            --client-secret=[YOUR_CLIENT_SECRET] \
            entity.find --parameters type_name=user \
            filter="email = '[email protected]' and birthday is null"

Versioning

This software follows Semantic Versioning convention. http://semver.org/

Copyright © 2014 Janrain, Inc. All Rights Reserved.

janrain-python-api's People

Contributors

janrainmicah avatar ebeesonjanrain avatar janrain-colin avatar akameron avatar cloeperjanrain avatar sergiojanrain avatar jbush-janrain avatar ltd avatar cameron-janrain avatar bunchesofdonald avatar jtripp avatar iamjprowan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.