Slide 1

Slide 1 text

Microsoft Graph API Client and OpenAPI FGN ΤϯδχΞ Meetup vol.3 ODA Hirohito

Slide 2

Slide 2 text

Fukuoka.rb ຖिਫ༵೔։࠵ https://fukuokarb.connpass.com/

Slide 3

Slide 3 text

Microsoft Graph

Slide 4

Slide 4 text

Microsoft Graph https://developer.microsoft.com/en-us/graph

Slide 5

Slide 5 text

Microsoft Graph • Ϣʔβʔ৘ใΛศརʹѻ͑ΔαʔϏε • Azure AD • Office 365 αʔϏε • OneDrive • ͳͲͳͲ • G Suite ͱΑ͘ൺֱ͞ΕΔ https://docs.microsoft.com/en-us/graph/?view=graph-rest-1.0

Slide 6

Slide 6 text

༷ʑͳϓϥοτϑΥʔϜʹରԠ https://docs.microsoft.com/en-us/graph/?view=graph-rest-1.0#supported-platforms

Slide 7

Slide 7 text

༷ʑͳϓϥοτϑΥʔϜʹରԠ https://docs.microsoft.com/en-us/graph/?view=graph-rest-1.0#supported-platforms

Slide 8

Slide 8 text

2018/06/04 Microsoft ͕ GitHub Λങऩ https://news.microsoft.com/ja-jp/2018/06/05/microsoft-to-acquire-github-for-7-5-billion/

Slide 9

Slide 9 text

2018/06/04 Microsoft ͕ GitHub Λങऩ https://news.microsoft.com/ja-jp/2018/06/05/microsoft-to-acquire-github-for-7-5-billion/ •ങऩ౰࣌ʹݴΘΕ͍ͯͨ͜ͱ •GitHub ͷΦʔϓϯιʔεจԽ͕ࣦΘΕͳ͍͔ʁ •GitHub ͷاۀจԽࣗମ͕େ͖͘มΘͬͯ͠·Θͳ͍͔ʁ

Slide 10

Slide 10 text

લධ൑Λ෷১ͯ͠ SDK Λ OSS ͱͯ͠ެ։͍ͯ͠Δ https://docs.microsoft.com/en-us/graph/?view=graph-rest-1.0#supported-platforms

Slide 11

Slide 11 text

લධ൑Λ෷১ͯ͠ SDK Λ OSS ͱͯ͠ެ։͍ͯ͠Δ https://docs.microsoft.com/en-us/graph/?view=graph-rest-1.0#supported-platforms Α͏ʹݟ͑Δ

Slide 12

Slide 12 text

ݱ࣮ͱͷ௚໘

Slide 13

Slide 13 text

༷ʑͳϓϥοτϑΥʔϜʹରԠ https://docs.microsoft.com/en-us/graph/?view=graph-rest-1.0#supported-platforms

Slide 14

Slide 14 text

platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — SDK ͷ։ൃঢ়گ

Slide 15

Slide 15 text

platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — MS ϓϥοτϑΥʔϜ͸ NuGet ͔Βఏڙ

Slide 16

Slide 16 text

platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — JS ܥ͸ඃ͍ͬͯΔ

Slide 17

Slide 17 text

platform URL commits Android https://github.com/microsoftgraph/msgraph-sdk-android 259 Angular https://github.com/microsoftgraph/msgraph-sdk-javascript 469 ASP .NET https://www.nuget.org/packages/Microsoft.Graph — iOS https://github.com/microsoftgraph/msgraph-sdk-objc 110 Java https://github.com/microsoftgraph/msgraph-sdk-java 445 JavaScript https://github.com/microsoftgraph/msgraph-sdk-javascript 469 Node.js https://github.com/microsoftgraph/msgraph-sdk-javascript 469 PHP https://github.com/microsoftgraph/msgraph-sdk-php 227 Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby 34 UWP https://www.nuget.org/packages/Microsoft.Graph — Xamarin https://www.nuget.org/packages/Microsoft.Graph — Ͱ΋ຊ౰ʹண໨͢΂͖͸͜͜ʂ

Slide 18

Slide 18 text

ݱ࣮ • SDK ͸༷ʑϓϥοτϑΥʔϜͰରԠ͍ͯ͠Δࣄʹͳ͍ͬͯΔ͕ɺ
 ϓϥοτϑΥʔϜ͝ͱͷରԠͷ͕ܹ͍ࠩ͠ • Microsoft ؔ࿈ϓϥοτϑΥʔϜ͸ԿͰ΋ॆ࣮͍ͯ͠Δ • Ruby ͷରԠ͸͋·Γʹ΋஗͗͢Δ

Slide 19

Slide 19 text

Ruby ͷରԠঢ়گ

Slide 20

Slide 20 text

microsoft_graph https://rubygems.org/gems/microsoft_graph

Slide 21

Slide 21 text

