Skip to content

Commit

Permalink
Support TicketIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
geuben committed Jun 17, 2020
1 parent 4ce6518 commit b73890b
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 3 deletions.
2 changes: 2 additions & 0 deletions livestyled/client.py
Expand Up @@ -115,6 +115,8 @@ def _api_post(
},
data=json.dumps(data)
)
if response.status_code >= 400:
print(response.json())
response.raise_for_status()
return response.json()

Expand Down
2 changes: 2 additions & 0 deletions livestyled/models/__init__.py
Expand Up @@ -31,6 +31,7 @@
from livestyled.models.sport_venue import SportVenue
from livestyled.models.team import Team
from livestyled.models.ticket import Ticket
from livestyled.models.ticket_integration import TicketIntegration
from livestyled.models.user import User, UserInfo, UserSSO

__all__ = [
Expand Down Expand Up @@ -65,6 +66,7 @@
SportVenue,
Team,
Ticket,
TicketIntegration,
UserInfo,
User,
UserSSO
Expand Down
18 changes: 17 additions & 1 deletion livestyled/models/ticket.py
@@ -1,3 +1,4 @@
from livestyled.models.ticket_integration import TicketIntegration
from livestyled.models.user import User


Expand Down Expand Up @@ -42,6 +43,7 @@ def __init__(
legal_short_text=None,
map_url=None,
map_image_url=None,
ticket_integration=None
):
self.id = id
self.external_ticket_id = external_ticket_id
Expand Down Expand Up @@ -96,6 +98,13 @@ def __init__(
self.legal_short_text = legal_short_text
self.map_url = map_url
self.map_image_url = map_image_url
if ticket_integration:
if isinstance(ticket_integration, dict):
self._ticket_integration = TicketIntegration(**ticket_integration)
elif isinstance(ticket_integration, (int, str)):
self._ticket_integration = TicketIntegration.placeholder(ticket_integration)
else:
self._ticket_integration = None

@classmethod
def placeholder(
Expand Down Expand Up @@ -141,6 +150,7 @@ def placeholder(
legal_short_text=None,
map_url=None,
map_image_url=None,
ticket_integration=None
)

@classmethod
Expand Down Expand Up @@ -181,6 +191,7 @@ def create_new(
legal_short_text=None,
map_url=None,
map_image_url=None,
ticket_integration=None
):
ticket = Ticket(
id=None,
Expand Down Expand Up @@ -221,6 +232,7 @@ def create_new(
legal_short_text=legal_short_text,
map_url=map_url,
map_image_url=map_image_url,
ticket_integration=ticket_integration
)
if isinstance(user, (str, int)):
user = User.placeholder(id=user)
Expand Down Expand Up @@ -273,6 +285,10 @@ def sharer(self):
def parent_ticket(self):
return self._parent_ticket

@property
def ticket_integration(self):
return self._ticket_integration

def __repr__(self):
return '<Ticket(id={self.id!r})>'.format(self=self)

Expand All @@ -283,7 +299,7 @@ def diff(self, other):
'barcode', 'sector_name', 'venue_name', 'venue_room', 'client_name', 'premium', 'client_email',
'price', 'status', 'can_share', 'sharer_email', 'redeemed_at', 'redeemer_id', 'share_code',
'redeemer_email', 'parent_ticket', 'shared_at', 'legal_long_text', 'legal_short_text', 'map_url',
'map_image_url'
'map_image_url', 'ticket_integration'
)
for field in fields:
if getattr(self, field) != getattr(other, field):
Expand Down
88 changes: 88 additions & 0 deletions livestyled/models/ticket_integration.py
@@ -0,0 +1,88 @@
class TicketIntegration:
def __init__(
self,
id,
label,
name,
adapter,
config_payload,
endpoint_url,
auth_required,
module,
login_request,
default,
can_share
):
self.id = id
self.label = label
self.name = name
self.adapter = adapter
self.config_payload = config_payload
self.endpoint_url = endpoint_url
self.auth_required = auth_required
self.module = module
self.login_request = login_request
self.default = default
self.can_share = can_share

@classmethod
def placeholder(
cls,
id
):
return cls(
id=id,
label=None,
name=None,
adapter=None,
config_payload=None,
endpoint_url=None,
auth_required=None,
module=None,
login_request=None,
default=None,
can_share=None
)

@classmethod
def create_new(
cls,
endpoint_url,
login_request,
adapter,
label=None,
name=None,
config_payload=None,
auth_required=None,
module=None,
default=None,
can_share=None
):
ticket_integration = TicketIntegration(
id=None,
label=label,
name=name,
adapter=adapter,
config_payload=config_payload,
endpoint_url=endpoint_url,
auth_required=auth_required,
module=module,
login_request=login_request,
default=default,
can_share=can_share
)
return ticket_integration

def __repr__(self):
return '<TicketIntegration(id={self.id!r})>'.format(self=self)

def diff(self, other):
differences = {}
fields = (
'label', 'name', 'endpoint_url', 'adapter', 'config_payload',
'auth_required', 'module', 'login_request', 'default', 'can_share'
)
for field in fields:
if getattr(self, field) != getattr(other, field):
differences[field] = getattr(self, field)
return differences
21 changes: 21 additions & 0 deletions livestyled/resource_client.py
Expand Up @@ -27,6 +27,7 @@
SportVenue,
Team,
Ticket,
TicketIntegration,
User,
UserInfo,
UserSSO,
Expand All @@ -52,6 +53,7 @@
SeasonSchema,
SportVenueSchema,
TeamSchema,
TicketIntegrationSchema,
TicketSchema,
UserCreateSchema,
UserInfoSchema,
Expand Down Expand Up @@ -811,3 +813,22 @@ def get_product_categories(
self,
) -> Generator[ProductCategory, None, None]:
return self._get_resource_list(ProductCategorySchema)

# ---- TICKET INTEGRATIONS

def get_ticket_integrations(
self,
) -> Generator[TicketIntegration, None, None]:
return self._get_resource_list(TicketIntegrationSchema)

def get_ticket_integration(
self,
id
) -> TicketIntegration:
return self._get_resource_by_id(TicketIntegrationSchema, id)

def create_ticket_integration(
self,
ticket_integration: TicketIntegration
) -> TicketIntegration:
return self._create_resource(TicketIntegrationSchema, ticket_integration)
2 changes: 2 additions & 0 deletions livestyled/schemas/__init__.py
Expand Up @@ -22,6 +22,7 @@
from livestyled.schemas.sport_venue import SportVenueSchema
from livestyled.schemas.team import TeamSchema
from livestyled.schemas.ticket import TicketSchema
from livestyled.schemas.ticket_integration import TicketIntegrationSchema
from livestyled.schemas.user import UserCreateSchema, UserInfoSchema, UserSchema, UserSSOSchema

__all__ = [
Expand Down Expand Up @@ -50,6 +51,7 @@
SeasonSchema,
SportVenueSchema,
TeamSchema,
TicketIntegrationSchema,
TicketSchema,
UserCreateSchema,
UserInfoSchema,
Expand Down
20 changes: 19 additions & 1 deletion livestyled/schemas/tests/fixtures/example_ticket.json
Expand Up @@ -19,5 +19,23 @@
"canShare": true,
"status": "active",
"legalLongText": "this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text this is the legal long text",
"legalShortText": "More information or questions regarding the ADA ticket"
"legalShortText": "More information or questions regarding the ADA ticket",
"ticketIntegration": {
"@context": "/v4/contexts/TicketIntegration",
"@id": "/v4/ticket_integrations/17",
"@type": "TicketIntegration",
"id": 17,
"endpointUrl": "XXXXXXsd",
"label": "XXXXXXdsds",
"name": "SeatGeek",
"loginRequest": "XXXXXXXdsds",
"adapter": "XXXXXXds",
"default": false,
"createdAt": "2018-07-19T15:10:00+00:00",
"updatedAt": "2020-01-27T14:57:57+00:00",
"module": "SHARE",
"authRequired": false,
"canShare": false,
"app": "/v4/apps/27"
}
}
18 changes: 18 additions & 0 deletions livestyled/schemas/tests/fixtures/example_ticket_integration.json
@@ -0,0 +1,18 @@
{
"@context": "/v4/contexts/TicketIntegration",
"@id": "/v4/ticket_integrations/17",
"@type": "TicketIntegration",
"id": 17,
"endpointUrl": "XXXXXXsd",
"label": "XXXXXXdsds",
"name": "SeatGeek",
"loginRequest": "XXXXXXXdsds",
"adapter": "XXXXXXds",
"default": false,
"createdAt": "2018-07-19T15:10:00+00:00",
"updatedAt": "2020-01-27T14:57:57+00:00",
"module": "SHARE",
"authRequired": false,
"canShare": false,
"app": "/v4/apps/27"
}
15 changes: 15 additions & 0 deletions livestyled/schemas/tests/test_ticket.py
Expand Up @@ -57,6 +57,19 @@ def test_deserialize_ticket():
'legal_short_text': 'More information or questions regarding the ADA ticket',
'map_url': None,
'map_image_url': None,
'ticket_integration': {
'adapter': 'XXXXXXds',
'auth_required': False,
'can_share': False,
'config_payload': None,
'default': False,
'endpoint_url': 'XXXXXXsd',
'id': 17,
'label': 'XXXXXXdsds',
'login_request': 'XXXXXXXdsds',
'module': 'SHARE',
'name': 'SeatGeek'
},
}


Expand Down Expand Up @@ -103,6 +116,7 @@ def test_deserialize_ticket_shared():
'legal_short_text': None,
'map_url': None,
'map_image_url': None,
'ticket_integration': None
}


Expand Down Expand Up @@ -149,4 +163,5 @@ def test_deserialize_ticket_shared_redeemed():
'legal_short_text': None,
'map_url': None,
'map_image_url': None,
'ticket_integration': None
}
26 changes: 26 additions & 0 deletions livestyled/schemas/tests/test_ticket_integration.py
@@ -0,0 +1,26 @@
import os

