コード例 #1
0
ファイル: payment.py プロジェクト: stevenleeg/Venmo
    def from_json(cls, json):
        """
        init a new Payment form JSON
        :param json:
        :return:
        """
        if not json:
            return

        parser = JSONSchema.payment(json)

        return cls(
            id_=parser.get_id(),
            actor=User.from_json(parser.get_actor()),
            target=User.from_json(parser.get_target()),
            action=parser.get_action(),
            amount=parser.get_amount(),
            audience=parser.get_amount(),
            date_created=string_to_timestamp(parser.get_date_created()),
            date_reminded=string_to_timestamp(parser.get_date_reminded()),
            date_completed=string_to_timestamp(parser.get_date_completed()),
            note=parser.get_note(),
            status=PaymentStatus(parser.get_status()),
            json=json
        )
コード例 #2
0
ファイル: user.py プロジェクト: will-holley/Venmo
    def from_json(cls, json, is_profile=False):
        """
        init a new user form JSON
        :param json:
        :param is_profile:
        :return:
        """
        if not json:
            return

        parser = JSONSchema.user(json, is_profile=is_profile)

        date_joined_timestamp = string_to_timestamp(parser.get_date_created())

        return cls(user_id=parser.get_user_id(),
                   username=parser.get_username(),
                   first_name=parser.get_first_name(),
                   last_name=parser.get_last_name(),
                   display_name=parser.get_full_name(),
                   phone=parser.get_phone(),
                   profile_picture_url=parser.get_picture_url(),
                   about=parser.get_about(),
                   date_joined=date_joined_timestamp,
                   is_group=parser.get_is_group(),
                   is_active=parser.get_is_active())
コード例 #3
0
    def from_json(cls, json):
        """
        Create a new Mention from the given json.
        :param json:
        :return:
        """

        if not json:
            return

        parser = JSONSchema.mention(json)

        return cls(username=parser.get_username(),
                   user=User.from_json(parser.get_user()),
                   json=json)
コード例 #4
0
    def from_json(cls, json: Dict):

        payment_parser = JSONSchema.payment_method(json)

        pid = payment_parser.get_id()
        p_role = payment_parser.get_payment_method_role()
        p_name = payment_parser.get_payment_method_name()
        p_type = payment_parser.get_payment_method_type()

        # Get the class for this payment, must be either VenmoBalance or BankAccount
        payment_class = payment_type[p_type]

        return payment_class(pid=pid,
                             p_role=p_role,
                             p_name=p_name,
                             p_type=p_type)
コード例 #5
0
ファイル: transaction.py プロジェクト: alexwilson1/Venmo
    def from_json(cls, json):
        """
        Create a new Transaction from the given json.
        This only works for transactions, skipping refunds and bank transfers.
        :param json:
        :return:
        """

        if not json:
            return

        parser = JSONSchema.transaction(json)
        transaction_type = TransactionType(parser.get_transaction_type())

        # Currently only handles Payment-type transactions
        if transaction_type is not TransactionType.PAYMENT:
            return

        date_created = string_to_timestamp(parser.get_date_created())
        date_updated = string_to_timestamp(parser.get_date_updated())
        date_completed = string_to_timestamp(parser.get_date_completed())
        target = User.from_json(json=parser.get_target())
        actor = User.from_json(json=parser.get_actor())
        device_used = get_phone_model_from_json(parser.get_actor_app())

        comments_list = parser.get_comments()
        comments = [
            Comment.from_json(json=comment) for comment in comments_list
        ] if comments_list else []

        return cls(story_id=parser.get_story_id(),
                   payment_id=parser.get_payment_id(),
                   date_completed=date_completed,
                   date_created=date_created,
                   date_updated=date_updated,
                   payment_type=parser.get_type(),
                   amount=parser.get_amount(),
                   audience=parser.get_audience(),
                   note=parser.get_story_note(),
                   status=parser.get_status(),
                   device_used=device_used,
                   actor=actor,
                   target=target,
                   comments=comments,
                   json=json)
コード例 #6
0
    def from_json(cls, json: Dict):

        payment_parser = JSONSchema.payment_method(json)

        pid = payment_parser.get_id()
        p_role = payment_parser.get_payment_method_role()
        p_name = payment_parser.get_payment_method_name()
        p_type = payment_parser.get_payment_method_type()

        # Get the class for this payment, must be either VenmoBalance or BankAccount
        payment_class = payment_type.get(p_type)
        if not payment_class:
            logging.warning(f"Skipped a payment_method; No schema existed for the payment_method: {p_type}")
            return

        return payment_class(pid=pid,
                             p_role=p_role,
                             p_name=p_name,
                             p_type=p_type)
コード例 #7
0
ファイル: comment.py プロジェクト: alexwilson1/Venmo
    def from_json(cls, json):
        """
        Create a new Comment from the given json.
        :param json:
        :return:
        """

        if not json:
            return

        parser = JSONSchema.comment(json)

        mentions_list = parser.get_mentions()
        mentions = [Mention.from_json(mention)
                    for mention in mentions_list] if mentions_list else []

        return cls(id_=parser.get_id(),
                   message=parser.get_message(),
                   date_created=string_to_timestamp(parser.get_date_created()),
                   mentions=mentions,
                   user=User.from_json(parser.get_user()),
                   json=json)
コード例 #8
0
ファイル: transaction.py プロジェクト: hshore29/Venmo
    def from_json(cls, json):
        """
        Create a new Transaction from the given json.
        This only works for transactions, skipping refunds and bank transfers.
        :param json:
        :return:
        """

        if not json:
            return

        parser = JSONSchema.transaction(json)
        transaction_type = TransactionType(parser.get_transaction_type())

        # Skip money transfers to/from bank accounts and refunds
        if transaction_type == TransactionType.REFUND or transaction_type == TransactionType.TRANSFER:
            return

        date_created = string_to_timestamp(parser.get_date_created())
        date_updated = string_to_timestamp(parser.get_date_updated())
        date_completed = string_to_timestamp(parser.get_date_completed())
        target = User.from_json(json=parser.get_target())
        actor = User.from_json(json=parser.get_actor())
        device_used = get_phone_model_from_json(parser.get_actor_app())

        return cls(story_id=parser.get_story_id(),
                   payment_id=parser.get_payment_id(),
                   date_completed=date_completed,
                   date_created=date_created,
                   date_updated=date_updated,
                   payment_type=parser.get_type(),
                   amount=parser.get_amount(),
                   audience=parser.get_audience(),
                   note=parser.get_story_note(),
                   status=parser.get_status(),
                   device_used=device_used,
                   actor=actor,
                   target=target)
コード例 #9
0
ファイル: transaction.py プロジェクト: cjhetzle/Venmo
    def from_json(cls, json):

        parser = JSONSchema.transaction(json)
        date_created = string_to_timestamp(parser.get_date_created())
        date_updated = string_to_timestamp(parser.get_date_updated())
        date_completed = string_to_timestamp(parser.get_date_completed())

        target = User.from_json(json=parser.get_target())
        actor = User.from_json(json=parser.get_actor())
        device_used = get_phone_model_from_json(parser.get_actor_app())

        return cls(story_id=parser.get_story_id(),
                   payment_id=parser.get_payment_id(),
                   date_completed=date_completed,
                   date_created=date_created,
                   date_updated=date_updated,
                   payment_type=parser.get_type(),
                   audience=parser.get_audience(),
                   status=parser.get_status(),
                   note=parser.get_story_note(),
                   device_used=device_used,
                   actor=actor,
                   target=target)