Microsoft Graph Client Library for Ruby https://github.com/microsoftgraph/msgraph-sdk-ruby

Slide 22

Slide 22 text

׆ൃͱ͸ݴ͍೉͍ gem ͷެ։։࢝͸ 2016/08/01

Slide 23

Slide 23 text

ࢀߟ·Ͱʹ… google-api-client https://rubygems.org/gems/google-api-client

Slide 24

Slide 24 text

ࢀߟ·Ͱʹ… • 2010/10/14 ʹ v. 0.1.0 ެ։ • ݱࡏ v. 0.31.0 • ৽ػೳͷ௥Ճ͸ͳ͘ɺॏେͳ όάͱηΩϡϦςΟύονͷ Έ https://rubygems.org/gems/google-api-client

Slide 25

Slide 25 text

Ұํ… microsoft_graph

Slide 26

Slide 26 text

https://github.com/microsoftgraph/msgraph-sdk-ruby#usage-example require 'adal' require 'microsoft_graph' # authenticate using ADAL 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 puts "Hello, I am #{me.display_name}." me.direct_reports.each do |person| puts "How's it going, #{person.display_name}?" end

Slide 27

Slide 27 text

https://github.com/microsoftgraph/msgraph-sdk-ruby#usage-example require 'adal' require 'microsoft_graph' # authenticate using ADAL 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 puts "Hello, I am #{me.display_name}." me.direct_reports.each do |person| puts "How's it going, #{person.display_name}?" end ͜ͷαϯϓϧΛಈ͔͢ͱ…

Slide 28

Slide 28 text

https://github.com/microsoftgraph/msgraph-sdk-ruby#usage-example require 'adal' require 'microsoft_graph' # authenticate using ADAL 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 puts "Hello, I am #{me.display_name}." me.direct_reports.each do |person| puts "How's it going, #{person.display_name}?" end <= ͜͜ͰίέΔ

Slide 29

Slide 29 text

Microsoft Graph SDK for Ruby ͷ໰୊఺ • ʮRuby ରԠʯͱᨳ͍ͬͯΔ͕ SDK ͸࣮͸ preview ൛ • ϝϯςφϯε͞Ε͍ͯΔͱ͸౸ఈࢥ͑ͳ͍ • GitHub Overview ʹهࡌ͞Ε͍ͯΔαϯϓϧͰ͑͞·ͱ΋ʹಈ͔ͳ͍ • υΩϡϝϯτ͕ͳ͍ͷͰ࢖͍ํ͕શ͘෼͔Βͳ͍

Slide 30

Slide 30 text

Ruby is Dead in Microsoft Graph https://youtu.be/zb8dXWYUX10

Slide 31

Slide 31 text

Issues #42 https://github.com/microsoftgraph/msgraph-sdk-ruby/issues/42

Slide 32

Slide 32 text

Issues #42 https://github.com/microsoftgraph/msgraph-sdk-ruby/issues/42 ࠓޙ΋։ൃ͕ܧଓ͞ΕΔ͔ෆ໌ྎ

Slide 33

Slide 33 text

Microsoft Graph SDK for Ruby ʹ ͲͷΑ͏ͳΞϓϩʔν͕Ͱ͖Δ͔ʁ

Slide 34

Slide 34 text

ͲͷΑ͏ͳΞϓϩʔν͕Ͱ͖Δ͔ʁ • microsoft_grapsh ͸ Microsoft ͷ΋ͷ • ϝϯςφϯεͯ͠΋Β͑Δ or Ͱ͖Δ Ruby ੡ SDK ͕ཉ͍͠ • ͳ͍ͳΒࣗ࡞ͪ͠Ό͏ʁ

Slide 35

Slide 35 text

ࣗ࡞ͷ೉ؔ • ΤϯυϙΠϯτ਺͕๲େ • طଘͷ࣮૷͕೉ղ • OData Protocol • Microsoft ͕ 2007 ೥ʹఏএʢݱࡏ ver. 4.01ʣ • RESTful API ΛΑΓ؆୯ʹѻ͑ΔΑ͏ʹߟ͑ΒΕͨ
 Φʔϓϯϓϩτίϧ • https://www.odata.org/documentation/

Slide 36

Slide 36 text

Microsoft Graph νϡʔτϦΞϧ https://docs.microsoft.com/en-us/graph/tutorials/ruby

Slide 37

Slide 37 text

Microsoft Graph νϡʔτϦΞϧ https://docs.microsoft.com/en-us/graph/tutorials/ruby microsoft_graph ͸
 ࢖ΘΕ͍ͯͳ͍…

Slide 38

Slide 38 text

ࣗ࡞ͷ೉ؔ • ΤϯυϙΠϯτ਺͕๲େ • طଘͷ࣮૷͕೉ղ • OData Protocol • Microsoft ͕ 2007 ೥ʹఏএʢݱࡏ ver. 4.01ʣ • RESTful API ΛΑΓ؆୯ʹѻ͑ΔΑ͏ʹߟ͑ΒΕͨ
 Φʔϓϯϓϩτίϧ • https://www.odata.org/documentation/

