diff --git a/README.md b/README.md index 5730390b2e..599aba7850 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ +### Microsoft Graph Ruby client library is not actively supported + +Please read this [post](https://github.com/microsoftgraph/msgraph-sdk-ruby/issues/69) for more information and to provide feedback. + # Getting started with the Microsoft Graph Client Library for Ruby -This client library is a release candidate and is still in preview status, please continue to provide [feedback](https://github.com/microsoftgraph/msgraph-sdk-ruby/issues/new) as we iterate towards a production supported library. +This client library is a release candidate and is still in preview status. As such, this library is **not production ready**. Please proceed at your own risk and continue to provide [feedback](https://github.com/microsoftgraph/msgraph-sdk-ruby/issues/new) as we iterate towards a production supported library. ## Installation run ```gem install microsoft_graph``` or include ```gem microsoft_graph``` in your gemfile. @@ -12,7 +16,7 @@ Register your application to use Microsoft Graph API using one of the following supported authentication portals: * [Microsoft Application Registration Portal](https://apps.dev.microsoft.com) (**Recommended**): - Register a new application that authenticates using the v2.0 authentication endpoint. This endpoint autthenticates both personal (Microsoft) and work or school (Azure Active Directory) accounts. + Register a new application that authenticates using the v2.0 authentication endpoint. This endpoint authenticates both personal (Microsoft) and work or school (Azure Active Directory) accounts. * [Microsoft Azure Active Directory](https://manage.windowsazure.com): Register a new application in your tenant's Active Directory to support work or school users for your tenant, or multiple tenants. @@ -40,15 +44,16 @@ 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}" +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"), - &callback +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 @@ -96,3 +101,5 @@ To view or log issues, see [issues](https://github.com/microsoftgraph/msgraph-sd ## License Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT [license](LICENSE). + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/lib/microsoft_graph.rb b/lib/microsoft_graph.rb index ecef3192db..57a4f06875 100644 --- a/lib/microsoft_graph.rb +++ b/lib/microsoft_graph.rb @@ -14,9 +14,10 @@ class MicrosoftGraph def initialize(options = {}, &auth_callback) @service = OData::Service.new( + api_version: options[:api_version], + auth_callback: auth_callback, base_url: BASE_URL, - metadata_file: options[:cached_metadata_file], - auth_callback: auth_callback + metadata_file: options[:cached_metadata_file] ) @association_collections = {} unless MicrosoftGraph::ClassBuilder.loaded? diff --git a/lib/microsoft_graph/collection_association.rb b/lib/microsoft_graph/collection_association.rb index ba29d24d22..2663ca3860 100644 --- a/lib/microsoft_graph/collection_association.rb +++ b/lib/microsoft_graph/collection_association.rb @@ -191,21 +191,24 @@ def last? def fetch_next_page @next_link ||= query_path - result = begin - @graph.service.get(@next_link) - rescue OData::ClientError => e - if matches = /Unsupported sort property '([^']*)'/.match(e.message) - raise MicrosoftGraph::TypeError.new("Cannot sort by #{matches[1]}") - elsif /OrderBy not supported/.match(e.message) - if @order_by.length == 1 - raise MicrosoftGraph::TypeError.new("Cannot sort by #{@order_by.first}") + + result = + begin + @graph.service.get(@next_link) + rescue OData::ClientError => e + if matches = /Unsupported sort property '([^']*)'/.match(e.message) + raise MicrosoftGraph::TypeError.new("Cannot sort by #{matches[1]}") + elsif /OrderBy not supported/.match(e.message) + if @order_by.length == 1 + raise MicrosoftGraph::TypeError.new("Cannot sort by #{@order_by.first}") + else + raise MicrosoftGraph::TypeError.new("Cannot sort by at least one field requested") + end else - raise MicrosoftGraph::TypeError.new("Cannot sort by at least one field requested") + raise e end - else - raise e end - end + @next_link = result[:attributes]['@odata.next_link'] @next_link.sub!(MicrosoftGraph::BASE_URL, "") if @next_link diff --git a/lib/microsoft_graph/version.rb b/lib/microsoft_graph/version.rb index 4f7d50ff64..3bd2ff5a6f 100644 --- a/lib/microsoft_graph/version.rb +++ b/lib/microsoft_graph/version.rb @@ -1,3 +1,3 @@ class MicrosoftGraph - VERSION = "0.1.2" + VERSION = "0.1.3" end diff --git a/lib/odata/service.rb b/lib/odata/service.rb index 9ec5d419ad..6af2d8ade4 100644 --- a/lib/odata/service.rb +++ b/lib/odata/service.rb @@ -4,6 +4,9 @@ class Service attr_reader :metadata def initialize(options = {}, &block) + @api_version = { + 'api-version': options[:api_version] + } if options[:api_version] @auth_callback = options[:auth_callback] || block @base_url = options[:base_url] @metadata_file = options[:metadata_file] @@ -64,7 +67,17 @@ def patch(path, data) end def request(options = {}) - req = Request.new(options[:method], options[:uri], options[:data]) + uri = options[:uri] + + if @api_version then + parsed_uri = URI(uri) + params = URI.decode_www_form(parsed_uri.query || '') + .concat(@api_version.to_a) + parsed_uri.query = URI.encode_www_form params + uri = parsed_uri.to_s + end + + req = Request.new(options[:method], uri, options[:data]) @auth_callback.call(req) if @auth_callback req.perform end diff --git a/lib/odata/types/primitive_types/binary_type.rb b/lib/odata/types/primitive_types/binary_type.rb index 90e6f9e047..b4cf0d97e8 100644 --- a/lib/odata/types/primitive_types/binary_type.rb +++ b/lib/odata/types/primitive_types/binary_type.rb @@ -5,7 +5,7 @@ def valid_value?(value) end def coerce(value) - raise RuntimeError + value end def name diff --git a/microsoft_graph-0.1.2.gem b/microsoft_graph-0.1.2.gem deleted file mode 100644 index 750bfdca93..0000000000 Binary files a/microsoft_graph-0.1.2.gem and /dev/null differ diff --git a/microsoft_graph.gemspec b/microsoft_graph.gemspec index 97c42c1627..bcac27595e 100644 --- a/microsoft_graph.gemspec +++ b/microsoft_graph.gemspec @@ -27,5 +27,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "simplecov", "~> 0.11.1" spec.add_development_dependency "webmock", "~> 1.22.6" - spec.add_dependency "nokogiri", "~> 1.6.8" + spec.add_dependency "nokogiri", ">= 1.8.0" end diff --git a/spec/common_spec_helper.rb b/spec/common_spec_helper.rb index 4f3eb01de4..134ac95f6b 100644 --- a/spec/common_spec_helper.rb +++ b/spec/common_spec_helper.rb @@ -5,6 +5,10 @@ require "rspec" require 'rspec/given' + +# NOTE: Please remove this line if https://github.com/AzureAD/azure-activedirectory-library-for-ruby/pull/50 is released. +require "adal/request_parameters" + require "adal" require "pry"