from livestyled.schemas.ticket_integration import TicketIntegrationSchema


FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'fixtures')
TEST_API_DOMAIN = 'test.livestyled.com'


def test_deserialize_ticket_integration():
with open(os.path.join(FIXTURES_DIR, 'example_ticket_integration.json'), 'r') as fixture_file:
ticket_integration = fixture_file.read()
deserialized_ticket_integration = TicketIntegrationSchema().loads(ticket_integration)
assert deserialized_ticket_integration == {
'adapter': 'XXXXXXds',
'auth_required': False,
'can_share': False,
'config_payload': None,
'endpoint_url': 'XXXXXXsd',
'id': 17,
'default': False,
'label': 'XXXXXXdsds',
'login_request': 'XXXXXXXdsds',
'module': 'SHARE',
'name': 'SeatGeek',
}
4 changes: 3 additions & 1 deletion livestyled/schemas/ticket.py
Expand Up @@ -2,7 +2,8 @@
from marshmallow_polyfield import PolyField

from livestyled.models.ticket import Ticket
from livestyled.schemas.fields import RelatedResourceLinkField
from livestyled.schemas.fields import RelatedResourceField, RelatedResourceLinkField
from livestyled.schemas.ticket_integration import TicketIntegrationSchema
from livestyled.schemas.user import UserSchema


