class Microsoft::Graph::Batch
Attributes
requests[R]
Public Class Methods
new(graph, token:, size: 20)
click to toggle source
# File lib/microsoft/graph/batch.rb, line 8 def initialize(graph, token:, size: 20) @graph = graph @requests = [] @token = token @size = size end
Public Instance Methods
add(endpoint, id: SecureRandom.uuid, method: "GET", headers: {}, params: nil, body: nil, depends_on: nil)
click to toggle source
# File lib/microsoft/graph/batch.rb, line 15 def add(endpoint, id: SecureRandom.uuid, method: "GET", headers: {}, params: nil, body: nil, depends_on: nil) @requests << Request.new( endpoint, id: id, method: method, headers: headers, params: params, body: body, depends_on: depends_on ) end
call()
click to toggle source
# File lib/microsoft/graph/batch.rb, line 27 def call @requests.each_slice(@size).flat_map do |group| requests_by_id = group.group_by(&:id).transform_values(&:first) group.first.depends_on = nil response = @graph.call("/$batch", method: "POST", token: @token, body: { requests: group.map(&:to_h) }) response.responses.map do |current| Result.new(request: requests_by_id[current.id], response: current) end end end