Class: Microsoft::Graph::Batch::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/microsoft/graph/batch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, id:, method:, headers:, params:, body:, depends_on:) ⇒ Request

Returns a new instance of Request.



51
52
53
54
55
56
57
58
59
60
# File 'lib/microsoft/graph/batch.rb', line 51

def initialize(endpoint, id:, method:, headers:, params:, body:, depends_on:)
  @id = id
  @endpoint = "#{self.class.parser.escape(endpoint)}#{params ? "?#{params.to_query}" : ""}"
  @method = method.upcase
  @headers = headers
  @headers[:Accept] = "application/json" if body
  @headers[:"Content-Type"] = "application/json" if body
  @body = body
  @depends_on = depends_on
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



48
49
50
# File 'lib/microsoft/graph/batch.rb', line 48

def body
  @body
end

#depends_onObject

Returns the value of attribute depends_on.



49
50
51
# File 'lib/microsoft/graph/batch.rb', line 49

def depends_on
  @depends_on
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



48
49
50
# File 'lib/microsoft/graph/batch.rb', line 48

def endpoint
  @endpoint
end

#headersObject (readonly)

Returns the value of attribute headers.



48
49
50
# File 'lib/microsoft/graph/batch.rb', line 48

def headers
  @headers
end

#idObject (readonly)

Returns the value of attribute id.



48
49
50
# File 'lib/microsoft/graph/batch.rb', line 48

def id
  @id
end

#methodObject (readonly)

Returns the value of attribute method.



48
49
50
# File 'lib/microsoft/graph/batch.rb', line 48

def method
  @method
end

Class Method Details

.body_formatterObject



44
45
46
# File 'lib/microsoft/graph/batch.rb', line 44

def self.body_formatter
  @body_formatter ||= Microsoft::Graph::BodyFormatter.new
end

.parserObject



40
41
42
# File 'lib/microsoft/graph/batch.rb', line 40

def self.parser
  @parser ||= URI::Parser.new
end

Instance Method Details

#to_hObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/microsoft/graph/batch.rb', line 62

def to_h
  hash = {
    id: @id,
    url: @endpoint,
    method: @method
  }
  hash[:headers] = @headers unless @headers.empty?
  hash[:body] = self.class.body_formatter.call(@body, method: @method) if @body
  hash[:dependsOn] = [@depends_on] if @depends_on

  hash
end