Coder Social home page Coder Social logo

microsoftgraph / msgraph-sdk-ruby Goto Github PK

View Code? Open in Web Editor NEW
98.0 34.0 68.0 41.36 MB

Microsoft Graph Ruby client library for v1 APIs

Home Page: https://graph.microsoft.com

License: MIT License

Ruby 100.00% PowerShell 0.01%
microsoftgraph ruby devxeng

msgraph-sdk-ruby's Introduction

Microsoft Graph SDK for Ruby

If you're using a version lower than 0.10.0 of this gem, please read this post for more information.

Get started with the Microsoft Graph SDK for Ruby by integrating the Microsoft Graph API into your Ruby application!

Note: this SDK allows you to build applications using the v1.0 of Microsoft Graph. If you want to try the latest Microsoft Graph APIs under beta, use our beta SDK instead.

Note: the Microsoft Graph Ruby SDK is currently in Community Preview. During this period we're expecting breaking changes to happen to the SDK based on community's feedback. Checkout the known limitations.

1. Installation

run gem install microsoft_graph or include gem microsoft_graph in your gemfile.

2. Getting started

2.1 Register your application

Register your application by following the steps at Register your app with the Microsoft Identity Platform.

2.2 Create an AuthenticationProvider object

An instance of the MicrosoftGraphServiceClient class handles building client. To create a new instance of this class, you need to provide an instance of AuthenticationProvider, which can authenticate requests to Microsoft Graph.

For an example of how to get an authentication provider, see choose a Microsoft Graph authentication provider.

Note: we are working to add the getting started information for Ruby to our public documentation, in the meantime the following sample should help you getting started.

require "microsoft_kiota_authentication_oauth"
require "microsoft_graph_core"

context = MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new("<the tenant id from your app registration>", "<the client id from your app registration>", "<the client secret from your app registration>")

authentication_provider = MicrosoftGraphCore::Authentication::OAuthAuthenticationProvider.new(context, nil, ["https://graph.microsoft.com/.default"])

2.3 Get a Graph Service Client and Adapter object

You must get a MicrosoftGraphServiceClient object to make requests against the service.

require "microsoft_graph"

adapter = MicrosoftGraph::GraphRequestAdapter.new(authentication_provider)
client = MicrosoftGraph::GraphServiceClient.new(adapter)

3. Make requests against the service

After you have a MicrosoftGraphServiceClient that is authenticated, you can begin making calls against the service. The requests against the service look like our REST API.

3.1 Get the user's drive

To retrieve the user's drive:

result = client.users_by_id('<user-id>').get.resume
puts "Found User : " + result.id

4. Getting results that span across multiple pages

Automatic paging is currently not supported with the Ruby SDK, we're working to enable this feature.

5. Documentation

For more detailed documentation, see:

6. Issues

For known issues, see issues.

7. Contributions

The Microsoft Graph SDK is open for contribution. To contribute to this project, see Contributing.

8. License

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.

9. Third-party notices

Third-party notices

msgraph-sdk-ruby's People

Contributors

andrewjmay avatar andrueastman avatar arseny-emchik avatar baywet avatar beth-panx avatar darrelmiller avatar dependabot[bot] avatar ethanfann avatar francescm avatar fuse avatar github-actions[bot] avatar junichiito avatar mattgeim avatar michaelmainer avatar ndiritu avatar neall avatar noah-stahl avatar nokafor avatar oskarklintrot avatar phedinkus avatar quatermain avatar srtippan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

msgraph-sdk-ruby's Issues

how to update the contacts using graph?

  token = get_access_token
  email = session[:user_email]
  if token
    # If a token is present in the session, get contacts
    callback = Proc.new do |r|
      r.headers['Authorization'] = "Bearer #{token}"
      r.headers['X-AnchorMailbox'] = email
    end

graph = MicrosoftGraph.new(base_url: 'https://graph.microsoft.com/v1.0/',
                              cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, 'metadata_v1.0.xml'),
                              &callback)

graph.me.contacts.first.update(:given_name => "ashish")
no method update

