lib/timetree/models/calendar.rb in timetree-0.3.2 vs lib/timetree/models/calendar.rb in timetree-1.0.0
- old
+ new
@@ -30,11 +30,11 @@
# @raise [TimeTree::Error] if @client, @id or the event_id arg is empty.
# @raise [TimeTree::ApiError] if the http response status will not success.
# @since 0.0.1
def event(event_id)
check_client
- @client.event id, event_id
+ get_event(event_id)
end
#
# Get the events' information after a request date.
#
@@ -46,11 +46,11 @@
# @raise [TimeTree::Error] if @client or @id is empty.
# @raise [TimeTree::ApiError] if the http response status will not success.
# @since 0.0.1
def upcoming_events(days: 7, timezone: 'UTC')
check_client
- @client.upcoming_events id, days: days, timezone: timezone
+ get_upcoming_event(days, timezone)
end
#
# Get a calendar's member information.
#
@@ -60,11 +60,11 @@
# @since 0.0.1
def members
return @members if defined? @members
check_client
- @members = @client.calendar_members id
+ @members = get_members
end
#
# Get a calendar's label information used in event.
#
@@ -74,9 +74,43 @@
# @since 0.0.1
def labels
return @labels if defined? @labels
check_client
- @labels = @client.calendar_labels id
+ @labels = get_labels
+ end
+
+ private
+
+ def get_event(event_id)
+ if @client.is_a?(CalendarApp::Client)
+ @client.event(event_id)
+ else
+ @client.event(id, event_id)
+ end
+ end
+
+ def get_upcoming_event(days, timezone)
+ if @client.is_a?(CalendarApp::Client)
+ @client.upcoming_events(days: days, timezone: timezone)
+ else
+ @client.upcoming_events(id, days: days, timezone: timezone)
+ end
+ end
+
+ def get_members
+ if @client.is_a?(CalendarApp::Client)
+ @client.calendar_members
+ else
+ @client.calendar_members(id)
+ end
+ end
+
+ def get_labels
+ if @client.is_a?(CalendarApp::Client)
+ raise Error.new 'CalendarApp does not support label api'
+ else
+ @client.calendar_labels(id)
+ end
end
end
end