Fix "undefined method `member_type'" when accessing masterCategories
Hi, I'm trying to get the master categories with the gem, but either I get nothing or an exception is raised.
If I try to get the categories using the gem generated classes, I get nothing:
graph.me.outlook.master_categories.as_json => []
If I call the service directly, I get an exception:
graph.service.get('me/outlook/masterCategories')
NoMethodError: undefined method `member_type' for #<OData::EntityType:0x000055cebd0ba018>
from [redacted]/.rvm/gems/ruby-2.5.1@alkimii/bundler/gems/msgraph-sdk-ruby-925a65ee14ad/lib/odata/service.rb:177:in `block in get_type_for_odata_response'
Debugging the code I see that get_type_for_odata_response method does not take in account mixed Collection/Entity in the result, and it thinks all intermediate segments are collections. When I change
last_entity_type.member_type.navigation_property_by_name(segment).type
by
member_type = last_entity_type.respond_to?(:member_type) ? last_entity_type.member_type : last_entity_type
member_type.navigation_property_by_name(segment).type
It finally gets the categories.
👍
Thank you for the contribution. We retired that version of the SDK a number of years ago and are now working on a new preview. You can learn all about it on the readme page.