Webhooks suddenly stopped sending Data

This is probably an issue with the Webhooks module, and I asked a stackoverflow question as @Cbales recommended, but I just wanted to clarify that it is a webhook issue. if it it I will close this issue.

What happened was my app was receiving and processing WebHook notifications just fine, and then suddenly I stopped receiving notifications from the WebHook. I am just wondering what might have caused this.

As always, I appreciate the help.

Sending drafts through outlook with Rails

Hi,

I'm wondering if this API can be used for something like opening Outlook and saving an email as a draft automatically in the Outlook drafts folder. Thank you!

Gem Load Error is: uninitialized constant MicrosoftGraph::Base

I have developed and used the microsoft_graph gem in development without a hiccup. However, when I push the code to Heroku, I get an error saying Gem Load Error is: uninitialized constant MicrosoftGraph::Base. The backtrace for the gem load is below.

Any help is much appreciated :)

NoMethodError: undefined method `collection?' for nil:NilClass

Hi, everything was ok yesterday but today we got this error with loading messages.

Backtrace from Airbrake:

[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/base_entity.rb:114 in get_navigation_property
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/class_builder.rb:133 in block (3 levels) in create_navigation_properties
/home/apps/shopvox/releases/20170201073122/app/services/ms_api/emails.rb:221 in block in generate_body
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/collection_association.rb:220 in block in each
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/collection_association.rb:219 in each
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/collection_association.rb:219 in each
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/collection_association.rb:228 in each
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/collection_association.rb:228 in each
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/collection_association.rb:228 in each
[GEM_ROOT]/bundler/gems/msgraph-sdk-ruby-bc62e191fd7b/lib/microsoft_graph/collection_association.rb:228 in each
/home/apps/shopvox/releases/20170201073122/app/services/ms_api/emails.rb:171 in generate_body

URL request:

users/MY-ID/mailFolders/AAMLWU3NjktNDk1ZS1hYTyNzI2Yzg3ZjRiNwAuAAAAAACBU3N0PLTiSbJx7JPaTqjyAQAr5RAohRreTqqvlKinnUVNAAAAAAEMAAA=/messages

place in our code where it creates error:

@graph_client.me.mail_folders.filter(display_name: 'Inbox').first.messages.each do |m|
	m.attachments.each do |a|
		# ....
	end
end

When I call m.attachments it creates that error.
any ideas? It worked yesterday.

Microsoft Graph blocking all requests from AWS?

The issue we are facing is quite unexpected, We use Microsoft Graph API Client for Ruby, https://github.com/microsoftgraph/msgraph-sdk-ruby but we were also able to reproduce it in postman and curl.

Any request sent to Microsoft Graph API from Europe and Brazil received a success response,
but requests sent from our production server (AWS, Oregon) always, always fail.

here is an example request:

curl -X GET   https://graph.microsoft.com/v1.0/users/a9f4a487353d5ca4/contacts/ 

-H 'Authorization: Bearer ACCESS_TOKEN'

-H 'Cache-Control: no-cache' 

-H 'Content-Type: application/x-www-form-urlencoded'  

-H 'Postman-Token: e3ba1d72-5b17-b0ca-692e-ecbc96110c93'  

-H 'SdkVersion: Graph-ruby-0.1.0'

and the answer we get on production (AWS, Oregon):

{

"error": {

    "code": "ErrorServiceUnavailable",

    "message": "Active Directory operation did not succeed. Try again later.",

    "innerError": {

      "request-id": "2ab9ab7a-eb21-494d-8970-69c5101b87da",

      "date": "2018-03-15T15:24:19"

    }

  }

}

Our API Keys are fresh, and access token is requested with offline access, and so is always refreshed.

Also the fact that API is working from Europe and Brazil and not from AWS Oregon,
gave us the impression that:

  1. API calls are restricted from AWS
    OR
  2. Your CDN has some downtime issues

some more details nslookup graph.microsoft.com:

output from production (AWS Oregon, failed requests):

Server:         10.179.0.2
Address:        10.179.0.2#53

Non-authoritative answer:
graph.microsoft.com     canonical name = www.ags.graph.microsoft.com.akadns.net.
www.ags.graph.microsoft.com.akadns.net  canonical name = www.ags-prd.graph.microsoft.com.akadns.net.
www.ags-prd.graph.microsoft.com.akadns.net      canonical name = wus.ags-prd.graph.microsoft.com.akadns.net.
wus.ags-prd.graph.microsoft.com.akadns.net      canonical name = wus-a.ags-prd.graph.microsoft.com.akadns.net.
Name:   wus-a.ags-prd.graph.microsoft.com.akadns.net
Address: 137.135.50.212
Name:   wus-a.ags-prd.graph.microsoft.com.akadns.net
Address: 168.62.11.66
Name:   wus-a.ags-prd.graph.microsoft.com.akadns.net
Address: 168.62.16.21
Name:   wus-a.ags-prd.graph.microsoft.com.akadns.net
Address: 168.62.24.134


output from dev (Europe, successful requests):
Server:         192.168.0.1
Address:        192.168.0.1#53

Non-authoritative answer:
graph.microsoft.com     canonical name = www.ags.graph.microsoft.com.akadns.net.
www.ags.graph.microsoft.com.akadns.net  canonical name = www.ags-prd.graph.microsoft.com.akadns.net.
www.ags-prd.graph.microsoft.com.akadns.net      canonical name = weu.ags-prd.graph.microsoft.com.akadns.net.
weu.ags-prd.graph.microsoft.com.akadns.net      canonical name = weu-a.ags-prd.graph.microsoft.com.akadns.net.
Name:   weu-a.ags-prd.graph.microsoft.com.akadns.net
Address: 65.52.144.66
Name:   weu-a.ags-prd.graph.microsoft.com.akadns.net
Address: 213.199.132.167
Name:   weu-a.ags-prd.graph.microsoft.com.akadns.net
Address: 23.97.144.12
Name:   weu-a.ags-prd.graph.microsoft.com.akadns.net
Address: 65.52.136.185

Support for $top and $skip

Is there a reason that there is lack of support of skip and top parameters? I am guessing it could be overriden with next_link parameters, but providing that ability would be nice.

Also I see that the code doesn't support filtering and ordering at the same time. Is that intentional ? I don't understand why that is, given the lack of documentation.

Documentation

It would be nice to have a documentiaon for this gem. I am having some trouble finding out how to create an event using this gem.

Can't Download Metadata

Unless you use a local metadata file, you get the following error:

Traceback (most recent call last):
10: from /usr/bin/irb:11:in <main>' 9: from (irb):4 8: from (irb):4:in new'
7: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph.rb:23:in initialize' 6: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/class_builder.rb:8:in load!'
5: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/class_builder.rb:8:in each' 4: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/class_builder.rb:9:in block in load!'
3: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/class_builder.rb:69:in create_class!' 2: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/class_builder.rb:213:in get_superklass'
1: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/class_builder.rb:213:in `const_get'
NameError (wrong constant name Graph.entity)