Expand Down Expand Up @@ -64,3 +65,4 @@ class Meta:
legal_long_text = fields.String(data_key='legalLongText', required=False, allow_none=True, missing=None)
map_url = fields.String(data_key='mapUrl', required=False, allow_none=True, missing=None)
map_image_url = fields.String(data_key='mapImageUrl', required=False, allow_none=True, missing=None)
ticket_integration = RelatedResourceField(schema=TicketIntegrationSchema, required=False, missing=None, data_key='ticketIntegration')
23 changes: 23 additions & 0 deletions livestyled/schemas/ticket_integration.py
@@ -0,0 +1,23 @@
from marshmallow import EXCLUDE, fields, Schema

from livestyled.models.ticket_integration import TicketIntegration


class TicketIntegrationSchema(Schema):
class Meta:
unknown = EXCLUDE
api_type = 'ticket_integrations'
url = 'v4/ticket_integrations'
model = TicketIntegration

id = fields.Int()
label = fields.String(required=False, missing=None)
name = fields.String(required=False, missing=None)
adapter = fields.String(required=False, missing=None)
endpoint_url = fields.String(required=False, missing=None, data_key='endpointUrl')
config_payload = fields.String(required=False, missing=None, data_key='configPayload')
auth_required = fields.Boolean(required=False, missing=None, data_key='authRequired')
module = fields.String(required=False, missing=None)
login_request = fields.String(required=False, missing=None, data_key='loginRequest')
default = fields.Boolean(required=False, missing=None, data_key='default')
can_share = fields.Boolean(required=False, missing=None, data_key='canShare')

0 comments on commit b73890b

Please sign in to comment.