Class: Msgraph::Api::Client
- Inherits:
-
MicrosoftGraphMailer::Client
- Object
- MicrosoftGraphMailer::Client
- Msgraph::Api::Client
- Defined in:
- lib/msgraph/api/client.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(settings) ⇒ Client
constructor
A new instance of Client.
- #me ⇒ Object
- #request(verb, path_or_url, **options) ⇒ Object
- #resource_path ⇒ Object
- #url_for(path) ⇒ Object
- #user ⇒ Object
Methods inherited from MicrosoftGraphMailer::Client
Constructor Details
#initialize(settings) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/msgraph/api/client.rb', line 7 def initialize(settings) # Delivery already implements checking setting params and # applying defaults if required, so we're gonna abuse that # for our implementation. completed = MicrosoftGraphMailer::Delivery.new(settings).microsoft_graph_settings super( user_id: completed[:user_id], tenant: completed[:tenant], client_id: completed[:client_id], client_secret: completed[:client_secret], azure_ad_endpoint: completed[:azure_ad_endpoint], graph_endpoint: completed[:graph_endpoint] ) self.debug = completed[:debug] == true end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
5 6 7 |
# File 'lib/msgraph/api/client.rb', line 5 def debug @debug end |
Instance Method Details
#client ⇒ Object
27 28 29 |
# File 'lib/msgraph/api/client.rb', line 27 def client self end |
#me ⇒ Object
23 24 25 |
# File 'lib/msgraph/api/client.rb', line 23 def me Resource::User.new(self, id: user_id) end |
#request(verb, path_or_url, **options) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/msgraph/api/client.rb', line 47 def request(verb, path_or_url, **) # set content type header if it doesn't exist in options [:headers] ||= {} [:headers]["Content-Type"] ||= "application/json" # format body as json document with proper graph attribute names [:body] = [:body].to_graph_attributes.to_json unless [:body].nil? url = url_for(path_or_url) puts "#{verb.to_s.upcase} #{url} ((#{.inspect})" if self.debug rsp = api_token.send(verb, url, ) puts rsp.body if self.debug rsp end |
#resource_path ⇒ Object
35 36 37 |
# File 'lib/msgraph/api/client.rb', line 35 def resource_path "" end |
#url_for(path) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/msgraph/api/client.rb', line 39 def url_for(path) if path =~ /https?:\/\// path else graph_endpoint.join_path("v1.0", path) end end |
#user ⇒ Object
31 32 33 |
# File 'lib/msgraph/api/client.rb', line 31 def user me end |