Exemple #1
0
def main():
    """
    Main entry point for CLI. This may be called by running the module directly
    or by an executable installed onto the system path.
    """
    parser = ApiArgumentParser(formatter_class=lambda prog: HelpFormatter(prog,max_help_position=30))
    parser.add_argument('api_call',
                        help="API endpoint expressed as a relative path " \
                             "(eg. /settings/get).")
    # combining nargs='*' with append action produces a list of lists when
    # using -p multiple times.
    parser.add_argument('-p', '--parameters', action='append', nargs='*',
                        metavar="parameter=value",
                        help="parameters passed through to the API call")
    parser.add_argument('-v', '--version', action='version',
                        version="capture-api " + get_version())
    parser.add_argument('-x', '--disable-signed-requests', action='store_true',
                        help="sign HTTP requests")
    parser.add_argument('-b', '--debug', action='store_true',
                        help="log debug messages to stdout")
    parser.add_argument('-a', '--user-agent',
                        help="user agent to use for the API call")
    args = parser.parse_args()

    try:
        api = parser.init_api()
    except (JanrainConfigError, JanrainCredentialsError) as error:
        sys.exit(str(error))

    if args.disable_signed_requests:
        api.sign_requests = False

    if args.user_agent:
        api.user_agent = args.user_agent

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)

    # map list of parameters from command line into a dict for use as kwargs
    kwargs = {}
    if args.parameters:
        kwargs = dict(item.split("=", 1) for item in flatten_list(args.parameters))

    try:
        data = api.call(args.api_call, **kwargs)
    except ApiResponseError as error:
        sys.exit("API Error {} - {}\n".format(error.code, str(error)))

    print(json.dumps(data, indent=2, sort_keys=True))

    sys.exit()
Exemple #2
0
def main():
    """
    Main entry point for CLI. This may be called by running the module directly
    or by an executable installed onto the system path.
    """
    parser = ApiArgumentParser(formatter_class=lambda prog: HelpFormatter(prog,max_help_position=30))
    parser.add_argument('api_call', 
                        help="API endpoint expressed as a relative path " \
                             "(eg. /settings/get).")
    parser.add_argument('-p', '--parameters', nargs='*', 
                        metavar="parameter=value",
                        help="parameters passed through to the API call")
    parser.add_argument('-v', '--version', action='version', 
                        version="capture-api " + get_version())
    args = parser.parse_args()
    
    try:
        api = parser.init_api()
    except (JanrainConfigError, JanrainCredentialsError) as error:
        sys.exit(error.message)
    
    # map list of parameters from command line into a dict for use as kwargs
    kwargs = {}
    if args.parameters:
        kwargs = dict((key, value) for key, value in [s.split("=", 1) 
                      for s in args.parameters])
    
    try:
        data = api.call(args.api_call, **kwargs)
    except ApiResponseError as error:
        sys.exit("Error {} - {}\n".format(error.code, error.message))
    except Exception as error:
        sys.exit("Error - {}\n".format(error))
    
    print(json.dumps(data, indent=2, sort_keys=True))
    
    sys.exit()
Exemple #3
0
def main():
    """
    Main entry point for CLI. This may be called by running the module directly
    or by an executable installed onto the system path.
    """
    parser = ApiArgumentParser(
        formatter_class=lambda prog: HelpFormatter(prog, max_help_position=30))
    parser.add_argument('api_call',
                        help="API endpoint expressed as a relative path " \
                             "(eg. /settings/get).")
    # combining nargs='*' with append action produces a list of lists when
    # using -p multiple times.
    parser.add_argument('-p',
                        '--parameters',
                        action='append',
                        nargs='*',
                        metavar="parameter=value",
                        help="parameters passed through to the API call")
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version="capture-api " + get_version())
    parser.add_argument('-x',
                        '--disable-signed-requests',
                        action='store_true',
                        help="sign HTTP requests")
    parser.add_argument('-b',
                        '--debug',
                        action='store_true',
                        help="log debug messages to stdout")
    parser.add_argument('-a',
                        '--user-agent',
                        help="user agent to use for the API call")
    args = parser.parse_args()

    try:
        api = parser.init_api()
    except (JanrainConfigError, JanrainCredentialsError) as error:
        sys.exit(str(error))

    if args.disable_signed_requests:
        api.sign_requests = False

    if args.user_agent:
        api.user_agent = args.user_agent

    if args.debug:
        logging.basicConfig(level=logging.DEBUG)

    # map list of parameters from command line into a dict for use as kwargs
    kwargs = {}
    if args.parameters:
        kwargs = dict(
            item.split("=", 1) for item in flatten_list(args.parameters))

    try:
        data = api.call(args.api_call, **kwargs)
    except ApiResponseError as error:
        sys.exit("API Error {} - {}\n".format(error.code, str(error)))

    print(json.dumps(data, indent=2, sort_keys=True))

    sys.exit()
#!/usr/bin/env python
import distribute_setup
distribute_setup.use_setuptools()

import os
from setuptools import setup, find_packages

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

from janrain.capture import get_version

setup(
    name = "janrain-python-api", 
    version = get_version(),
    description = "Python interface to the Janrain Capture API.",
    long_description = read("README.rst"),
    author = "Micah Carrick",
    author_email = "*****@*****.**",
    url = "http://developers.janrain.com/",
    packages = find_packages(),
    namespace_packages = ["janrain"],
    scripts=[os.path.join("bin", script) for script in os.listdir("./bin")],
    #license = "",
    classifiers = [
        "Development Status :: 4 - Beta",
        "Environment :: Console",
        "Intended Audience :: Developers",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Topic :: Software Development :: Libraries :: Python Modules",
import distribute_setup
distribute_setup.use_setuptools()

import os
from setuptools import setup, find_packages


def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()


from janrain.capture import get_version

setup(
    name="janrain-python-api",
    version=get_version(),
    description="Python interface to the Janrain Capture API.",
    long_description=read("README.rst"),
    author="Micah Carrick",
    author_email="*****@*****.**",
    url="http://developers.janrain.com/",
    packages=find_packages(),
    namespace_packages=["janrain"],
    scripts=[os.path.join("bin", script) for script in os.listdir("./bin")],
    package_data={'janrain.capture.test': ["janrain-config"]},
    #license = "",
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Environment :: Console", "Intended Audience :: Developers",
        "Operating System :: OS Independent", "Programming Language :: Python",
        "Topic :: Software Development :: Libraries :: Python Modules",