Class: MSGraph::Client
- Inherits:
-
Object
- Object
- MSGraph::Client
- Defined in:
- lib/msgraph/client.rb,
lib/msgraph/client/version.rb
Overview
Simple client for Microsoft Graph.
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Attribute Summary collapse
-
#symbolize_names ⇒ Boolean
Whether hash keys of API responses are symbolized.
Instance Method Summary collapse
-
#initialize(symbolize_names: true) ⇒ Client
constructor
Create a new client object.
-
#request(command, path, token, data = nil, header = nil) ⇒ Object
Calls an API and returns the parsed response.
Constructor Details
#initialize(symbolize_names: true) ⇒ Client
Create a new client object.
18 19 20 |
# File 'lib/msgraph/client.rb', line 18 def initialize(symbolize_names: true) @symbolize_names = symbolize_names end |
Instance Attribute Details
#symbolize_names ⇒ Boolean
Returns whether hash keys of API responses are symbolized.
23 24 25 |
# File 'lib/msgraph/client.rb', line 23 def symbolize_names @symbolize_names end |
Instance Method Details
#request(command, path, token, data = nil, header = nil) ⇒ Object
Calls an API and returns the parsed response.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/msgraph/client.rb', line 34 def request(command, path, token, data = nil, header = nil) req = Net::HTTPGenericRequest.new( command.to_s.upcase, !data.nil?, true, url(path), header ) res = http_request(req, token, data) raise Error, res unless res.is_a? Net::HTTPSuccess raise Error, res unless res.content_type&.start_with? 'application/json' JSON.parse(res.body, symbolize_names: @symbolize_names) end |