Beispiel #1
0
def restlet(script_id,
            payload,
            deploy=1,
            log_level=None,
            config_path=DEFAULT_INI_PATH,
            config_section=DEFAULT_INI_SECTION):
    """Make requests to restlets"""

    _set_log_level(log_level)
    conf = config.from_ini(path=config_path, section=config_section)
    ns = netsuite.NetSuite(conf)

    if not payload:
        payload = None
    elif payload == '-':
        payload = json.load(sys.stdin)
    else:
        payload = json.loads(payload)

    resp = ns.restlet.raw_request(
        script_id=script_id,
        deploy=deploy,
        payload=payload,
        raise_on_bad_status=False,
    )
    return resp.text
Beispiel #2
0
def interact(log_level=None,
             config_path=DEFAULT_INI_PATH,
             config_section=DEFAULT_INI_SECTION):
    """Starts a REPL to enable live interaction with NetSuite webservices"""
    _set_log_level(log_level)

    conf = config.from_ini(path=config_path, section=config_section)

    ns = netsuite.NetSuite(conf)

    user_ns = {'ns': ns}

    banner1 = """Welcome to Netsuite WS client interactive mode
Available vars:
    `ns` - NetSuite client

Example usage:
    ws_results = ns.getList('customer', internalIds=[1337])
    restlet_results = ns.restlet.request(987)
"""

    IPython.embed(
        user_ns=user_ns,
        banner1=banner1,
        config=traitlets.config.Config(colors='LightBG'),
        # To fix no colored input we pass in `using=False`
        # See: https://github.com/ipython/ipython/issues/11523
        # TODO: Remove once this is fixed upstream
        using=False,
    )
Beispiel #3
0
def interact(
    log_level: 'The log level to use' = None,
    config_path: 'The config file to get settings from.' = DEFAULT_INI_PATH,
    config_section:
    'The config section to get settings from.' = DEFAULT_INI_SECTION,
):
    """Starts a REPL to enable live interaction with NetSuite webservices"""
    _set_log_level(log_level)

    conf = config.from_ini(path=config_path, section=config_section)
    ns = netsuite.NetSuite(conf, sandbox=True)
    # print(ns.getList('customer', internalIds=['11397']))

    user_ns = {'ns': ns}

    banner1 = """Welcome to Netsuite WS client interactive mode
Available vars:
    `ns` - NetSuite client

Example usage:
    results = ns.getList('customer', internalIds=[1337])
"""

    IPython.embed(user_ns=user_ns,
                  banner1=banner1,
                  config=traitlets.config.Config(colors='LightBG'))
Beispiel #4
0
def _load_config_or_error(path: str, section: str) -> config.Config:
    try:
        return config.from_ini(path=path, section=section)
    except FileNotFoundError:
        parser.error(f"Config file {path} not found")
    except KeyError as ex:
        if ex.args == (section, ):
            parser.error(f"No config section `{section}` in file {path}")
        else:
            raise ex