Skip to content

Commit

Permalink
LSN-2598 Added bookings and device_preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
schoolboytom committed Apr 9, 2020
1 parent 5fc6892 commit 08e87d2
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
4 changes: 4 additions & 0 deletions livestyled/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from livestyled.models.booking import Booking
from livestyled.models.cohort import Cohort
from livestyled.models.competition import Competition
from livestyled.models.device import Device
from livestyled.models.device_preference import DevicePreference
from livestyled.models.event import Event
from livestyled.models.fixture import Fixture
from livestyled.models.league_table import LeagueTable, LeagueTableGroup
Expand All @@ -15,9 +17,11 @@
from livestyled.models.user import User, UserInfo, UserSSO

__all__ = [
Booking,
Cohort,
Competition,
Device,
DevicePreference,
Event,
Fixture,
LeagueTable,
Expand Down
45 changes: 45 additions & 0 deletions livestyled/models/booking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class Booking:
def __init__(
self,
id,
type,
device,
user,
event,
created_at,
updated_at,
action,
):
self._id = id
self.type = type
self.device = device
self.user = user
self.event = event
self.created_at = created_at
self.created_at = updated_at
self.action = action

@classmethod
def create_new(
cls,
type: str,
device: str,
user: str or None,
event:str,
created_at: str,
updated_at: str,
action: str,
):
return Booking(
id=None,
type=type,
device=device,
user=user,
event=event,
created_at=created_at,
updated_at=updated_at,
action=action,
)

def __repr__(self):
return '<Booking(id={self.id!r}, type={self.type!r}, action={self.action!r})>'.format(self=self)
34 changes: 34 additions & 0 deletions livestyled/models/device_preference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class DevicePreference:
def __init__(
self,
id,
created_at,
device,
venue,
event,
):
self._id = id
self.created_at = created_at
self.device = device
self.venue = venue
self.event = event

@classmethod
def create_new(
cls,
created_at: str,
device: str,
venue: str or None,
event: str or None,
):
return DevicePreference(
id=None,
device=device,
venue=venue,
event=event,
created_at=created_at,
)

def __repr__(self):
return '<DevicePreference(id={self.id!r}, device={self.device!r}, venue={self.venue!r}, event={self.event!r})>'\
.format(self=self)
42 changes: 42 additions & 0 deletions livestyled/resource_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

from livestyled.client import LiveStyledAPIClient
from livestyled.models import (
Booking,
Cohort,
Competition,
DevicePreference,
Event,
Fixture,
LeagueTable,
Expand All @@ -24,8 +26,10 @@
UserSSO
)
from livestyled.schemas import (
BookingSchema,
CohortSchema,
CompetitionSchema,
DevicePreferenceSchema,
EventSchema,
FixtureSchema,
LeagueTableGroupSchema,
Expand Down Expand Up @@ -607,3 +611,41 @@ def get_events(
return self._get_resource_list(EventSchema, filters={'title': title})
else:
return self._get_resource_list(EventSchema)

# ---- BOOKINGS

def get_bookings(
self,
device: str or None = None,
event: str or None = None,
action: str or None = None,
) -> Generator[Booking, None, None]:
if device and event and action:
return self._get_resource_list(BookingSchema, filters={'device': device, 'event': event, 'action': action})
else:
return self._get_resource_list(BookingSchema)

def create_booking(
self,
booking: BookingSchema
) -> Booking:
return self._create_resource(BookingSchema, booking)

# ---- DEVICE PREFERENCES

def get_device_preferences(
self,
device: str or None = None,
event: str or None = None,
) -> Generator[Booking, None, None]:
if device and event:
return self._get_resource_list(DevicePreferenceSchema,
filters={'device': device, 'event': event})
else:
return self._get_resource_list(DevicePreferenceSchema)

def create_device_preference(
self,
booking: DevicePreferenceSchema
) -> Booking:
return self._create_resource(DevicePreferenceSchema, booking)
4 changes: 4 additions & 0 deletions livestyled/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from livestyled.schemas.app import AppSchema
from livestyled.schemas.booking import BookingSchema
from livestyled.schemas.cohort import CohortSchema
from livestyled.schemas.competition import CompetitionSchema
from livestyled.schemas.device import DeviceSchema
from livestyled.schemas.device_preference import DevicePreferenceSchema
from livestyled.schemas.device_consent import DeviceConsentSchema
from livestyled.schemas.device_token import DeviceTokenSchema
from livestyled.schemas.event import EventSchema
Expand All @@ -22,9 +24,11 @@

__all__ = [
AppSchema,
BookingSchema,
CohortSchema,
CompetitionSchema,
DeviceSchema,
DevicePreferenceSchema,
DeviceConsentSchema,
DeviceTokenSchema,
EventSchema,
Expand Down
20 changes: 20 additions & 0 deletions livestyled/schemas/booking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from marshmallow import EXCLUDE, fields, Schema

from livestyled.models.booking import Booking


class BookingSchema(Schema):
class Meta:
unknown = EXCLUDE
model = Booking
api_type = 'bookings'
url = 'v4/bookings'

id = fields.Int()
title = fields.String()
device = fields.String()
user = fields.String()
event = fields.String()
created_at = fields.String()
updated_at = fields.String()
action = fields.String()
17 changes: 17 additions & 0 deletions livestyled/schemas/device_preference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from marshmallow import EXCLUDE, fields, Schema

from livestyled.models.device_preference import DevicePreference


class DevicePreferenceSchema(Schema):
class Meta:
unknown = EXCLUDE
model = DevicePreference
api_type = 'device_preferences'
url = 'v4/device_preferences'

id = fields.Int()
created_at = fields.String()
device = fields.String()
venue = fields.String()
event = fields.String()
2 changes: 2 additions & 0 deletions livestyled/schemas/event.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from marshmallow import EXCLUDE, fields, Schema

from livestyled.models import Event
from livestyled.schemas.utils import get_id_from_url


Expand All @@ -8,6 +9,7 @@ class Meta:
unknown = EXCLUDE
api_type = 'events'
url = 'v4/events'
model = Event

id = fields.Int()
status = fields.String()
Expand Down

0 comments on commit 08e87d2

Please sign in to comment.