Microsoft Graph Ruby client < 0.11.0 library is not actively supported

tl;dr
Don't use this client library.

Longer
We apologize for the situation. We currently do not have the resources available to maintain this library. Additionally, when we do have resources to restart work on supporting Ruby it is unlikely that we would continue to use the current approach that relies on an embedded copy of the metadata.

At this point, we have to encourage you to use your favorite Ruby HTTP client (like httparty) to make calls against the Microsoft Graph HTTP API. The documentation is written with the Microsoft Graph HTTP API as the primary focus. We do provide a sample/tutorial that demonstrates calling Microsoft Graph via Ruby.

Please continue to provide us feedback on the Ruby developer experience here in this repo. We do see the issues come through. We appreciate all feedback, especially the critical feedback.

No HTTP response with MicrosoftGraph Create Event

I am able to get, post, for calendar and emails with MicrosoftGraph api, but the api does not return a JSON response object.

Here is the code I am using to create an event, any guidance as to access response codes and messages is much appreciated, as I need them for validation purposes. The code below successfully adds events to a users calendar. just trying to get json response object.

def self.create_event(user, dateTime, endTime)
if user.outlook_token.expired?
user.outlook_token.refresh!(user)
end

  callback = Proc.new do |r| 
    r.headers['Authorization'] = "Bearer #{user.outlook_token.access_token}"
    r.headers['Content-type'] = 'application/json'
    r.headers['X-AnchorMailbox'] = user.email
  end

  graph = MicrosoftGraph.new(base_url: 'https://graph.microsoft.com/v1.0',
                            &callback)
  @create = graph.me.events.create(messageHash)

