Class: Microsoft::Graph::Batch
- Inherits:
-
Object
- Object
- Microsoft::Graph::Batch
- Defined in:
- lib/microsoft/graph/batch.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Instance Method Summary collapse
- #add(endpoint, id: SecureRandom.uuid, method: "GET", headers: {}, params: nil, body: nil, depends_on: nil) ⇒ Object
- #call ⇒ Object
-
#initialize(graph, token:, size: 20) ⇒ Batch
constructor
A new instance of Batch.
Constructor Details
#initialize(graph, token:, size: 20) ⇒ Batch
Returns a new instance of Batch.
8 9 10 11 12 13 |
# File 'lib/microsoft/graph/batch.rb', line 8 def initialize(graph, token:, size: 20) @graph = graph @requests = [] @token = token @size = size end |
Instance Attribute Details
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
6 7 8 |
# File 'lib/microsoft/graph/batch.rb', line 6 def requests @requests end |
Instance Method Details
#add(endpoint, id: SecureRandom.uuid, method: "GET", headers: {}, params: nil, body: nil, depends_on: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# 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 ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# 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 |