From 206aa96ce1c4073b5c570accf1559af9c2e2e509 Mon Sep 17 00:00:00 2001 From: James Armes Date: Thu, 23 May 2024 16:57:01 -0400 Subject: [PATCH] Support requests where the body may not be JSON (such as uploading a file). --- lib/microsoft/graph.rb | 3 ++- lib/microsoft/graph/body_formatter.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/microsoft/graph.rb b/lib/microsoft/graph.rb index 0686aaf..dd2d484 100644 --- a/lib/microsoft/graph.rb +++ b/lib/microsoft/graph.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "httparty" +require "ostruct" require "securerandom" require_relative "graph/version" require_relative "graph/batch" @@ -51,7 +52,7 @@ def call(endpoint, token: @token, method: "GET", headers: {}, params: nil, body: url, headers: headers, query: params, - body: @body_formatter.call(body, method: method).to_json, + body: @body_formatter.call(body, method: method), parser: InstanceParser ) diff --git a/lib/microsoft/graph/body_formatter.rb b/lib/microsoft/graph/body_formatter.rb index 9b8f59d..b6668a3 100644 --- a/lib/microsoft/graph/body_formatter.rb +++ b/lib/microsoft/graph/body_formatter.rb @@ -6,8 +6,9 @@ class BodyFormatter def call(body, method:) return nil unless Microsoft::Graph::BODY_METHODS.include?(method) return nil unless body + return body unless body.is_a?(Hash) - body.transform_keys(&method(:camelize)) + body.transform_keys(&method(:camelize)).to_json end private