Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/microsoft/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Graph
BODY_METHODS = %w[POST PUT PATCH].freeze
ALLOWED_METHODS = [*BODY_METHODS, "GET", "DELETE"].freeze

def initialize(token: nil, error_handler: method(:error_handler), version: "1.0")
attr_reader :last_response

def initialize(token: nil, error_handler: method(:error_handler), version: "v1.0")
@token = token
@parser = URI::Parser.new
@body_formatter = Microsoft::Graph::BodyFormatter.new
Expand All @@ -39,7 +41,7 @@ def call(endpoint, token: @token, method: "GET", headers: {}, params: nil, body:
method = method.upcase
raise ArgumentError, "`#{method}` is not a valid HTTP method." unless ALLOWED_METHODS.include?(method)

url = URI.join(GRAPH_HOST, @parser.escape("v#{@version}/#{endpoint.gsub(%r{^/}, "")}"))
url = URI.join(GRAPH_HOST, @parser.escape("#{@version}/#{endpoint.gsub(%r{^/}, "")}"))
headers = headers.merge(
Authorization: "Bearer #{token}",
Accept: "application/json"
Expand All @@ -54,6 +56,7 @@ def call(endpoint, token: @token, method: "GET", headers: {}, params: nil, body:
body: @body_formatter.call(body, method: method).to_json,
parser: InstanceParser
)
@last_response = response

case response.code
when 200...400
Expand Down