Commit ac8b3a06 authored by Ryan Gosse's avatar Ryan Gosse

Added calendar queries

parent 2f171ced
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
import json
try:
from urllib.parse import urlencode
except ImportError:
......@@ -119,6 +121,12 @@ class Item(Area):
def values_v2(self, item_id):
return self.transport.GET(url='/item/%s/value/v2' % item_id)
def field_values(self, item_id, field_id):
return self.transport.GET(url='/item/%s/value/%s' % (item_id, field_id))
def field_values_v2(self, item_id, field_id):
return self.transport.GET(url='/item/%s/value/%s/v2' % (item_id, field_id))
def create(self, app_id, attributes, silent=False, hook=True):
if not isinstance(attributes, dict):
raise TypeError('Must be of type dict')
......@@ -621,3 +629,39 @@ class View(Area):
return self.transport.PUT(url='/view/{}'.format(view_id),
body=attribute_data, type='application/json')
class Calendar(Area):
def get_app_calendar(self, app_id, start_time=datetime.now(), end_time=datetime.now() - timedelta(days=7)):
"""Get the app's calendar from between the start_time and end_time
Arguments:
app_id {int} -- The id of the app whose calendar is being queried
Keyword Arguments:
start_time {datetime} -- The beginning date (default: {datetime.now()})
end_time {datetime} -- The ending date (default: {datetime.now()-timedelta(days=7)})
Returns:
list -- List of calendar items from between the 2 given dates
"""
dates = {
'date_from': start_time.strftime('%Y-%m-%d'),
'date_to': end_time.strftime('%Y-%m-%d')
}
return self.transport.GET(url='/calendar/app/{}'.format(app_id), **dates)
def get_global_calendar(self, start_time=datetime.now(), end_time=datetime.now() - timedelta(days=7)):
"""Get the global calendar from between the start_time and end_time
Keyword Arguments:
start_time {datetime} -- The beginning date (default: {datetime.now()})
end_time {datetime} -- The ending date (default: {datetime.now()-timedelta(days=7)})
Returns:
list -- List of calendar items from between the 2 given dates
"""
dates = {
'date_from': start_time.strftime('%Y-%m-%d'),
'date_to': end_time.strftime('%Y-%m-%d')
}
return self.transport.GET(url='/calendar', **dates)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment