def get( endpoint: 'The endpoint to interact with.', hostname: 'E.g. wholesale.sandbox1.nuorder.com for sandbox' = None, consumer_key: 'The consumer key to use' = None, consumer_secret: 'The oauth shared secret to use' = None, oauth_token: 'OAuth token' = None, oauth_token_secret: 'OAuth token secret' = None, config_section: 'The name of the config section to get settings from.' = 'sandbox', log_level: 'The log level to use.' = None, dry_run: "Don't actually run command, just show what would be run." = False ): """Make a GET request to NuOrder""" _set_log_level(log_level) c = functools.partial(ini_config.get, config_section) nu = nuorder.NuOrder( hostname=hostname or c('hostname'), consumer_key=consumer_key or c('consumer_key'), consumer_secret=consumer_secret or c('consumer_secret'), oauth_token=oauth_token or c('oauth_token'), oauth_token_secret=oauth_token_secret or c('oauth_token_secret'), ) resp_json = nu.get(endpoint=endpoint, dry_run=dry_run) return json.dumps(resp_json, indent=2)
def interact( hostname: 'E.g. wholesale.sandbox1.nuorder.com for sandbox' = None, consumer_key: 'The consumer key to use' = None, consumer_secret: 'The oauth shared secret to use' = None, oauth_token: 'OAuth token' = None, oauth_token_secret: 'OAuth token secret' = None, config_section: 'The name of the config section to get settings from.' = 'sandbox', log_level: 'The log level to use.' = None, ): """ Starts an IPython REPL to enable easy interaction with the NuOrder API """ _set_log_level(log_level) c = functools.partial(ini_config.get, config_section) nu = nuorder.NuOrder( hostname=hostname or c('hostname'), consumer_key=consumer_key or c('consumer_key'), consumer_secret=consumer_secret or c('consumer_secret'), oauth_token=oauth_token or c('oauth_token'), oauth_token_secret=oauth_token_secret or c('oauth_token_secret'), ) banner1 = """Welcome to the `nuorder` client interactive mode Available vars: {additional_arg} `nuorder` - An instantiation of the nuorder.NuOrder class Example usage: schemas = nuorder.get('/api/schemas') products = nuorder.get('/api/products') {additional_arg_example} Notes: * Official NuOrder docs can be found online here: https://nuorderapi1.docs.apiary.io/ * Creation of oauth tokens can't be done inside this mode. Please see `nuorder initiate --help`. """ IPython.embed(user_ns={'nuorder': nu}, banner1=banner1, config=traitlets.config.Config(colors='LightBG'))
def put( endpoint: 'The endpoint to interact with.', hostname: 'E.g. wholesale.sandbox1.nuorder.com for sandbox' = None, consumer_key: 'The consumer key to use' = None, consumer_secret: 'The oauth shared secret to use' = None, oauth_token: 'OAuth token' = None, oauth_token_secret: 'OAuth token secret' = None, data: 'The data to send along with POST/PUT. If `-` then read from stdin.' = None, config_section: 'The name of the config section to get settings from.' = 'sandbox', log_level: 'The log level to use.' = None, dry_run: "Don't actually run command, just show what would be run." = False, gzip_data: "Gzip data to NuOrder" = False): """Make a PUT request to NuOrder""" _set_log_level(log_level) c = functools.partial(ini_config.get, config_section) if data == '-': data = sys.stdin.buffer.read() nu = nuorder.NuOrder( hostname=hostname or c('hostname'), consumer_key=consumer_key or c('consumer_key'), consumer_secret=consumer_secret or c('consumer_secret'), oauth_token=oauth_token or c('oauth_token'), oauth_token_secret=oauth_token_secret or c('oauth_token_secret'), ) resp_json = nu.put( endpoint, data, dry_run=dry_run, gzip_data=gzip_data, ) return json.dumps(resp_json, indent=2)
def initiate( hostname: 'E.g. wholesale.sandbox1.nuorder.com for sandbox' = None, consumer_key: 'The consumer key to use' = None, consumer_secret: 'The oauth shared secret to use' = None, app_name: 'The application name.' = None, config_section: 'The name of the config section to get settings from.' = 'sandbox', log_level: 'The log level to use.' = None, dry_run: "Don't actually run command, just show what would be run." = False ): """Generate a new oauth token and secret Interactive command that requires you to go to the NuOrder admin page and confirm the request. """ _set_log_level(log_level) c = functools.partial(ini_config.get, config_section) base_kwargs = { 'hostname': hostname or c('hostname'), 'consumer_key': consumer_key or c('consumer_key'), 'consumer_secret': consumer_secret or c('consumer_secret'), } nu = nuorder.NuOrder( **base_kwargs, oauth_token='', oauth_token_secret='', ) resp_json = nu.oauth_initiate(app_name or c('app_name'), dry_run=dry_run) resp_text = json.dumps(resp_json, indent=2) if 'request_error' in resp_json: sys.exit(_failure(resp_text)) print('Got response:', resp_text, file=sys.stderr) if dry_run: sys.exit() print( "Now go to the API management section of NuOrder's admin page " "and approve the pending application that matches the details above. " "Copy the verification code that was shown in the pop-up after the " "approval was made and paste it here.", file=sys.stderr) verifier = input("Verification code [paste and press Enter]: ") nu = nuorder.NuOrder( **base_kwargs, oauth_token=resp_json['oauth_token'], oauth_token_secret=resp_json['oauth_token_secret'], ) resp_json = nu.oauth_token_request(verifier, dry_run=dry_run) if 'request_error' in resp_json: sys.exit(_failure(json.dumps(resp_json, indent=2))) print( 'Success! Final OAuth token and secret to use below. ' 'Remember to save them in the INI config.', file=sys.stderr) return json.dumps(resp_json, indent=2)