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 )
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)
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)
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)
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)
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)