Module: Legion::Extensions::MicrosoftTeams::Helpers::GraphClient

Defined in:
lib/legion/extensions/microsoft_teams/helpers/graph_client.rb

Defined Under Namespace

Classes: GraphError

Instance Method Summary collapse

Instance Method Details

#graph_get(path, token:, params: {}) ⇒ Object



10
11
12
13
14
# File 'lib/legion/extensions/microsoft_teams/helpers/graph_client.rb', line 10

def graph_get(path, token:, params: {})
  connection = graph_connection(token: token)
  response   = connection.get(path, params)
  handle_graph_response(response, path)
end

#graph_paginate(path, token:, params: {}, max_pages: 10) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/legion/extensions/microsoft_teams/helpers/graph_client.rb', line 16

def graph_paginate(path, token:, params: {}, max_pages: 10)
  results   = []
  next_link = nil
  page      = 0

  loop do
    current_path = next_link || path
    data         = graph_get(current_path, token: token, params: page.zero? ? params : {})
    break if data.nil?

    items = data['value'] || data[:value]
    results.concat(Array(items)) if items

    next_link = data['@odata.nextLink'] || data[:'@odata.nextLink']
    page     += 1
    break if next_link.nil? || page >= max_pages
  end

  results
end

#graph_post(path, token:, body: {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/legion/extensions/microsoft_teams/helpers/graph_client.rb', line 37

def graph_post(path, token:, body: {})
  connection = graph_connection(token: token)
  response   = connection.post(path) do |req|
    req.body = body
  end
  handle_graph_response(response, path)
end