Skip to content

Commit

Permalink
fix(events): ms is now validating $top= properly
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Oct 25, 2023
1 parent 01c895b commit efbf4e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: office365
version: 1.23.0
version: 1.23.1

crystal: ">= 0.36.1"

Expand Down
24 changes: 18 additions & 6 deletions src/events.cr
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ 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? = 999,
filter : String? = nil
)
end_period = period_end || period_start + 6.months
Expand All @@ -251,12 +251,24 @@ module Office365::Events
raise "unknown endpoint"
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
query = String.build do |str|
str << "startDateTime="
str << period_start.to_utc.to_s("%FT%T-00:00")
str << "&endDateTime="
str << end_period.not_nil!.to_utc.to_s("%FT%T-00:00")
if filter.presence
str << "&"
str << URI::Params.parse("$filter=#{filter}")
elsif ical_uid.presence
str << "&"
str << URI::Params.parse("$filter=iCalUId eq '#{ical_uid}'")
end
if top
str << "&$top="
str << top
end
end

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?
{endpoint, URI::Params.parse(query)}
end
end
2 changes: 1 addition & 1 deletion src/models/attachment.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Office365
@odata_type = "#microsoft.graph.fileAttachment"
buffer = IO::Memory.new
buf = Bytes.new(64)
while ((bytes = content_bytes.read(buf)) > 0)
while (bytes = content_bytes.read(buf)) > 0
buffer.write(buf[0, bytes])
end
@content_bytes = Base64.strict_encode(buffer)
Expand Down

0 comments on commit efbf4e5

Please sign in to comment.