Slide 39

Slide 39 text

ࣗ࡞ͷ೉ؔ • ΤϯυϙΠϯτ਺͕๲େ • طଘΛ౿ऻ͢Δͷ͕ࠔ೉ • OData Protocol • Microsoft ͕ 2007 ೥ʹఏএʢݱࡏ ver. 4.01ʣ • RESTful API ΛΑΓ؆୯ʹѻ͑ΔΑ͏ʹߟ͑ΒΕͨ
 Φʔϓϯϓϩτίϧ • https://www.odata.org/documentation/ ΋ͬͱָʹࣗ࡞Ͱ͖Δ
 ํ๏͸ͳ͍ͩΖ͏͔ʁ

Slide 40

Slide 40 text

OpenAPI

Slide 41

Slide 41 text

OpenAPI • ϓϩάϥϛϯάݴޠʹґଘ͠ͳ͍ RESTful API ΠϯλϑΣʔεͷఆٛ • ࢓༷ͷݺশ͸ OpenAPI Specification • https://github.com/OAI/OpenAPI-Specification • ݱࡏ v. 3.0.2 • چ Swagger specification • ࢀߟɿ https://speakerdeck.com/akihito_nakano/gunmaweb34

Slide 42

Slide 42 text

OpenAPI Generator • OpenAPI Specification ʹଇͬͯ YAML/JSON ϑΝΠϧΛ࡞੒͢Ε͹
 ͦΕΛجʹ API Client Λੜ੒ͯ͘͠ΕΔπʔϧ • https://github.com/OpenAPITools/openapi-generator • ࢀߟɿ https://rubykaigi.org/2019/presentations/ota42y.html#apr18

Slide 43

Slide 43 text

OpenAPI Generator • ରԠ͍ͯ͠Δݴޠ͕๛෋ • ౰વ Ruby ΋͋Δ https://github.com/OpenAPITools/openapi-generator#overview

Slide 44

Slide 44 text

OpenAPI Generator • ରԠ͍ͯ͠Δݴޠ͕๛෋ • ౰વ Ruby ΋͋Δ https://github.com/OpenAPITools/openapi-generator#overview OpenAPI Schema ͕͋Ε͹ ΫϥΠΞϯτΛੜ੒Ͱ͖Δ

Slide 45

Slide 45 text

microsoft-graph-openapi https://github.com/microsoftgraph/microsoft-graph-openapi

Slide 46

Slide 46 text

OpenAPI Generator Λ࢖ͬͯΈͨ https://github.com/microsoftgraph/microsoft-graph-openapi

Slide 47

Slide 47 text

OpenAPI Generator Λ࢖ͬͯΈͨ https://github.com/microsoftgraph/microsoft-graph-openapi

Slide 48

Slide 48 text

OpenAPI Generator Λ࢖ͬͯΈͨ https://github.com/microsoftgraph/microsoft-graph-openapi

Slide 49

Slide 49 text

ؾʹͳΔ఺ • ϝιου໊͕৑௕ • e.g. get_pet_by_id(pet_id, opts = {})

Slide 50

Slide 50 text

ݱࡏͷᷤ౻ʢͦͷ̍ʣ • OpenAPI Generator Λར༻͢Δ • OpenAPI Schema ͑͞࡞Ε͹ͦͷϝϯς͚ͩͰࡁΉ • microsoft-graph-openapi ͸໿ 51 ສߦ͋Δ • ϝιου໊͕৑௕

Slide 51

Slide 51 text

ݱࡏͷᷤ౻ʢͦͷ̎ʣ • OpenAPI Generator Λར༻͠ͳ͍ • ஍ຯʹΤϯυϙΠϯτΛҰͭͻͱ࣮ͭ૷͢Δ • OpenAPI Generator ͷ࠶ൃ໌ • Ͱ΋࣌ؒ͸༗ݶ…

Slide 52

Slide 52 text

·ͱΊ • Microsoft Graph • αʔϏεͱͯ͠͸ศར • υΩϡϝϯτ΍ SDK ΋׬උʢ˞ Ruby Λআ͘ʣ • OpenAPI • ϓϩάϥϛϯάݴޠʹґଘ͠ͳ͍ RESTful API ΠϯλϑΣʔεͷఆٛ • OpenAPI Generator Λ্ख͘׆༻Ͱ͖Ε͹ Microsoft Graph SDK Λ
 ࠶ൃ໌Ͱ͖ͦ͏ • ࣗ࡞͢Δಓ͸ͲͷಓΛબΜͰ΋Ἒͷಓ • Microsoft Graph SDK for Ruby ΛͪΌΜͱϝϯςφϯεͯ͘͠ΕΕ͹ສࣄղܾ͢Δ…

Slide 53

Slide 53 text

͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