Skip to content

Commit

Permalink
feat(events): [PPT-316] custom filter (#37)
Browse files Browse the repository at this point in the history
* feat(events): custom filter

* test(mock): update webmock urls
  • Loading branch information
chillfox authored Sep 11, 2023
1 parent f05d65c commit 7ba135c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ module SpecHelper
end

def mock_list_events
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users/foo%40bar.com/calendar/calendarView?startDateTime=2020-01-01T00:00:00-00:00&endDateTime=2020-06-01T00:00:00-00:00&$top=10000").to_return(mock_event_query_json)
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users/foo%40bar.com/calendar/calendarView?startDateTime=2020-01-01T00%3A00%3A00-00%3A00&endDateTime=2020-06-01T00%3A00%3A00-00%3A00").to_return(mock_event_query_json)
end

def mock_list_events_error
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users/bar%40foo.com/calendar/calendarView?startDateTime=2020-01-01T00:00:00-00:00&endDateTime=2020-06-01T00:00:00-00:00&$top=10000")
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users/bar%40foo.com/calendar/calendarView?startDateTime=2020-01-01T00%3A00%3A00-00%3A00&endDateTime=2020-06-01T00%3A00%3A00-00%3A00")
.to_return(mock_event_query_json_error)
end

Expand Down
10 changes: 7 additions & 3 deletions src/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ module Office365::Events
calendar_id : String? = nil,
period_start : Time = Time.local.at_beginning_of_day,
period_end : Time? = nil,
ical_uid : String? = nil
ical_uid : String? = nil,
filter : String? = nil
)
path, params = calendar_view_path(mailbox, calendar_group_id, calendar_id, period_start, period_end, ical_uid)
path, params = calendar_view_path(mailbox, calendar_group_id, calendar_id, period_start, period_end, ical_uid, filter)

graph_http_request(request_method: "GET", path: path, query: params)
end
Expand Down Expand Up @@ -226,7 +227,8 @@ module Office365::Events
period_start : Time = Time.local.at_beginning_of_day,
period_end : Time? = nil,
ical_uid : String? = nil,
top : Int32? = 10000
top : Int32? = 10000,
filter : String? = nil
)
end_period = period_end || period_start + 6.months

Expand All @@ -250,6 +252,8 @@ module Office365::Events
end

ical_filter = URI::Params.parse(ical_uid.presence ? "$filter=iCalUId eq '#{ical_uid}'" : "").to_s
ical_filter = URI::Params.parse("$filter=#{filter}").to_s if filter.presence

ical_filter = "&#{ical_filter}" unless ical_filter.empty?
query = "startDateTime=#{period_start.to_utc.to_s("%FT%T-00:00")}&endDateTime=#{end_period.not_nil!.to_utc.to_s("%FT%T-00:00")}#{ical_filter}"
query += "&$top=#{top}" unless top.nil?
Expand Down

0 comments on commit 7ba135c

Please sign in to comment.