def cmd_session_latest(source_identifier, user_identifier=None): user = helpers.get_or_create_user(user_identifier) sources = ricloud.Source.list(user=user, identifier=source_identifier) if sources.data: source = sources.data[0] else: warn( "No sources (identifier:{src_identifier}) found for user (identifier:{usr.identifier}).".format( src_identifier=source_identifier, usr=user ) ) raise click.Abort sessions = ricloud.Session.list(source=source, state="active", limit=1) if sessions.data: session = sessions.data[0] else: warn( "No active sessions exist for source (id:{src.id}, identifier:{src.identifier}).".format( src=source ) ) raise click.Abort info(compat.to_str(session))
def cmd_sub_poll(subscription_id, info_types, data_types, files): """Create a manual poll against an existing subscription.""" payload = helpers.build_poll_payload(info_types, data_types, files) poll = helpers.create_poll(payload, subscription=subscription_id) info(compat.to_str(poll))
def cmd_sub_create(session_id, source_id, info_types, data_types, files): session = helpers.retrieve_session(session_id) poll_payload = helpers.build_poll_payload(info_types, data_types, files) sub = helpers.create_subscription( session, source=source_id, poll_payload=poll_payload ) info(compat.to_str(sub))
def cmd_poll_latest(session_id): polls = ricloud.Poll.list(session=session_id, limit=1) if polls.data: poll = polls.data[0] else: warn("No polls found for session (id:{})".format(session_id)) raise click.Abort info(compat.to_str(poll))
def cmd_sub_latest(subscription_id): """Retrieve the latest automatic poll for the subscription.""" polls = ricloud.Poll.list( subscription=subscription_id, requestor="subscription", limit=1 ) if not polls: info("No automatic polls found for this subscription.") return poll = polls[0] info(compat.to_str(poll))
def _encode(data): """Adapted from Django source: https://github.com/django/django/blob/master/django/core/serializers/json.py """ if isinstance(data, datetime.datetime): r = data.isoformat() if data.microsecond: r = r[:23] + r[26:] if r.endswith("+00:00"): r = r[:-6] + "Z" return r elif isinstance(data, datetime.date): return data.isoformat() elif isinstance(data, datetime.time): r = data.isoformat() if data.microsecond: r = r[:12] return r elif isinstance(data, datetime.timedelta): return data.total_seconds() elif isinstance(data, (decimal.Decimal, uuid.UUID)): return compat.to_str(data)
def cmd_session_retrieve(session_id): session = helpers.retrieve_session(session_id) info(compat.to_str(session))
def cmd_session_create(rirelay_pairing_code, user_identifier=None): user = helpers.get_or_create_user(user_identifier) session = create_session(user.id, rirelay_pairing_code) info(compat.to_str(session))
def cmd_sub_retrieve(subscription_id): sub = ricloud.Subscription.retrieve(id=subscription_id) info(compat.to_str(sub))
def cmd_session_create(icloud_username, icloud_password, user_identifier=None): user = helpers.get_or_create_user(user_identifier) session = create_session(user.id, icloud_username, icloud_password) info(compat.to_str(session))
def cmd_result_retrieve(result_id): result = ricloud.Result.retrieve(id=result_id) info(compat.to_str(result))
def cmd_poll_retrieve(poll_id): poll = ricloud.Poll.retrieve(id=poll_id) info(compat.to_str(poll))
def cmd_poll_create(session_id, source_id, info_types, data_types, files): payload = helpers.build_poll_payload(info_types, data_types, files) poll = helpers.create_poll(payload, session=session_id, source=source_id) info(compat.to_str(poll))