end

Can't Create Users Unless Using ADAL

If you don't use ADAL, you get the following error when creating an user:

Traceback (most recent call last):
7: from /usr/bin/irb:11:in <main>' 6: from (irb):8 5: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/collection_association.rb:136:in create!'
4: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/collection_association.rb:136:in tap' 3: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/collection_association.rb:136:in block in create!'
2: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/base_entity.rb:82:in save!' 1: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph/base.rb:44:in to_json'
NoMethodError (undefined method `to_json' for #Hash:0x00005581b19d8a90)

You can workaround it by adding "require 'json'" to your own code.

Similar to #67

Enterprise consumer needing immediate support

I haven't gotten a response in your documentation about an issue that I've submitted. I currently work with a team that has an enterprise account with you. Since this SDK isn't being supported, we are rolling one internally. The docs are fairly clear, except the response from your API seems incongruent. Could you please have a look? https://github.com/microsoftgraph/microsoft-graph-docs-contrib/issues/7399

You guys have a beta endpoint for notifications as well, but some of the code samples (I've looked at the NodeJS one) include subscription creation to subscribe to notifications. They set up an endpoint to receive notifications. If you know of one that does, it may be helpful in resolving the issue above, but because they do not, it's been a black box for me.

list endpoints return empty

If I list calendars or mail_folders, I always get an empty result:

> graph.me.calendars
=> []
> graph.me.mail_folders
=> []

However, get calendar and finding a folder returns a result:

graph.me.calendar
=> {"id":"<CALENDAR_ID>","name":"Calendar","color":"auto","change_key":"<CHANGE_KEY>"}
graph.me.mail_folders.find('inbox')
=> {"id":"<FOLDER_ID>","display_name":"Inbox","parent_folder_id":"<PARENT_FOLDER_ID>","child_folder_count":0,"unread_item_count":0,"total_item_count":0}

Email Attachments not working: RuntimeError

To reproduce:

require 'adal'
require 'microsoft_graph'

# Code from example
username      = '[email protected]'
password      = 'xxxxxxxxxxxx'
client_id     = 'xxxxx-xxxx-xxx-xxxxxx-xxxxxxx'
client_secret = 'xxxXXXxxXXXxxxXXXxxXXXXXXXXxxxxxx='
tenant        = 'tenant.onmicrosoft.com'
user_cred     = ADAL::UserCredential.new(username, password)
client_cred   = ADAL::ClientCredential.new(client_id, client_secret)
context       = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, tenant)
resource      = "https://graph.microsoft.com"
tokens        = context.acquire_token_for_user(resource, client_cred, user_cred)

# add the access token to the request header
callback = Proc.new { |r| r.headers["Authorization"] = "Bearer #{tokens.access_token}" }

graph = MicrosoftGraph.new(base_url: "https://graph.microsoft.com/v1.0",
                           cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, "metadata_v1.0.xml"),
                           api_version: '1.6', # Optional
                           &callback
)

me = graph.me # get the current user

# CUSTOM CODE
first_inbox_message = me.mail_folders.find('inbox').messages.first
first_inbox_message.attachments.first # => RuntimeError

Question: Why RuntimeError was added here ?

I've replaced raise RuntimeError with valuefor myself and it works brilliant

    def coerce(value)
      value
    end

messages.length returns wrong value

[4] pry(#<FetchOutlookJob>)> graph.me.mail_folders.find('inbox').messages.length
=> 0
[5] pry(#<FetchOutlookJob>)> graph.me.mail_folders.find('inbox').messages.first
=> #<MicrosoftGraph::Message:0x00007f9ad2183228
 @cached_navigation_property_values={},
 @cached_property_values=

if you call messages.length it always returns a 0 instead of returning the number of messages.

Delete Subscription - 500 ExtensionError

When I try to delete a subscription I get this error. Any reasons why this might be happening?

def self.delete_subscription(user)   
  if user.outlook_token.expired?
    user.outlook_token.refresh!(user)
  end
  
  callback = Proc.new do |r| 
    r.headers['Authorization'] = "Bearer #{user.outlook_token.access_token}"
    r.headers['Content-type'] = 'application/json'
    r.headers['X-AnchorMailbox'] = user.email
  end

  graph = MicrosoftGraph.new(base_url: 'https://graph.microsoft.com/v1.0/',
                            cached_metadata_

  graph.service.delete("subscriptions/#{subscriptionId}") 

500 ExtensionError: "Operation: Delete; Exception: [There was no raw user ticket in the requestPropertyMappings]" from "https://graph.microsoft.com/v1.0/subscriptions/{subscriptionID}"

Add ability to sort and filter

I'm a true beginner at Ruby RoR and for my internship I decided to use this gem over the Microsoft Graph Ruby on Rails Connect Sample one. It looked better to me (comparing both tutorials and gem name)
It's the first time i check this github repo, to star it.

As you said you need feedback, I would just say that not being able to filter and sort a query is pretty annoying. And of course there's a crazy lack of documentation... but now i understand better why.

Anyway thanks for the gem, I'm using it to create an intranet for our collaborators, around an office365 dashboard (mails, agenda, yammer, ...).

Is this Gem still supported?

This library has been more than 3 years in preview status, and despite al the user requests there have been no major changes.

Ruby client and OneDrive

Hey, I'd like to convert get 'https://graph.microsoft.com/v1.0/me/drive/sharedWithMe' using this gem.

It doesn't look like it has been implemented, am I wrong ?

Downloading profile photos

Per the Get Profile Photo docs, it appears that getting photo meta data is supported by the SDK:

e.g. graph.me.photo => GET /me/photo

But that getting the actual image is not supported. GET /me/photo/$value. Am I missing something, or is this a known issue?. Thanks!

Nokogiri not required when library is loaded.

To re-create:

  1. Install microsoft_graph gem with gem install microsoft_graph

  2. create a file with the following code:

# test.rb
MicrosoftGraph.new({
    base_url: 'https://graph.microsoft.com/v1.0',
    cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, 'metadata_v1.0.xml'),
}, &(->(r) { r.headers['Authorization'] = "Bearer #{token}" }))
  1. run this code with ruby test.rb

Gem Version: microsoft_graph (0.1.3)

Solution

I think require 'nokogiri' is just required somewhere in the loading process? Would a PR be appreciated?

uninitialized constant MicrosoftGraphCore::Authentication (NameError)

I tried to install the gem and I went through the Create an AuthenticationProvider object

require "microsoft_kiota_authentication_oauth"
require "microsoft_graph_core"

context = MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new("<the tenant id from your app registration>", "<the client id from your app registration>", "<the client secret from your app registration>")

authentication_provider = MicrosoftGraphCore::Authentication::OAuthAuthenticationProvider.new(context, nil, ["Files.Read"])

I replaced the ids & secrets with my credentials, Then I got this error:

uninitialized constant MicrosoftGraphCore::Authentication (NameError)

I added to my gemfile:
gem 'microsoft_graph'

What is timeline to first production release?

Hi there,

We're a bit uncomfortable using a gem that is a "release candidate...still in preview status". What is the timeline to first production release?

Would you also please publish a version history for the alpha/beta/gamma versions up until now? There is no version history listed -- other than commit history -- yet there's been development for multiple years by the looks of it...

Thanks!

SharePoint Support

Hi,
I'm interested in using the Sharepoint API, do you have any plans to update this gem to support the full API?

How to handle OData::ServerError: 503 ConcurrentItemSave ?

Hello everyone! In my app, I use this line to create a new calendar event:
@graph.service.post("me/calendars/#{my_calendar_id}/events", data.to_json)
which works most of the time. But sometimes, the error tracking app (I use Sentry) send me the exception, and I am not able to re-produce this 503 error.

OData::ServerError: 503 ConcurrentItemSave: "Conflicts occurred during saving data to store (saveresult: IrresolvableConflict, properties: ). Please retry the request." from "https://graph.microsoft.com/v1.0/me/calendars/AAMkADg1YmMzNjE2LTM5Y2MtNGI2NC05NjJjLWRiY2RhZTZkNDRkMABGAAAAAADZc5aq6QclSqy_4oRMVv_EBwB4ZnW6S6xLTZDSXIsgJfprAAAAAAEGAAB4ZnW6S6xLTZDSXIsgJfprAAAGEcjmAAA=/events"

Every time this occurs, 2 same events are created. From HTTP status codes, I can see what the generic cause of the issue is, but I am having trouble debugging and handling this exception.

I would appreciate if anyone here could help me to debug the issue, thanks in advance!

I have also posted this on Stackoverflow, and haven't got the solution yet.

Update:
When I look into the duplicate events using Graph Explorer, I found that they were created at very close timestamp, for example:
"createdDateTime": "2019-02-18T04:55:07.9453147Z"
"createdDateTime": "2019-02-18T04:55:24.9173342Z"

Can't Create Instances Unless Using ADAL

If you don't use ADAL, you get the following error when creating a GraphSession instance:

Traceback (most recent call last):
7: from /usr/bin/irb:11:in <main>' 6: from (irb):2 5: from (irb):2:in new'
4: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph.rb:16:in initialize' 3: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph.rb:16:in new'
2: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/odata/service.rb:11:in initialize' 1: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/odata/service.rb:230:in fetch_metadata'
NameError (uninitialized constant OData::Service::Net)

If you add "require 'net/http'' to your own code, you still get another error:

Traceback (most recent call last):
7: from /usr/bin/irb:11:in <main>' 6: from (irb):4 5: from (irb):4:in new'
4: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph.rb:16:in initialize' 3: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/microsoft_graph.rb:16:in new'
2: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/odata/service.rb:11:in initialize' 1: from /usr/local/share/gems/gems/microsoft_graph-0.1.3/lib/odata/service.rb:235:in fetch_metadata'
NameError (uninitialized constant Nokogiri)

You can workaround by also adding "'require 'nokogiri'" to your own code.

Can't get organization contact as members

Hello. I am in trouble.

I created distribution group in exchange online.
This DG(distribution group) includes organization contact as member.

I want to get all member email addresses of DG.
And I wrote the following code.

distriobution_group = graph.groups.find(~ID of DG ~)
members = distribution_group.members
members_email = members.map { |m| m.mail || m.user_principal_name }

But, the following error was output.

NoMethodError: undefined method `new' for nil:NilClass
from /vendor/bundle/ruby/2.6.0/gems/microsoft_graph0.1.3/lib/microsoft_graph/collection_association.rb:219:in `block in fetch_next_page' 

Is this a bug?
I would appreciate your help.

Thank you for reading my ugly English.

Memory leak?

I am trying to pull down ~1,500 emails with png and pdf attachments and its killing my server.

Looking at the code, I see the gem is keeping in memory the last 1000 collection objects.

@internal_values.push klass.new(attributes: entity_hash, parent: self, persisted: true)

I don't have time to investigate this further, but my machine doesn't have the resources to maintain ~1500 pdf files in memory. It would be better if with each fetch from the API, we GC the last page, since I not longer need it.

My quick fix in my active job worker like this:

    @emails = []
    outlook_service.latest_messages.each do |message|
      email = OutlookEmail::CreateEmailService.new(message: message,
                                           domain: @domain,
                                           company: @domain.company).email!
      @emails.push(email)
      break if @emails.length > 10
    end

    FetchOutlookJob.perform_later(domain_id) if @emails.any?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.