- removes ruby libraries after their publishing

Signed-off-by: Vincent Biret <vibiret@microsoft.com>
This commit is contained in:
Vincent Biret 2022-12-30 16:27:02 -05:00
Родитель 447d26aeac
Коммит fc462b0540
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 32426322EDFFB7E3
107 изменённых файлов: 26 добавлений и 4750 удалений

21
.github/dependabot.yml поставляемый
Просмотреть файл

@ -12,24 +12,3 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: bundler
directory: "/abstractions/ruby/microsoft_kiota_abstractions"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- Ruby
- package-ecosystem: bundler
directory: "/serialization/ruby/json/microsoft_kiota_serialization"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- Ruby
- package-ecosystem: bundler
directory: "/http/ruby/nethttp/microsoft_kiota_nethttplibrary"
schedule:
interval: daily
open-pull-requests-limit: 10
labels:
- Ruby

97
.github/workflows/abstractions-ruby.yml поставляемый
Просмотреть файл

@ -1,97 +0,0 @@
name: Ruby abstractions
on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['abstractions/ruby/**', '.github/workflows/**']
pull_request:
paths: ['abstractions/ruby/**', '.github/workflows/**']
jobs:
build:
env:
relativePath: ./abstractions/ruby/microsoft_kiota_abstractions
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
ruby-version: ['2.7', '3.0', '3.1', head, jruby, jruby-head, truffleruby, truffleruby-head]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- name: Run tests
run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Upload artifacts for ruby version 3 and ubuntu
if: ${{ matrix.os == 'ubuntu-latest' && matrix.ruby-version == '3.1'}}
uses: actions/upload-artifact@v3
with:
name: drop
path: |
${{ env.relativePath }}/Gemfile.lock
${{ env.relativePath }}/README.md
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
environment:
name: staging_feeds
runs-on: ubuntu-latest
env:
relativePath: ./abstractions/ruby/microsoft_kiota_abstractions
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
working-directory: ${{ env.relativePath }}
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.PUBLISH_GH_TOKEN}}"
OWNER: ${{ github.repository_owner }}
# deploy_prod:
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# environment:
# name: production_feeds
# runs-on: ubuntu-latest
# env:
# relativePath: ./abstractions/ruby
# needs: [build]
# steps:
# - uses: actions/checkout@v3
# - uses: ruby/setup-ruby@v1
# with:
# ruby-version: '3.1'
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically
# - run: bundle exec rake
# - name: Publish to RubyGems
# run: |
# mkdir -p $HOME/.gem
# touch $HOME/.gem/credentials
# chmod 0600 $HOME/.gem/credentials
# printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
# gem build *.gemspec
# gem push *.gem
# env:
# GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" TODO: Token for rubyGems.org

Просмотреть файл

@ -1,101 +0,0 @@
name: Ruby authentication
on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['authentication/ruby/**', '.github/workflows/**']
pull_request:
paths: ['authentication/ruby/**', '.github/workflows/**']
jobs:
build:
env:
relativePath: ./authentication/ruby/oauth/microsoft_kiota_authentication_oauth
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}" #needed for jruby-head
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
ruby-version: ['2.7', '3.0', '3.1', head, jruby, jruby-head, truffleruby, truffleruby-head]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- name: Run tests
run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Upload artifacts for ruby version 3 and ubuntu
if: ${{ matrix.os == 'ubuntu-latest' && matrix.ruby-version == '3.1'}}
uses: actions/upload-artifact@v3
with:
name: drop
path: |
${{ env.relativePath }}/Gemfile.lock
${{ env.relativePath }}/README.md
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
environment:
name: staging_feeds
runs-on: ubuntu-latest
env:
relativePath: ./authentication/ruby/oauth/microsoft_kiota_authentication_oauth
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
working-directory: ${{ env.relativePath }}
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.PUBLISH_GH_TOKEN}}"
OWNER: ${{ github.repository_owner }}
# deploy_prod:
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# environment:
# name: production_feeds
# runs-on: ubuntu-latest
# env:
# relativePath: ./authentication/ruby/oauth/microsoft_kiota_authentication_oauth
# BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
# needs: [build]
# steps:
# - uses: actions/checkout@v3
# - uses: ruby/setup-ruby@v1
# with:
# ruby-version: '3.1'
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically
# - run: bundle exec rake
# - name: Publish to RubyGems
# run: |
# mkdir -p $HOME/.gem
# touch $HOME/.gem/credentials
# chmod 0600 $HOME/.gem/credentials
# printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
# gem build *.gemspec
# gem push *.gem
# env:
# GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" TODO: Token for rubyGems.org

100
.github/workflows/http-ruby-faraday.yml поставляемый
Просмотреть файл

@ -1,100 +0,0 @@
name: Ruby http faraday
on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['http/ruby/**', '.github/workflows/**']
pull_request:
paths: ['http/ruby/**', '.github/workflows/**']
jobs:
build:
env:
relativePath: ./http/ruby/faraday/microsoft_kiota_faraday
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}" #needed for jruby-head
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
ruby-version: ['2.7', '3.0', '3.1', head, jruby, jruby-head, truffleruby, truffleruby-head]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- name: Run tests
run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Upload artifacts for ruby version 3 and ubuntu
if: ${{ matrix.os == 'ubuntu-latest' && matrix.ruby-version == '3.1'}}
uses: actions/upload-artifact@v3
with:
name: drop
path: |
${{ env.relativePath }}/Gemfile.lock
${{ env.relativePath }}/README.md
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
environment:
name: staging_feeds
runs-on: ubuntu-latest
env:
relativePath: ./http/ruby/faraday/microsoft_kiota_faraday
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
working-directory: ${{ env.relativePath }}
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.PUBLISH_GH_TOKEN}}"
OWNER: ${{ github.repository_owner }}
# deploy_prod:
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# environment:
# name: production_feeds
# runs-on: ubuntu-latest
# env:
# relativePath: ./http/ruby/faraday/microsoft_kiota_faraday
# needs: [build]
# steps:
# - uses: actions/checkout@v3
# - uses: ruby/setup-ruby@v1
# with:
# ruby-version: '3.1'
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically
# - run: bundle exec rake
# - name: Publish to RubyGems
# run: |
# mkdir -p $HOME/.gem
# touch $HOME/.gem/credentials
# chmod 0600 $HOME/.gem/credentials
# printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
# gem build *.gemspec
# gem push *.gem
# env:
# GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" TODO: Token for rubyGems.org

101
.github/workflows/serialization-ruby-json.yml поставляемый
Просмотреть файл

@ -1,101 +0,0 @@
name: Ruby serialization
on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['serialization/ruby/**', '.github/workflows/**']
pull_request:
paths: ['serialization/ruby/**', '.github/workflows/**']
jobs:
build:
env:
relativePath: ./serialization/ruby/json/microsoft_kiota_serialization
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}" #needed for jruby-head
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
ruby-version: ['2.7', '3.0', '3.1', head, jruby, jruby-head, truffleruby, truffleruby-head]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- name: Run tests
run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Upload artifacts for ruby version 3 and ubuntu
if: ${{ matrix.os == 'ubuntu-latest' && matrix.ruby-version == '3.1'}}
uses: actions/upload-artifact@v3
with:
name: drop
path: |
${{ env.relativePath }}/Gemfile.lock
${{ env.relativePath }}/README.md
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
environment:
name: staging_feeds
runs-on: ubuntu-latest
env:
relativePath: ./serialization/ruby/json/microsoft_kiota_serialization
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
needs: [build]
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler: 'latest'
cache-version: 1
working-directory: ${{ env.relativePath }}
- run: bundle exec rake
working-directory: ${{ env.relativePath }}
- name: Publish to GPR
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
working-directory: ${{ env.relativePath }}
env:
GEM_HOST_API_KEY: "Bearer ${{secrets.PUBLISH_GH_TOKEN}}"
OWNER: ${{ github.repository_owner }}
# deploy_prod:
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
# environment:
# name: production_feeds
# runs-on: ubuntu-latest
# env:
# relativePath: ./abstractions/ruby
# BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/MICROSOFT/: "${{ secrets.PUBLISH_GH_USERNAME }}:${{ secrets.PUBLISH_GH_TOKEN }}"
# needs: [build]
# steps:
# - uses: actions/checkout@v3
# - uses: ruby/setup-ruby@v1
# with:
# ruby-version: '3.1'
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically
# - run: bundle exec rake
# - name: Publish to RubyGems
# run: |
# mkdir -p $HOME/.gem
# touch $HOME/.gem/credentials
# chmod 0600 $HOME/.gem/credentials
# printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
# gem build *.gemspec
# gem push *.gem
# env:
# GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" TODO: Token for rubyGems.org

Просмотреть файл

@ -21,15 +21,15 @@ The following table provides an overview of the languages supported by Kiota and
| Language | Generation | Abstractions | Serialization | Authentication | HTTP | Required tools & dependencies |
| -------- | ---------- |--------------------------------|-----------------------------------------------------------------| -------------- | ---- | -------------- |
| CSharp | [](https://github.com/microsoft/kiota/projects/5) | [](https://github.com/microsoft/kiota-abstractions-dotnet) | [FORM](https://github.com/microsoft/kiota-serialization-form-dotnet), [JSON](https://github.com/microsoft/kiota-serialization-json-dotnet), [TEXT](https://github.com/microsoft/kiota-serialization-text-dotnet) | [Anonymous](https://github.com/microsoft/kiota-abstractions-dotnet/blob/main/src/authentication/AnonymousAuthenticationProvider.cs), [API Key](https://github.com/microsoft/kiota-abstractions-dotnet/blob/main/src/authentication/ApiKeyAuthenticationProvider.cs), [Azure](https://github.com/microsoft/kiota-authentication-azure-dotnet) | [](https://github.com/microsoft/kiota-http-dotnet) | [link](https://microsoft.github.io/kiota/get-started/dotnet) |
| Go | [](https://github.com/microsoft/kiota/projects/8) | [](https://github.com/microsoft/kiota-abstractions-go) | [FORM](https://github.com/microsoft/kiota-serialization-form-go), [JSON](https://github.com/microsoft/kiota-serialization-json-go), [TEXT](https://github.com/microsoft/kiota-serialization-text-go) | [Anonymous](https://github.com/microsoft/kiota-abstractions-go/blob/main/authentication/anonymous_authentication_provider.go), [API Key](https://github.com/microsoft/kiota-abstractions-go/blob/main/authentication/api_key_authentication_provider.go), [Azure](https://github.com/microsoft/kiota-authentication-azure-go/) | [](https://github.com/microsoft/kiota-http-go/) | [link](https://microsoft.github.io/kiota/get-started/go) |
| Java | [](https://github.com/microsoft/kiota/projects/7) | [](https://github.com/microsoft/kiota-java/tree/main/components/abstractions) | [FORM](https://github.com/microsoft/kiota-java/tree/main/components/serialization/form), [JSON](https://github.com/microsoft/kiota-java/tree/main/components/serialization/json), [TEXT](https://github.com/microsoft/kiota-java/tree/main/components/serialization/text) | [Anonymous](https://github.com/microsoft/kiota-java/blob/main/components/abstractions/src/main/java/com/microsoft/kiota/authentication/AnonymousAuthenticationProvider.java), [API Key](https://github.com/microsoft/kiota-java/blob/main/components/abstractions/src/main/java/com/microsoft/kiota/authentication/ApiKeyAuthenticationProvider.java), [Azure](https://github.com/microsoft/kiota-java/tree/main/components/authentication/azure) | [](https://github.com/microsoft/kiota-java/tree/main/components/http/okHttp) | [link](https://microsoft.github.io/kiota/get-started/java) |
| PHP | [](https://github.com/microsoft/kiota/projects/4) | [](https://github.com/microsoft/kiota-abstractions-php) | [JSON](https://github.com/microsoft/kiota-serialization-json-php), [❌ FORM](https://github.com/microsoft/kiota/issues/2074), [TEXT](https://github.com/microsoft/kiota-serialization-text-php) | [Anonymous](https://github.com/microsoft/kiota-abstractions-php/blob/main/src/Authentication/AnonymousAuthenticationProvider.php), [✔️ PHP League](https://github.com/microsoft/kiota-authentication-phpleague-php) | [](https://github.com/microsoft/kiota-http-guzzle-php) | [link](https://microsoft.github.io/kiota/get-started/php) |
| Python | [](https://github.com/microsoft/kiota/projects/3) | [](https://github.com/microsoft/kiota-abstractions-python) | [❌ FORM](https://github.com/microsoft/kiota/issues/2075), [JSON](https://github.com/microsoft/kiota-serialization-json-python), [TEXT](https://github.com/microsoft/kiota-serialization-text-python) | [Anonymous](https://github.com/microsoft/kiota-abstractions-python/blob/main/kiota_abstractions/authentication/anonymous_authentication_provider.py), [Azure](https://github.com/microsoft/kiota-authentication-azure-python) | [](https://github.com/microsoft/kiota-http-python) | [link](https://microsoft.github.io/kiota/get-started/python) |
| Ruby | [](https://github.com/microsoft/kiota/projects/6) | [](./abstractions/ruby) | [❌ FORM](https://github.com/microsoft/kiota/issues/2077), [JSON](./serialization/ruby/json/microsoft_kiota_serialization), [❌ TEXT](https://github.com/microsoft/kiota/issues/1049) | [Anonymous](./abstractions/ruby/microsoft_kiota_abstractions/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb), [❌ Azure](https://github.com/microsoft/kiota/issues/421) | [](./http/ruby/nethttp/microsoft_kiota_nethttplibrary)| [link](https://microsoft.github.io/kiota/get-started/ruby) |
| Shell | [](https://github.com/microsoft/kiota/projects/10) | (see CSHarp) + [](https://github.com/microsoft/kiota-cli-commons) | (see CSHarp) | (see CSharp) | (see CSharp) | [link](https://microsoft.github.io/kiota/get-started/cli) |
| CSharp | ✔ | [](https://github.com/microsoft/kiota-abstractions-dotnet) | [FORM](https://github.com/microsoft/kiota-serialization-form-dotnet), [JSON](https://github.com/microsoft/kiota-serialization-json-dotnet), [TEXT](https://github.com/microsoft/kiota-serialization-text-dotnet) | [Anonymous](https://github.com/microsoft/kiota-abstractions-dotnet/blob/main/src/authentication/AnonymousAuthenticationProvider.cs), [API Key](https://github.com/microsoft/kiota-abstractions-dotnet/blob/main/src/authentication/ApiKeyAuthenticationProvider.cs), [Azure](https://github.com/microsoft/kiota-authentication-azure-dotnet) | [](https://github.com/microsoft/kiota-http-dotnet) | [link](https://microsoft.github.io/kiota/get-started/dotnet) |
| Go | ✔ | [](https://github.com/microsoft/kiota-abstractions-go) | [FORM](https://github.com/microsoft/kiota-serialization-form-go), [JSON](https://github.com/microsoft/kiota-serialization-json-go), [TEXT](https://github.com/microsoft/kiota-serialization-text-go) | [Anonymous](https://github.com/microsoft/kiota-abstractions-go/blob/main/authentication/anonymous_authentication_provider.go), [API Key](https://github.com/microsoft/kiota-abstractions-go/blob/main/authentication/api_key_authentication_provider.go), [Azure](https://github.com/microsoft/kiota-authentication-azure-go/) | [](https://github.com/microsoft/kiota-http-go/) | [link](https://microsoft.github.io/kiota/get-started/go) |
| Java | ✔ | [](https://github.com/microsoft/kiota-java/tree/main/components/abstractions) | [FORM](https://github.com/microsoft/kiota-java/tree/main/components/serialization/form), [JSON](https://github.com/microsoft/kiota-java/tree/main/components/serialization/json), [TEXT](https://github.com/microsoft/kiota-java/tree/main/components/serialization/text) | [Anonymous](https://github.com/microsoft/kiota-java/blob/main/components/abstractions/src/main/java/com/microsoft/kiota/authentication/AnonymousAuthenticationProvider.java), [API Key](https://github.com/microsoft/kiota-java/blob/main/components/abstractions/src/main/java/com/microsoft/kiota/authentication/ApiKeyAuthenticationProvider.java), [Azure](https://github.com/microsoft/kiota-java/tree/main/components/authentication/azure) | [](https://github.com/microsoft/kiota-java/tree/main/components/http/okHttp) | [link](https://microsoft.github.io/kiota/get-started/java) |
| PHP | ✔ | [](https://github.com/microsoft/kiota-abstractions-php) | [JSON](https://github.com/microsoft/kiota-serialization-json-php), [❌ FORM](https://github.com/microsoft/kiota/issues/2074), [TEXT](https://github.com/microsoft/kiota-serialization-text-php) | [Anonymous](https://github.com/microsoft/kiota-abstractions-php/blob/main/src/Authentication/AnonymousAuthenticationProvider.php), [✔️ PHP League](https://github.com/microsoft/kiota-authentication-phpleague-php) | [](https://github.com/microsoft/kiota-http-guzzle-php) | [link](https://microsoft.github.io/kiota/get-started/php) |
| Python | ✔ | [](https://github.com/microsoft/kiota-abstractions-python) | [❌ FORM](https://github.com/microsoft/kiota/issues/2075), [JSON](https://github.com/microsoft/kiota-serialization-json-python), [TEXT](https://github.com/microsoft/kiota-serialization-text-python) | [Anonymous](https://github.com/microsoft/kiota-abstractions-python/blob/main/kiota_abstractions/authentication/anonymous_authentication_provider.py), [Azure](https://github.com/microsoft/kiota-authentication-azure-python) | [](https://github.com/microsoft/kiota-http-python) | [link](https://microsoft.github.io/kiota/get-started/python) |
| Ruby | ✔ | [](https://github.com/microsoft/kiota-abstractions-ruby) | [❌ FORM](https://github.com/microsoft/kiota/issues/2077), [JSON](https://github.com/microsoft/kiota-serialization-json-ruby), [❌ TEXT](https://github.com/microsoft/kiota/issues/1049) | [Anonymous](https://github.com/microsoft/kiota-abstractions-ruby/blob/main/lib/microsoft_kiota_abstractions/authentication/anonymous_authentication_provider.rb), [✔️ OAuth2](https://github.com/microsoft/kiota-authentication-oauth-ruby) | [](https://github.com/microsoft/kiota-http-ruby)| [link](https://microsoft.github.io/kiota/get-started/ruby) |
| Shell | ✔ | (see CSHarp) + [](https://github.com/microsoft/kiota-cli-commons) | (see CSHarp) | (see CSharp) | (see CSharp) | [link](https://microsoft.github.io/kiota/get-started/cli) |
| Swift | [](https://github.com/microsoft/kiota/issues/1449) | [](./abstractions/swift) | [❌ FORM](https://github.com/microsoft/kiota/issues/2076), [❌ JSON](https://github.com/microsoft/kiota/issues/1451), [❌ TEXT](https://github.com/microsoft/kiota/issues/1452) | [Anonymous](./abstractions/swift/Source/MicrosoftKiotaAbstractions/Authentication/AnonymousAuthenticationProvider.swift), [❌ Azure](https://github.com/microsoft/kiota/issues/1453) | [](https://github.com/microsoft/kiota/issues/1454)| |
| TypeScript/JavaScript | [](https://github.com/microsoft/kiota/projects/2) | [](https://github.com/microsoft/kiota-typescript/tree/main/packages/abstractions) | [FORM](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/form), [JSON](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/json), [TEXT](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/text) | [Anonymous](https://github.com/microsoft/kiota-typescript/blob/main/packages/abstractions/src/authentication/anonymousAuthenticationProvider.ts), [API Key](https://github.com/microsoft/kiota-typescript/blob/main/packages/abstractions/src/authentication/apiKeyAuthenticationProvider.ts), [Azure](https://github.com/microsoft/kiota-typescript/tree/main/packages/authentication/azure) | [](https://github.com/microsoft/kiota-typescript/tree/main/packages/http/fetch) | [link](https://microsoft.github.io/kiota/get-started/typescript) |
| TypeScript/JavaScript | ✔ | [](https://github.com/microsoft/kiota-typescript/tree/main/packages/abstractions) | [FORM](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/form), [JSON](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/json), [TEXT](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/text) | [Anonymous](https://github.com/microsoft/kiota-typescript/blob/main/packages/abstractions/src/authentication/anonymousAuthenticationProvider.ts), [API Key](https://github.com/microsoft/kiota-typescript/blob/main/packages/abstractions/src/authentication/apiKeyAuthenticationProvider.ts), [Azure](https://github.com/microsoft/kiota-typescript/tree/main/packages/authentication/azure) | [](https://github.com/microsoft/kiota-typescript/tree/main/packages/http/fetch) | [link](https://microsoft.github.io/kiota/get-started/typescript) |
> Legend: ✔ -> in preview, ❌ -> not started, ▶ -> in progress.

Просмотреть файл

@ -6,7 +6,7 @@ Your project will need a reference to the abstraction package to build and run,
- [Dotnet](https://github.com/microsoft/kiota-abstractions-dotnet)
- [Java](https://github.com/microsoft/kiota-java/tree/main/components/abstractions)
- [Go](https://github.com/microsoft/kiota-abstractions-go)
- [Ruby](./ruby/microsoft_kiota_abstractions)
- [Ruby](https://github.com/microsoft/kiota-abstractions-ruby)
- [TypeScript](https://github.com/microsoft/kiota-typescript/tree/main/packages/abstractions)
- [PHP](https://github.com/microsoft/kiota-abstractions-php)
- [Python](https://github.com/microsoft/kiota-abstractions-python)

Просмотреть файл

@ -1,13 +0,0 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
# rspec failure tracking
.rspec_status
Gemfile.lock

Просмотреть файл

@ -1,6 +0,0 @@
# frozen_string_literal: true
source 'https://rubygems.org'
# Specify your gem's dependencies in microsoft_kiota_abstractions.gemspec
gemspec

Просмотреть файл

@ -1,49 +0,0 @@
# MicrosoftKiotaAbstractions
![Ruby](https://github.com/microsoft/kiota/actions/workflows/abstractions-ruby.yml/badge.svg)
## Using the abstractions
Option 1: Bundler config
```shell
bundle config https://rubygems.pkg.github.com/microsoft/kiota USERNAME:TOKEN
```
Option 2: Configuring `~/.gemrc` file
```
---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://rubygems.org/
- https://USERNAME:TOKEN@rubygems.pkg.github.com/microsoft/kiota
:update_sources: true
:verbose: true
```
## Installation
Add this line to your application's Gemfile:
```ruby
source "https://rubygems.pkg.github.com/microsoft" do
gem "microsoft_kiota_abstractions", "0.2.0"
end
```
And then execute:
```shell
bundle install
```
Or install it yourself as:
```shell
gem install microsoft_kiota_abstractions --version "0.2.0" --source "https://{USERNAME}{PASSWORD/TOKEN}rubygems.pkg.github.com/microsoft"
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/microsoft/kiota.

Просмотреть файл

@ -1,8 +0,0 @@
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task default: :spec

Просмотреть файл

@ -1,25 +0,0 @@
# frozen_string_literal: true
require_relative "microsoft_kiota_abstractions/authentication/authentication_provider"
require_relative "microsoft_kiota_abstractions/authentication/base_bearer_token_authentication_provider"
require_relative "microsoft_kiota_abstractions/authentication/anonymous_authentication_provider"
require_relative "microsoft_kiota_abstractions/api_error"
require_relative "microsoft_kiota_abstractions/http_method"
require_relative "microsoft_kiota_abstractions/api_client_builder"
require_relative "microsoft_kiota_abstractions/request_adapter"
require_relative "microsoft_kiota_abstractions/request_option"
require_relative "microsoft_kiota_abstractions/request_headers"
require_relative "microsoft_kiota_abstractions/request_information"
require_relative "microsoft_kiota_abstractions/version"
require_relative "microsoft_kiota_abstractions/serialization/parsable"
require_relative "microsoft_kiota_abstractions/serialization/iso_duration"
require_relative "microsoft_kiota_abstractions/serialization/additional_data_holder"
require_relative "microsoft_kiota_abstractions/serialization/parse_node"
require_relative "microsoft_kiota_abstractions/serialization/parse_node_factory"
require_relative "microsoft_kiota_abstractions/serialization/parse_node_factory_registry"
require_relative "microsoft_kiota_abstractions/serialization/serialization_writer"
require_relative "microsoft_kiota_abstractions/serialization/serialization_writer_factory"
require_relative "microsoft_kiota_abstractions/serialization/serialization_writer_factory_registry"
module MicrosoftKiotaAbstractions
end

Просмотреть файл

@ -1,19 +0,0 @@
require_relative "serialization/parse_node_factory"
require_relative "serialization/parse_node_factory_registry"
require_relative "serialization/serialization_writer_factory"
require_relative "serialization/serialization_writer_factory_registry"
module MicrosoftKiotaAbstractions
class ApiClientBuilder
def self.register_default_serializer(factory_class)
factory = factory_class.new()
MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.content_type_associated_factories[factory.get_valid_content_type()] = factory
end
def self.register_default_deserializer(factory_class)
factory = factory_class.new()
MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.content_type_associated_factories[factory.get_valid_content_type()] = factory
end
end
end

Просмотреть файл

@ -1,23 +0,0 @@
require_relative 'serialization/parsable'
module MicrosoftKiotaAbstractions
class ApiError < StandardError
include MicrosoftKiotaAbstractions::Parsable
##
## The deserialization information for the current model
## @return a i_dictionary
##
def get_field_deserializers()
return Hash.new
end
##
## Serializes information the current object
## @param writer Serialization writer to use to serialize this model
## @return a void
##
def serialize(writer)
raise StandardError, 'writer cannot be null' if writer.nil?
end
end
end

Просмотреть файл

@ -1,20 +0,0 @@
# frozen_string_literal: true
require_relative 'allowed_hosts_validator'
module MicrosoftKiotaAbstractions
# Access Token Provider Module implementation
module AccessTokenProvider
# This function obtains the authorization token.
# :params
# uri: a string containing the uri
# additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
# default is empty hash
def get_authorization_token(uri, additional_properties = {})
raise NotImplementedError.new
end
attr_accessor :scopes, :host_validator
end
end

Просмотреть файл

@ -1,39 +0,0 @@
# frozen_string_literal: true
require 'uri'
module MicrosoftKiotaAbstractions
# Maintains a list of valid hosts and allows authentication providers to check whether
# a host is valid before authenticating a request
class AllowedHostsValidator
# creates a new AllocatedHostsValidator with provided values
def initialize(allowed_hosts)
@allowed_hosts = {}
allowed_hosts.each { |host| @allowed_hosts[host.downcase] = true }
end
# sets the list of valid hosts with provided value (val)
def allowed_hosts=(val)
@allowed_hosts = {}
val.each { |host| @allowed_hosts[host.downcase] = true }
end
# checks whether the provided host is valid
def url_host_valid?(url)
return true if @allowed_hosts.empty?
parsed_url = URI(url)
return false if parsed_url.host.nil?
return false unless parsed_url.is_a?(URI::HTTPS)
@allowed_hosts.key? parsed_url.host.downcase
rescue URI::InvalidURIError
false
end
# gets the list of valid hosts
attr_reader :allowed_hosts
end
end

Просмотреть файл

@ -1,7 +0,0 @@
module MicrosoftKiotaAbstractions
class AnonymousAuthenticationProvider
include MicrosoftKiotaAbstractions::AuthenticationProvider
def authenticate_request(request)
end
end
end

Просмотреть файл

@ -1,7 +0,0 @@
module MicrosoftKiotaAbstractions
module AuthenticationProvider
def authenticate_request(request, additional_properties = {})
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,26 +0,0 @@
# frozen_string_literal: true
require_relative './authentication_provider'
require_relative './access_token_provider'
module MicrosoftKiotaAbstractions
# Provides a base class for implementing AuthenticationProvider for Bearer token scheme
class BaseBearerTokenAuthenticationProvider
include MicrosoftKiotaAbstractions::AuthenticationProvider
def initialize(access_token_provider)
raise StandardError, 'access_token_provider parameter cannot be nil' if access_token_provider.nil?
@access_token_provider = access_token_provider
end
AUTHORIZATION_HEADER_KEY = 'Authorization'
def authenticate_request(request, additional_properties = {})
raise StandardError, 'Request cannot be null' if request.nil?
Fiber.new do
token = @access_token_provider.get_authorization_token(request.uri, additional_properties).resume
request.headers.add(AUTHORIZATION_HEADER_KEY, "Bearer #{token}") unless token.nil? || token.empty?
end unless request.headers.get_all.key?(AUTHORIZATION_HEADER_KEY)
end
end
end

Просмотреть файл

@ -1,17 +0,0 @@
module MicrosoftKiotaAbstractions
module HttpMethod
HTTP_METHOD = {
GET: :GET,
POST: :POST,
PATCH: :PATCH,
DELETE: :DELETE,
OPTIONS: :OPTIONS,
CONNECT: :CONNECT,
PUT: :PUT,
TRACE: :TRACE,
HEAD: :HEAD
}
end
end

Просмотреть файл

@ -1,25 +0,0 @@
require_relative 'request_information'
module MicrosoftKiotaAbstractions
module RequestAdapter
def send_async(request_info, factory, errors_mapping)
raise NotImplementedError.new
end
# TODO we're most likley missing something for enums and collections or at least at the implemenation level
def get_serialization_writer_factory()
raise NotImplementedError.new
end
def set_base_url(base_url)
raise NotImplementedError.new
end
def get_base_url()
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,44 +0,0 @@
module MicrosoftKiotaAbstractions
class RequestHeaders
def initialize()
@headers = Hash.new
end
def add(key, value)
if key.nil? || key.empty? || value.nil? || value.empty? then
raise ArgumentError, 'key and value cannot be nil or empty'
end
existing_value = @headers[key]
if existing_value.nil? then
if value.kind_of?(Array) then
@headers[key] = value
else
@headers[key] = Array[value.to_s]
end
else
if value.kind_of?(Array) then
@headers[key] = existing_value | value
else
existing_value << value.to_s
end
end
end
def get(key)
if key.nil? || key.empty? then
raise ArgumentError, 'key cannot be nil or empty'
end
return @headers[key]
end
def remove(key)
if key.nil? || key.empty? then
raise ArgumentError, 'key cannot be nil or empty'
end
@headers.delete(key)
end
def clear()
@headers.clear()
end
def get_all()
return @headers
end
end
end

Просмотреть файл

@ -1,130 +0,0 @@
require 'uri'
require 'addressable/template'
require_relative 'http_method'
require_relative 'request_headers'
module MicrosoftKiotaAbstractions
class RequestInformation
attr_reader :content, :http_method, :headers
attr_accessor :url_template, :path_parameters, :query_parameters
@@binary_content_type = 'application/octet-stream'
@@content_type_header = 'Content-Type'
@@raw_url_key = 'request-raw-url'
def initialize()
@headers = RequestHeaders.new
@query_parameters = Hash.new
@path_parameters = Hash.new
end
def uri=(arg)
if arg.nil? || arg.empty?
raise ArgumentError, 'arg cannot be nil or empty'
end
self.path_parameters.clear()
self.query_parameters.clear()
@uri = URI(arg)
end
def uri
if @uri != nil
return @uri
else
if self.path_parameters[@@raw_url_key] != nil
self.uri = self.path_parameters[@@raw_url_key]
return @uri
else
template = Addressable::Template.new(@url_template)
return URI(template.expand(self.path_parameters.merge(self.query_parameters)).to_s)
end
end
end
def add_request_options(request_options_to_add)
unless request_options_to_add.nil? then
@request_options ||= Hash.new
unless request_options_to_add.kind_of?(Array) then
request_options_to_add = [request_options_to_add]
end
request_options_to_add.each do |request_option|
key = request_option.get_key
@request_options[key] = request_option
end
end
end
def get_request_options()
if @request_options.nil? then
return []
else
return @request_options.values
end
end
def get_request_option(key)
if @request_options.nil? || key.nil? || key.empty? then
return nil
else
return @request_options[key]
end
end
def remove_request_options(keys)
unless keys.nil? || @request_options.nil? then
unless keys.kind_of?(Array) then
keys = [keys]
end
keys.each do |key|
@request_options.delete(key)
end
end
end
def http_method=(method)
@http_method = HttpMethod::HTTP_METHOD[method]
end
def set_stream_content(value = $stdin)
@content = value
@headers.add(@@content_type_header, @@binary_content_type)
end
def set_content_from_parsable(request_adapter, content_type, values)
begin
writer = request_adapter.get_serialization_writer_factory().get_serialization_writer(content_type)
@headers.add(@@content_type_header, content_type)
if values != nil && values.kind_of?(Array)
writer.write_collection_of_object_values(nil, values)
else
writer.write_object_value(nil, values);
end
this.content = writer.get_serialized_content();
rescue => exception
raise Exception.new "could not serialize payload"
end
end
def add_headers_from_raw_object(h)
h.select{|x,y| @headers.add(x.to_s, y)} unless !h
end
def set_query_string_parameters_from_raw_object(q)
if !q || q.is_a?(Hash) || q.is_a?(Array)
return
end
q.class.instance_methods(false).select{|x|
method_name = x.to_s
unless method_name == "compare_by_identity" || method_name == "get_query_parameter" || method_name.end_with?("=") || method_name.end_with?("?") || method_name.end_with?("!") then
begin
key = q.get_query_parameter(method_name)
rescue => exception
key = method_name
end
value = eval("q.#{method_name}")
self.query_parameters[key] = value unless value.nil?
end
}
end
end
end

Просмотреть файл

@ -1,7 +0,0 @@
module MicrosoftKiotaAbstractions
module RequestOption
def get_key()
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,7 +0,0 @@
module MicrosoftKiotaAbstractions
module AdditionalDataHolder
def additional_data
@additional_data ||= Hash.new
end
end
end

Просмотреть файл

@ -1,209 +0,0 @@
# frozen_string_literal: true
require 'iso8601'
module MicrosoftKiotaAbstractions
# Wrapper Class for ISO8601::Duration
# Integer support for :years, :months, :weeks, :days, :hours, :minutes, :seconds
# Initialize with a hash of symbols to integers eg { :years => 3, :days => 4, seconds: => 2}
# or with an ISO8601 formated string eg "PT3H12M5S".
class ISODuration
attr_reader :years, :months, :weeks, :days, :hours, :minutes, :seconds
UNITS = { :years => 'Y',
:months => 'M',
:weeks => 'W',
:days => 'D',
:hours => 'H',
:minutes => 'M',
:seconds => 'S'}
CONVERSIONS = {
:ms_to_s => 1000,
:s_to_m => 60,
:m_to_h => 60,
:h_to_d => 24,
:d_to_w => 7,
:m_to_y => 12
}
def initialize(input)
if input.is_a? String
@duration_obj = ISO8601::Duration.new(input)
elsif input.is_a? Hash
@duration_obj = parse_hash(input)
else
raise StandardError, 'Must provide initialize ISODuration by providing a hash or an ISO8601-formatted string.'
end
update_member_variables
normalize
end
def string
input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours,
:days => @days, :weeks => @weeks, :months => @months,
:years => @years }
iso_str = 'P'
UNITS.each do |unit, abrev|
iso_str += input[unit].to_s + abrev unless input[unit].zero?
iso_str += 'T' if unit == :days
end
iso_str = iso_str.strip
iso_str = iso_str.chomp('T') if (iso_str[-1]).eql? 'T'
iso_str
end
def normalize
if @seconds >= CONVERSIONS[:s_to_m]
@minutes += (@seconds / CONVERSIONS[:s_to_m]).floor
@seconds %= CONVERSIONS[:s_to_m]
end
if @minutes >= CONVERSIONS[:m_to_h]
@hours += (@minutes / CONVERSIONS[:m_to_h]).floor
@minutes %= CONVERSIONS[:m_to_h]
end
if @hours >= CONVERSIONS[:h_to_d]
@days += (@hours / CONVERSIONS[:h_to_d]).floor
@hours %= CONVERSIONS[:h_to_d]
end
if @days >= CONVERSIONS[:d_to_w] && @months == 0 && @years == 0
@weeks += (@days / CONVERSIONS[:d_to_w]).floor
@days %= CONVERSIONS[:d_to_w]
end
if @months > CONVERSIONS[:m_to_y]
@years += (@months / CONVERSIONS[:m_to_y]).floor
@months %= CONVERSIONS[:m_to_y]
end
end
def seconds=(value)
input = { :seconds => value, :minutes => @minutes, :hours => @hours,
:days => @days, :weeks => @weeks, :months => @months,
:years => @years }
@duration_obj = parse_hash(input)
@seconds = value
normalize
end
def minutes=(value)
input = { :seconds => @seconds, :minutes => value, :hours => @hours,
:days => @days, :weeks => @weeks, :months => @months,
:years => @years }
@duration_obj = parse_hash(input)
@minutes = value
normalize
end
def hours=(value)
input = { :seconds => @seconds, :minutes => @minutes, :hours => value,
:days => @days, :weeks => @weeks, :months => @months,
:years => @years }
@duration_obj = parse_hash(input)
@hours = value
normalize
end
def days=(value)
input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours,
:days => value, :weeks => @weeks, :months => @months,
:years => @years }
@duration_obj = parse_hash(input)
@days = value
normalize
end
def weeks=(value)
input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours,
:days => @days, :weeks => value, :months => @months,
:years => @years }
@duration_obj = parse_hash(input)
@weeks = value
normalize
end
def months=(value)
input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours,
:days => @days, :weeks => @weeks, :months => value,
:years => @years }
@duration_obj = parse_hash(input)
@months = value
normalize
end
def years=(value)
input = { :seconds => @seconds, :minutes => @minutes, :hours => @hours,
:days => @days, :weeks => @weeks, :months => @months,
:years => value }
@duration_obj = parse_hash(input)
@years = value
normalize
end
def abs
@duration_obj = @duration_obj.abs
update_member_variables
return self
end
def +(other)
new_obj = self.duration_obj + other.duration_obj
MicrosoftKiotaAbstractions::ISODuration.new(dur_obj_to_hash(new_obj))
end
def -(other)
new_obj = self.duration_obj - other.duration_obj
MicrosoftKiotaAbstractions::ISODuration.new(dur_obj_to_hash(new_obj))
end
def ==(other)
@duration_obj == other.duration_obj
end
def -@
@duration_obj = -@duration_obj
update_member_variables
end
def eql?(other)
@duration_obj == other.duration_obj
end
protected
attr_accessor :duration_obj
def parse_hash(input)
iso_str = 'P'
input.each do |keys, values|
raise StandardError, "The key #{keys} is not recognized" unless UNITS.key?(keys)
end
UNITS.each do |unit, abrev|
iso_str += input[unit].to_s + abrev if input.key?(unit) && !input[unit].zero?
iso_str += 'T' if unit == :days
end
iso_str = iso_str.strip
iso_str = iso_str.chomp('T') if (iso_str[-1]).eql? 'T'
ISO8601::Duration.new(iso_str)
end
def update_member_variables
@seconds = @duration_obj.seconds.nil? ? 0 : ((@duration_obj.seconds.to_s).split('S')[0]).to_i
@minutes = @duration_obj.minutes.nil? ? 0 : ((@duration_obj.minutes.to_s).split('H')[0]).to_i
@hours = @duration_obj.hours.nil? ? 0 : ((@duration_obj.hours.to_s).split('H')[0]).to_i
@days = @duration_obj.days.nil? ? 0 : ((@duration_obj.days.to_s).split('D')[0]).to_i
@weeks = @duration_obj.weeks.nil? ? 0 : ((@duration_obj.weeks.to_s).split('W')[0]).to_i
@months = @duration_obj.months.nil? ? 0 : ((@duration_obj.months.to_s).split('M')[0]).to_i
@years = @duration_obj.years.nil? ? 0 : ((@duration_obj.years.to_s).split('Y')[0]).to_i
end
def dur_obj_to_hash(dur_obj)
result_hash = {}
result_hash[:seconds] = dur_obj.seconds.nil? ? 0 : ((dur_obj.seconds.to_s).split('S')[0]).to_i
result_hash[:minutes] = dur_obj.minutes.nil? ? 0 : ((dur_obj.minutes.to_s).split('H')[0]).to_i
result_hash[:hours] = dur_obj.hours.nil? ? 0 : ((dur_obj.hours.to_s).split('H')[0]).to_i
result_hash[:days] = dur_obj.days.nil? ? 0 : ((dur_obj.days.to_s).split('D')[0]).to_i
result_hash[:weeks] = dur_obj.weeks.nil? ? 0 : ((dur_obj.weeks.to_s).split('W')[0]).to_i
result_hash[:months] = dur_obj.months.nil? ? 0 : ((dur_obj.months.to_s).split('M')[0]).to_i
result_hash[:years] = dur_obj.years.nil? ? 0 : ((dur_obj.years.to_s).split('Y')[0]).to_i
result_hash
end
end
end

Просмотреть файл

@ -1,11 +0,0 @@
module MicrosoftKiotaAbstractions
module Parsable
def get_field_deserializers
raise NotImplementedError.new
end
def serialize(writer)
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,61 +0,0 @@
module MicrosoftKiotaAbstractions
module ParseNode
def get_string_value()
raise NotImplementedError.new
end
def get_boolean_value()
raise NotImplementedError.new
end
def get_number_value()
raise NotImplementedError.new
end
def get_guid_value()
raise NotImplementedError.new
end
def get_date_value()
raise NotImplementedError.new
end
def get_time_value()
raise NotImplementedError.new
end
def get_date_time_value()
raise NotImplementedError.new
end
def get_duration_value()
raise NotImplementedError.new
end
def get_collection_of_primitive_values()
raise NotImplementedError.new
end
def get_collection_of_object_values(factory)
raise NotImplementedError.new
end
def get_object_value(factory)
raise NotImplementedError.new
end
def assign_field_values(item)
raise NotImplementedError.new
end
def get_enum_value(type)
raise NotImplementedError.new
end
def get_child_node(name)
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,7 +0,0 @@
module MicrosoftKiotaAbstractions
module ParseNodeFactory
def ParseNodeFactory.get_parse_node(content_type, content)
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require_relative 'parse_node_factory'
module MicrosoftKiotaAbstractions
class ParseNodeFactoryRegistry
include ParseNodeFactory
class << self
attr_accessor :default_instance
def default_instance; @default_instance ||= ParseNodeFactoryRegistry.new; end
end
def default_instance
self.class.default_instance
end
def content_type_associated_factories
@content_type_associated_factories ||= Hash.new
end
def get_parse_node(content_type, content)
if !content_type
raise Exception.new 'content type cannot be undefined or empty'
end
if !content
raise Exception.new 'content cannot be undefined or empty'
end
vendor_specific_content_type = content_type.split(';').first
factory = @content_type_associated_factories[vendor_specific_content_type]
if factory
return factory.get_parse_node(vendor_specific_content_type, content)
end
clean_content_type = vendor_specific_content_type.gsub(/[^\/]+\+/i, '')
factory = @content_type_associated_factories[clean_content_type]
if factory
return factory.get_parse_node(clean_content_type, content)
end
raise Exception.new "Content type #{contentType} does not have a factory to be parsed"
end
end
end

Просмотреть файл

@ -1,69 +0,0 @@
module MicrosoftKiotaAbstractions
module SerializationWriter
def write_string_value(key, value)
raise NotImplementedError.new
end
def write_boolean_value(key, value)
raise NotImplementedError.new
end
def write_number_value(key, value)
raise NotImplementedError.new
end
def write_float_value(key, value)
raise NotImplementedError.new
end
def get_date_value(key, value)
raise NotImplementedError.new
end
def write_guid_value(key, value)
raise NotImplementedError.new
end
def write_date_value(key, value)
raise NotImplementedError.new
end
def write_time_value(key, value)
raise NotImplementedError.new
end
def write_date_time_value(key, value)
raise NotImplementedError.new
end
def write_duration_value(key, value)
raise NotImplementedError.new
end
def write_collection_of_primitive_values(key, value)
raise NotImplementedError.new
end
def write_collection_of_object_values(key, value)
raise NotImplementedError.new
end
def write_enum_value(key, value)
raise NotImplementedError.new
end
def get_serialized_content()
raise NotImplementedError.new
end
def write_additional_data(type)
raise NotImplementedError.new
end
def write_any_value(key, value)
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,9 +0,0 @@
module MicrosoftKiotaAbstractions
module SerializationWriterFactory
def get_serialization_writer(content_type)
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,40 +0,0 @@
require_relative 'serialization_writer_factory'
module MicrosoftKiotaAbstractions
class SerializationWriterFactoryRegistry
include SerializationWriterFactory
class << self
attr_accessor :default_instance
def default_instance; @default_instance ||= SerializationWriterFactoryRegistry.new; end
end
def default_instance
self.class.default_instance
end
def content_type_associated_factories
@content_type_associated_factories ||= Hash.new
end
def get_serialization_writer(content_type)
if !content_type
raise Exception.new 'content type cannot be undefined or empty'
end
vendor_specific_content_type = content_type.split(';').first
factory = @content_type_associated_factories[vendor_specific_content_type]
if factory
return factory.get_serialization_writer(vendor_specific_content_type)
end
clean_content_type = vendor_specific_content_type.gsub(/[^\/]+\+/i, '')
factory = @content_type_associated_factories[clean_content_type]
if factory
return factory.get_serialization_writer(clean_content_type)
end
raise Exception.new "Content type #{contentType} does not have a factory to be serialized"
end
end
end

Просмотреть файл

@ -1,5 +0,0 @@
# frozen_string_literal: true
module MicrosoftKiotaAbstractions
VERSION = "0.12.0"
end

Просмотреть файл

@ -1,36 +0,0 @@
# frozen_string_literal: true
require_relative 'lib/microsoft_kiota_abstractions/version'
Gem::Specification.new do |spec|
spec.name = 'microsoft_kiota_abstractions'
spec.version = MicrosoftKiotaAbstractions::VERSION
spec.authors = 'Microsoft Corporation'
spec.email = 'graphsdkpub@microsoft.com'
spec.description = 'Microsoft Kiota Abstractions - Ruby abstractions for building library agnostic http client'
spec.summary = 'The Kiota abstractions are language specific libraries defining the basic constructs Kiota projects need once an SDK has been generated from an OpenAPI definition.'
spec.homepage = 'https://microsoft.github.io/kiota/'
spec.license = 'MIT'
spec.metadata = {
'bug_tracker_uri' => 'https://github.com/microsoft/kiota/issues',
'changelog_uri' => 'https://github.com/microsoft/kiota/blob/main/CHANGELOG.md',
'homepage_uri' => spec.homepage,
'source_code_uri' => 'https://github.com/microsoft/kiota',
'github_repo' => 'ssh://github.com/microsoft/kiota'
}
spec.required_ruby_version = '>= 2.7.0'
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
end
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_runtime_dependency 'addressable', '~> 2.7', '>= 2.7.0'
spec.add_runtime_dependency 'iso8601', '~> 0.13.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
end

Просмотреть файл

@ -1,127 +0,0 @@
# frozen_string_literal: true
require 'uri'
require 'microsoft_kiota_abstractions'
RSpec.describe MicrosoftKiotaAbstractions do
it "has a version number" do
expect(MicrosoftKiotaAbstractions::VERSION).not_to be nil
end
it "tests library method" do
request_obj = MicrosoftKiotaAbstractions::RequestInformation.new
expect(!request_obj).to eq(false)
end
it "creates a anonymous token provider" do
token_provider = MicrosoftKiotaAbstractions::AnonymousAuthenticationProvider.new()
expect(token_provider).not_to be nil
end
it "returns the raw URI when set via setter" do
request_obj = MicrosoftKiotaAbstractions::RequestInformation.new
request_obj.path_parameters["term"] = "search"
request_obj.query_parameters["q1"] = "option1"
request_obj.uri = "https://www.bing.com"
expect(request_obj.uri).to eq(URI("https://www.bing.com"))
expect(request_obj.path_parameters).to eq({})
expect(request_obj.query_parameters).to eq({})
end
it "returns the raw URI when set via raw url parmeter" do
request_obj = MicrosoftKiotaAbstractions::RequestInformation.new
request_obj.path_parameters["request-raw-url"] = "https://www.bing.com"
expect(request_obj.path_parameters).to eq({ "request-raw-url" => "https://www.bing.com"})
request_obj.path_parameters["term"] = "search"
request_obj.query_parameters["q1"] = "option1"
expect(request_obj.uri).to eq(URI("https://www.bing.com"))
expect(request_obj.path_parameters).to eq({})
expect(request_obj.query_parameters).to eq({})
end
it "returns a templated url" do
request_obj = MicrosoftKiotaAbstractions::RequestInformation.new
request_obj.url_template = "https://www.bing.com/{term}{?q1,q2}"
request_obj.path_parameters["term"] = "search"
request_obj.query_parameters["q1"] = "option1"
expect(request_obj.uri).to eq(URI("https://www.bing.com/search?q1=option1"))
end
it "initializes a duration with ISO-formatted string or hash" do
time1 = MicrosoftKiotaAbstractions::ISODuration.new("P2Y1MT2H")
time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 2, :months => 1, :hours => 2 } )
expect(time1).to eq(time2)
end
it "fails on malformed string inputs" do
expect { MicrosoftKiotaAbstractions::ISODuration.new("P2Y1M3WT2H") }.to raise_error ISO8601::Errors::UnknownPattern
end
it "fails on malformed hash inputs" do
expect { MicrosoftKiotaAbstractions::ISODuration.new({ :laughter => 2, :months => 1, :hours => 2 }) }.to raise_error('The key laughter is not recognized')
end
it "handles addition" do
time1 = MicrosoftKiotaAbstractions::ISODuration.new("P2Y1MT2H")
time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 2, :months => 1, :hours => 2 } )
time3 = time1 + time2
expect(time3.string).to eq(MicrosoftKiotaAbstractions::ISODuration.new("P4Y2MT4H").string)
end
it "handles subtraction" do
time1 = MicrosoftKiotaAbstractions::ISODuration.new("P4Y2MT2H")
time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 1, :months => 1, :hours => 2 } )
time3 = time1 - time2
expect(time3.string).to eq(MicrosoftKiotaAbstractions::ISODuration.new("P3Y1M").string)
end
it "handles equality comparisons" do
time1 = MicrosoftKiotaAbstractions::ISODuration.new("P4Y2MT2H")
time2 = MicrosoftKiotaAbstractions::ISODuration.new({ :years => 4, :months => 2, :hours => 2 } )
expect(time1).to eq(time2)
end
it 'initializes empty allowed hosts properly' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new([])
expect(ahv.allowed_hosts).to eq({})
end
it 'initializes non-empty/cased allowed hosts properly' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', 'DOD-graph.microsoft.us'])
valid_hosts = ahv.allowed_hosts
expect(valid_hosts).to eq({'microsoft.com' => true, 'graph.microsoft.com' => true, 'dod-graph.microsoft.us' => true})
end
it 'tests the setter for allowed hosts on allowed hosts validator' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['microsoft.com', 'Graph.microsoft.com', 'DOD-graph.microsoft.us'])
ahv.allowed_hosts = ['MICROSOFT.com', 'GRAPH.microsoft.COM', 'DOD-graph.microsoft.us', 'graph.microsoft.de']
expect(ahv.allowed_hosts).to eq({'microsoft.com' => true, 'graph.microsoft.com' => true, 'dod-graph.microsoft.us' => true, 'graph.microsoft.de' => true})
end
it 'tests url_host_valid? method on malformed and valid urls' do
ahv = MicrosoftKiotaAbstractions::AllowedHostsValidator.new(['www.google.com', 'example.com', 'Graph.microsoft.com',
'DOD-graph.microsoft.us', "cool/groovy/art"])
url1 = ahv.url_host_valid?("https://www.google.com")
url2 = ahv.url_host_valid?("htts://google.com")
url3 = ahv.url_host_valid?("cool/groovy/art")
url4 = ahv.url_host_valid?("https://example.com")
url5 = ahv.url_host_valid?('https%3A%2F%2Fwww.example.com')
url6 = ahv.url_host_valid?('%3A%2F%2F')
expect(url1).to eq(true)
expect(url2).to eq(false)
expect(url3).to eq(false)
expect(url4).to eq(true)
expect(url5).to eq(false)
expect(url5).to eq(false)
expect(url6).to eq(false)
end
it 'tests the default instance for ParseNodeFactoryRegistry is set' do
expect(MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance).to_not be_nil
end
it 'tests the default instance for SerializationWriterFactoryRegistry is set' do
expect(MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance).to_not be_nil
end
end

Просмотреть файл

@ -1,11 +0,0 @@
require 'microsoft_kiota_abstractions'
class ParseNodeFactoryMock
include MicrosoftKiotaAbstractions::ParseNodeFactory
def get_valid_content_type
'application/json'
end
def get_parse_node(clean_content_type, content)
return {}
end
end

Просмотреть файл

@ -1,16 +0,0 @@
require 'microsoft_kiota_abstractions'
require_relative 'parse_node_factory_mock'
RSpec.describe MicrosoftKiotaAbstractions do
values = []
values << "application/json"
values << "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
values << "application/vnd.github.mercy-preview+json"
values << "application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
serialized_value = "[1]"
MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.content_type_associated_factories["application/json"] = ParseNodeFactoryMock.new
it "gets the parse node" do
values.each do |value|
expect(MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance.get_parse_node(value, serialized_value)).not_to be nil
end
end
end

Просмотреть файл

@ -1,49 +0,0 @@
class QueryParametersMock
##
# Include count of items
attr_accessor :count
##
# Filter items by property values
attr_accessor :filter
##
# Order items by property values
attr_accessor :orderby
##
# Search items by search phrases
attr_accessor :search
##
# Select properties to be returned
attr_accessor :select
##
# Skip the first n items
attr_accessor :skip
##
# Show only the first n items
attr_accessor :top
##
## Maps the query parameters names to their encoded names for the URI template parsing.
## @param originalName The original query parameter name in the class.
## @return a string
##
def get_query_parameter(original_name)
case original_name
when "count"
return "%24count"
when "filter"
return "%24filter"
when "orderby"
return "%24orderby"
when "search"
return "%24search"
when "select"
return "%24select"
when "skip"
return "%24skip"
when "top"
return "%24top"
else
return originalName
end
end
end

Просмотреть файл

@ -1,42 +0,0 @@
require 'microsoft_kiota_abstractions'
RSpec.describe MicrosoftKiotaAbstractions do
it "adds a request header to the request information" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
request_info.headers.add("key", "value")
expect(request_info.headers.get_all.length).to eq(1)
expect(request_info.headers.get("key").length).to eq(1)
expect(request_info.headers.get("key").first).to eq("value")
end
it "adds a request header to the request information when one value is already present" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
request_info.headers.add("key", "value")
request_info.headers.add("key", "value2")
expect(request_info.headers.get_all.length).to eq(1)
expect(request_info.headers.get("key").length).to eq(2)
expect(request_info.headers.get("key").first).to eq("value")
expect(request_info.headers.get("key").last).to eq("value2")
end
it "removes a request header from the request information" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
request_info.headers.add("key", "value")
expect(request_info.headers.get_all.length).to eq(1)
request_info.headers.remove("key")
expect(request_info.headers.get_all.length).to eq(0)
end
it "doesnt fail when removing a value if none are present" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
request_info.headers.remove("key")
expect(request_info.headers.get_all.length).to eq(0)
end
it "clears the request headers from the request information" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
request_info.headers.add("key", "value")
expect(request_info.headers.get_all.length).to eq(1)
request_info.headers.clear
expect(request_info.headers.get_all.length).to eq(0)
end
end

Просмотреть файл

@ -1,45 +0,0 @@
require 'microsoft_kiota_abstractions'
require_relative 'request_option_mock'
require_relative 'query_parameters_mock'
RSpec.describe MicrosoftKiotaAbstractions do
it "adds a request option to the request information" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
mock_option = RequestOptionMock.new
mock_option.value = "value"
request_info.add_request_options(mock_option)
expect(request_info.get_request_options().length).to eq(1)
expect(request_info.get_request_option("key")).to eq(mock_option)
end
it "removes a request option from the request information" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
mock_option = RequestOptionMock.new
mock_option.value = "value"
request_info.add_request_options(mock_option)
expect(request_info.get_request_options().length).to eq(1)
request_info.remove_request_options("key")
expect(request_info.get_request_options().length).to eq(0)
end
it "adds query parameters with their escaped values" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
query_parameters = QueryParametersMock.new
query_parameters.select = "foo,bar"
request_info.set_query_string_parameters_from_raw_object(query_parameters)
expect(request_info.query_parameters.length).to eq(1)
expect(request_info.query_parameters["%24select"]).to eq("foo,bar")
expect(request_info.query_parameters["select"]).to be_nil
end
it "doesn't fail adding query parameters with anonymous object" do
request_info = MicrosoftKiotaAbstractions::RequestInformation.new
query_parameters = {
select: "foo,bar"
}
request_info.set_query_string_parameters_from_raw_object(query_parameters)
expect(request_info.query_parameters.length).to eq(0)
end
end

Просмотреть файл

@ -1,8 +0,0 @@
require 'microsoft_kiota_abstractions'
class RequestOptionMock
include MicrosoftKiotaAbstractions::RequestOption
attr_accessor :value
def get_key()
return "key"
end
end

Просмотреть файл

@ -1,11 +0,0 @@
require 'microsoft_kiota_abstractions'
class SerializationWriterFactoryMock
include MicrosoftKiotaAbstractions::SerializationWriterFactory
def get_valid_content_type
'application/json'
end
def get_serialization_writer(clean_content)
return {}
end
end

Просмотреть файл

@ -1,15 +0,0 @@
require 'microsoft_kiota_abstractions'
require_relative 'serialization_writer_factory_mock'
RSpec.describe MicrosoftKiotaAbstractions do
values = []
values << "application/json"
values << "application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
values << "application/vnd.github.mercy-preview+json"
values << "application/vnd.github.mercy-preview+json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8"
MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.content_type_associated_factories["application/json"] = SerializationWriterFactoryMock.new
it "gets the serialization writer" do
values.each do |value|
expect(MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance.get_serialization_writer(value)).not_to be nil
end
end
end

Просмотреть файл

@ -1,13 +0,0 @@
# frozen_string_literal: true
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
end

Просмотреть файл

@ -6,6 +6,7 @@ Your project will need a reference to the abstraction package to build and run,
- [Dotnet](https://github.com/microsoft/kiota-authentication-azure-dotnet): relies on [Azure identity](https://www.nuget.org/packages/Azure.Identity).
- [Go](https://github.com/microsoft/kiota-authentication-azure-go/): relies on [Azure identity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity)
- [Java](https://github.com/microsoft/kiota-java/tree/main/components/authentication/azure) : relies on [Azure identity](https://docs.microsoft.com/en-us/java/api/overview/azure/identity-readme?view=azure-java-stable).
- [Ruby](https://github.com/microsoft/kiota-authentication-oauth-ruby/): relies on [OAuth2](https://rubygems.org/gems/oauth2)
- [TypeScript](https://github.com/microsoft/kiota-typescript/tree/main/packages/authentication/azure) : relies on [Azure identity](https://www.npmjs.com/package/@azure/identity).
- [Python](https://github.com/microsoft/kiota-authentication-azure-python) : relies on [Azure identity](https://pypi.org/project/azure-identity/).
- [PHP](https://github.com/microsoft/kiota-authentication-phpleague-php) : relies on [The PHP League OAuth 2 client](https://packagist.org/packages/league/oauth2-client) to authenticate against the Azure Identity platform.

Просмотреть файл

@ -1,13 +0,0 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
# rspec failure tracking
.rspec_status
Gemfile.lock

Просмотреть файл

@ -1,10 +0,0 @@
# frozen_string_literal: true
source 'https://rubygems.org'
source "https://rubygems.pkg.github.com/microsoft"
# Specify your gem's dependencies in microsoft_kiota_authentication.gemspec
gemspec
# gem "microsoft_kiota_abstractions", path: "../../../../abstractions/ruby/microsoft_kiota_abstractions"

Просмотреть файл

@ -1,50 +0,0 @@
# MicrosoftKiotaAuthenticationOAuth
![Ruby](https://github.com/microsoft/kiota/actions/workflows/authentication-ruby-oauth.yml/badge.svg)
## Using the Authentication implementations
Option 1: Bundler config
```shell
bundle config https://rubygems.pkg.github.com/microsoft/kiota USERNAME:TOKEN
```
Option 2: Configuring `~/.gemrc` file
```
---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://rubygems.org/
- https://USERNAME:TOKEN@rubygems.pkg.github.com/microsoft/kiota
:update_sources: true
:verbose: true
```
## Installation
Add this line to your application's Gemfile:
```ruby
source "https://rubygems.pkg.github.com/microsoft" do
gem "microsoft_kiota_authentication_oauth", "0.1.0"
end
```
And then execute:
```shell
bundle install
```
Or install it yourself as:
```shell
gem install microsoft_kiota_authentication_oauth --version "0.1.0" --source "https://{USERNAME}{PASSWORD/TOKEN}rubygems.pkg.github.com/microsoft"
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/microsoft/kiota.

Просмотреть файл

@ -1,9 +0,0 @@
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec

Просмотреть файл

@ -1,14 +0,0 @@
# frozen_string_literal: true
require_relative "microsoft_kiota_authentication_oauth/version"
require_relative "microsoft_kiota_authentication_oauth/contexts/authorization_code_context"
require_relative "microsoft_kiota_authentication_oauth/contexts/client_credential_context"
require_relative "microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context"
require_relative "microsoft_kiota_authentication_oauth/contexts/oauth_context"
require_relative "microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow"
require_relative "microsoft_kiota_authentication_oauth/extensions/oauth2_ext"
require_relative "microsoft_kiota_authentication_oauth/oauth_access_token_provider"
require_relative "microsoft_kiota_authentication_oauth/oauth_authentication_provider"
module MicrosoftKiotaAuthenticationOAuth
end

Просмотреть файл

@ -1,87 +0,0 @@
# frozen_string_literal: true
require 'oauth2'
require_relative './oauth_context'
module MicrosoftKiotaAuthenticationOAuth
# Token request context class for the authorization code grant type.
class AuthorizationCodeContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext
attr_reader :grant_type, :redirect_uri, :additional_params,
:tenant_id, :client_id, :client_secret, :auth_code, :oauth_provider
attr_writer :scopes
# This is the initializer for AuthorizationCodeContext, the token request context when
# using the authorization code grant flow.
# :params
# tenant_id: a string containing the tenant id
# client_id: a string containing the client id
# client_secret: a string containing the client secret
# redirect_uri: a string containing redirect_uri
# auth_code: a string containting the auth code; default is nil, can be updated post-initialization
def initialize(tenant_id, client_id, client_secret, redirect_uri, auth_code = nil)
raise StandardError, 'redirect_uri cannot be nil/empty' if redirect_uri.nil? || redirect_uri.empty?
@tenant_id = tenant_id
@client_id = client_id
@client_secret = client_secret
@auth_code = auth_code
@redirect_uri = redirect_uri
@scopes = nil
@oauth_provider = nil
@grant_type = 'authorization code'
if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @tenant_id.empty? || @client_id.empty? || @client_secret.empty?
raise StandardError, 'tenant_id, client_id, and client_secret cannot be empty'
end
end
# setter for auth_code
def auth_code=(code)
raise StandardError, 'auth_code cannot be empty/nil.' if code.nil? || code.empty?
@auth_code = code
end
# This function generates an authorize URL for obtaining the auth code.
# :params
# scopes: an array of stings, where each string is a scope
# additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
# default is empty hash
def generate_authorize_url(scopes, additional_params = {})
@additional_params = additional_params
self.initialize_scopes(scopes)
self.initialize_oauth_provider
parameters = { scope: @scopes, redirect_uri: @redirect_uri, access_type: 'offline', prompt: 'consent'}
parameters = parameters.merge(additional_params)
@oauth_provider.auth_code.authorize_url(parameters)
end
def get_token
@oauth_provider.auth_code.get_token(@auth_code, redirect_uri: @redirect_uri)
end
def initialize_oauth_provider
@oauth_provider = OAuth2::Client.new(@client_id, @client_secret,
site: 'https://login.microsoftonline.com',
authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize",
token_url: "/#{@tenant_id}/oauth2/v2.0/token")
end
def initialize_scopes(scopes)
scope_str = ''
scopes.each { |scope| scope_str += scope + ' '}
raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty?
scope_str = 'offline_access ' + scope_str
@scopes = scope_str
end
private
attr_writer :grant_type, :redirect_uri, :additional_params,
:tenant_id, :client_id, :client_secret, :oauth_provider
end
end

Просмотреть файл

@ -1,59 +0,0 @@
# frozen_string_literal: true
require 'oauth2'
require_relative './oauth_context'
module MicrosoftKiotaAuthenticationOAuth
# Token request context class for the client credential grant type.
class ClientCredentialContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext
attr_reader :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider
attr_writer :scopes
# This is the initializer for ClientCredentialContext, the token request context when
# using the client credential grant flow.
# :params
# tenant_id: a string containing the tenant id
# client_id: a string containing the client id
# client_secret: a string containing the client secret
# additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
# default is empty hash
def initialize(tenant_id, client_id, client_secret, additional_params = {})
@tenant_id = tenant_id
@client_id = client_id
@client_secret = client_secret
@additional_params = additional_params
@scopes = nil
@oauth_provider = nil
@grant_type = 'client credential'
if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @tenant_id.empty? || @client_id.empty? || @client_secret.empty?
raise StandardError, 'tenant_id, client_id and client_secret cannot be empty'
end
end
def get_token
@oauth_provider.client_credentials.get_token({ scope: @scopes })
end
def initialize_oauth_provider
@oauth_provider = OAuth2::Client.new(@client_id, @client_secret,
site: 'https://login.microsoftonline.com',
authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize",
token_url: "/#{@tenant_id}/oauth2/v2.0/token")
end
# Function to initialize the scope for the client credential context object.
# This function forces to default since gradual consent is not supported
# for this flow.
def initialize_scopes(scopes = [])
scope_str = 'https://graph.microsoft.com/.default'
@scopes = scope_str
end
private
attr_writer :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider
end
end

Просмотреть файл

@ -1,30 +0,0 @@
# frozen_string_literal: true
require 'oauth2'
require_relative './oauth_custom_flow'
module MicrosoftKiotaAuthenticationOAuth
# Base class for token request contexs.
class OAuthContext
attr_accessor :scopes
attr_reader :oauth_provider
include MicrosoftKiotaAuthenticationOAuth::OAuthCustomFlow
def get_token
OAuthCustomFlow.get_token
end
def initialize_scopes(scopes = [])
@scopes = OAuthCustomFlow.get_scopes
end
def initialize_oauth_provider
@oauth_provider = OAuthCustomFlow.get_oauth_provider
end
private
attr_writer :oauth_provider
end
end

Просмотреть файл

@ -1,27 +0,0 @@
# frozen_string_literal: true
require 'oauth2'
module MicrosoftKiotaAuthenticationOAuth
# Module that can be optionally implemented for supporting custom token grant flows.
# To use a cutsom token grant flow, implement the functions below and
# use MicrosoftKiotaAuthenticationOAuth::OAuthContext.new as your token_request_context
# object for the use by the MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider
module OAuthCustomFlow
# Function that returns an oauth client using the oauth2 gem
def self.get_oauth_provider
raise NotImplementedError.new
end
# Function that returns a space seperated string of scopes, beginning with
# the offline_access scope if relevant
def self.get_scopes
raise NotImplementedError.new
end
# Function that returns the access token
def self.get_token
raise NotImplementedError.new
end
end
end

Просмотреть файл

@ -1,72 +0,0 @@
# frozen_string_literal: true
require 'oauth2'
require_relative './oauth_context'
module MicrosoftKiotaAuthenticationOAuth
# Token request context class for the on behlaf of grant type.
class OnBehalfOfContext < MicrosoftKiotaAuthenticationOAuth::OAuthContext
attr_reader :grant_type, :additional_params, :tenant_id, :client_id, :client_secret, :oauth_provider
attr_writer :scopes
# This is the initializer for OnBehalfOfContext, the token request context when
# using the client credential grant flow.
# :params
# tenant_id: a string containing the tenant id
# client_id: a string containing the client id
# client_secret: a string containing the client secret
# assertion: string containing assertion (access token used in the request)
# additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
# default is empty hash
def initialize(tenant_id, client_id, client_secret, assertion, additional_params = {})
raise StandardError, 'assertion cannot be empty' if assertion.nil? || assertion.empty?
@tenant_id = tenant_id
@client_id = client_id
@client_secret = client_secret
@assertion = assertion
@additional_params = additional_params
@scopes = nil
@oauth_provider = nil
@grant_type = 'urn:ietf:params:Oauth:grant-type:jwt-bearer'
if @tenant_id.nil? || @client_id.nil? || @client_secret.nil? || @client_secret.empty? || @tenant_id.empty? || @client_id.empty?
raise StandardError, 'tenant_id, client_secret, and client_id cannot be empty'
end
end
def get_token
params = {
grant_type: @grant_type,
assertion: @assertion,
scope: @scopes,
requested_token_use: 'on_behalf_of'
}
@oauth_provider.on_behalf_of.get_token(params)
end
def initialize_oauth_provider
@oauth_provider = OAuth2::Client.new(@client_id, @client_secret,
site: 'https://login.microsoftonline.com',
authorize_url: "/#{@tenant_id}/oauth2/v2.0/authorize",
token_url: "/#{@tenant_id}/oauth2/v2.0/token")
end
def initialize_scopes(scopes)
scope_str = ''
scopes.each { |scope| scope_str += scope + ' '}
raise StandardError, 'scopes cannot be empty/nil.' if scope_str.empty?
scope_str = 'offline_access ' + scope_str
@scopes = scope_str
end
private
attr_writer :grant_type, :additional_params, :tenant_id, :client_id,
:client_secret, :oauth_provider
end
end

Просмотреть файл

@ -1,22 +0,0 @@
# frozen_string_literal: true
require 'oauth2'
# Extension of Oauth2 Library to Include On Behalf Of Grant Type
module OAuth2
module Strategy
class OnBehalfOf < Base
def get_token(params, response_opts = {})
@client.get_token(params, response_opts)
end
end
end
end
module OAuth2
class Client
def on_behalf_of
@on_behalf_of ||= OAuth2::Strategy::OnBehalfOf.new(self)
end
end
end

Просмотреть файл

@ -1,81 +0,0 @@
# frozen_string_literal: true
require 'microsoft_kiota_abstractions'
require 'oauth2'
require_relative 'extensions/oauth2_ext'
require_relative 'contexts/client_credential_context'
require_relative 'contexts/authorization_code_context'
require_relative 'contexts/on_behalf_of_context'
require_relative 'contexts/oauth_context'
require_relative 'contexts/oauth_custom_flow'
module MicrosoftKiotaAuthenticationOAuth
# Access Token Provider class implementation
class OAuthAccessTokenProvider
# This is the initializer for OAuthAccessTokenProvider.
# :params
# token_request_context: a instance of one of our token request context or a custom implementation
# allowed_hosts: an array of strings, where each string is an allowed host, default is empty
# scopes: an array of strings, where each string is a scope, default is empty array
def initialize(token_request_context, allowed_hosts = [], scopes = [])
raise StandardError, 'Parameter token_request_context cannot be nil.' if token_request_context.nil?
@token_request_context = token_request_context
unless @token_request_context.is_a?(MicrosoftKiotaAuthenticationOAuth::OAuthContext)
raise StandardError, 'Parameter token_request_context must be an instance of one of our grant flow context classes.'
end
@cached_token = nil
@host_validator = if allowed_hosts.nil? || allowed_hosts.size.zero?
MicrsoftKiotaAbstractions::AllowedHostsValidator.new(['graph.microsoft.com', 'graph.microsoft.us', 'dod-graph.microsoft.us',
'graph.microsoft.de', 'microsoftgraph.chinacloudapi.cn',
'canary.graph.microsoft.com'])
else
MicrosoftKiotaAbstractions::AllowedHostsValidator.new(allowed_hosts)
end
@token_request_context.initialize_oauth_provider
@token_request_context.initialize_scopes(scopes)
end
# This function obtains the authorization token.
# :params
# uri: a string containing the uri
# additional_params: hash of symbols to string values, ie { response_mode: 'fragment', prompt: 'login' }
# default is empty hash
def get_authorization_token(uri, additional_properties = {})
return nil if !uri || !@host_validator.url_host_valid?(uri)
parsed_url = URI(uri)
raise StandardError, 'Only https is supported' if parsed_url.scheme != 'https'
Fiber.new do
if @cached_token
token = OAuth2::AccessToken.from_hash(@token_request_context.oauth_provider, @cached_token)
return token.token if !token.nil? && !token.expired?
if token.expired?
token = token.refresh!
@cached_token = token.to_hash
return token.token
end
end
token = nil
token = @token_request_context.get_token
@cached_token = token.to_hash unless token.nil?
return token.token unless token.nil?
end
end
attr_reader :scopes, :host_validator
protected
attr_writer :host_validator, :token_credential, :scopes, :cached_token
end
end

Просмотреть файл

@ -1,10 +0,0 @@
require 'microsoft_kiota_abstractions'
require_relative './oauth_access_token_provider'
module MicrosoftKiotaAuthenticationOAuth
class OAuthAuthenticationProvider < MicrosoftKiotaAbstractions::BaseBearerTokenAuthenticationProvider
def initialize(token_request_context, allowed_hosts, scopes)
super(MicrosoftKiotaAuthenticationOAuth::OAuthAccessTokenProvider.new(token_request_context, allowed_hosts, scopes))
end
end
end

Просмотреть файл

@ -1,5 +0,0 @@
# frozen_string_literal: true
module MicrosoftKiotaAuthenticationOAuth
VERSION = "0.5.0"
end

Просмотреть файл

@ -1,38 +0,0 @@
# frozen_string_literal: true
require_relative "lib/microsoft_kiota_authentication_oauth/version"
Gem::Specification.new do |spec|
spec.name = "microsoft_kiota_authentication_oauth"
spec.version = MicrosoftKiotaAuthenticationOAuth::VERSION
spec.authors = 'Microsoft Corporation'
spec.email = 'graphsdkpub@microsoft.com'
spec.description = 'Kiota Authentication implementation with oauth2'
spec.summary = 'Microsoft Kiota Authentication OAuth - Kiota Ruby Authentication OAuth library'
spec.homepage = 'https://microsoft.github.io/kiota/'
spec.license = 'MIT'
spec.metadata = {
'bug_tracker_uri' => 'https://github.com/microsoft/kiota/issues',
'changelog_uri' => 'https://github.com/microsoft/kiota/blob/main/CHANGELOG.md',
'homepage_uri' => spec.homepage,
'source_code_uri' => 'https://github.com/microsoft/kiota',
'github_repo' => 'ssh://github.com/microsoft/kiota'
}
spec.required_ruby_version = ">= 2.7.0"
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
end
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.12.0', '>= 0.12.0'
spec.add_runtime_dependency 'oauth2', '~> 2.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
end

Просмотреть файл

@ -1,43 +0,0 @@
# frozen_string_literal: true
require 'uri'
require_relative 'spec_helper'
RSpec.describe MicrosoftKiotaAuthenticationOAuth do
it '(client credential context) throws when tenant_id/client_secret is nil/empty' do
expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new(nil, nil, nil, {}) }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', {}) }.not_to raise_error
expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('', 'client_id', 'client_secret', {}) }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', '', 'client_secret', {}) }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', '', {}) }.to raise_error(StandardError)
end
it '(auth code context) throws when tenant_id/client_secret is nil/empty' do
expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new(nil, nil, nil, nil) }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', 'redirect_uri') }.not_to raise_error
expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('', 'client_id', 'client_secret', 'redirect_uri', 'code') }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', '') }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', '', 'redirect_uri') }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', '', 'client_secret', 'redirect_uri') }.to raise_error(StandardError)
end
it '(on behalf of) throws when tenant_id/client_secret is nil/empty' do
expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new(nil, nil, nil, nil) }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', 'assertion') }.not_to raise_error
expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('', 'client_id', 'client_secret', 'assertion') }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', '', 'client_secret', 'assertion') }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', '', 'assertion') }.to raise_error(StandardError)
expect { MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', '') }.to raise_error(StandardError)
end
it 'throws when OAuthContext is used, but a custom flow is not implemented' do
expect { MicrosoftKiotaAuthenticationOAuth::OAuthContext.get_token }.to raise_error(NoMethodError)
end
it 'recognizes contexts as an OAuthContext' do
expect(MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new('tenant_id', 'client_id', 'client_secret', {}).is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true)
expect(MicrosoftKiotaAuthenticationOAuth::OnBehalfOfContext.new('tenant_id', 'client_id', 'client_secret', 'assertion').is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true)
expect(MicrosoftKiotaAuthenticationOAuth::AuthorizationCodeContext.new('tenant_id', 'client_id', 'client_secret', 'redirect_uri').is_a? MicrosoftKiotaAuthenticationOAuth::OAuthContext).to eq(true)
end
end

Просмотреть файл

@ -1,20 +0,0 @@
# frozen_string_literal: true
require 'microsoft_kiota_abstractions'
require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/client_credential_context'
require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/authorization_code_context'
require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/on_behalf_of_context'
require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/oauth_context'
require_relative '../lib/microsoft_kiota_authentication_oauth/contexts/oauth_custom_flow'
require_relative '../lib/microsoft_kiota_authentication_oauth/extensions/oauth2_ext'
require_relative '../lib/microsoft_kiota_authentication_oauth/oauth_access_token_provider'
require_relative '../lib/microsoft_kiota_authentication_oauth/oauth_authentication_provider'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
end

Просмотреть файл

@ -10,13 +10,9 @@ parent: Get started
## Initializing target project
Before you can compile and run the target project, you will need to initialize it. After initializing the test project, you will need to add references to the [abstraction](https://github.com/microsoft/kiota/tree/main/abstractions/ruby/microsoft_kiota_abstractions), [authentication](https://github.com/microsoft/kiota/tree/main/authentication/ruby/oauth/microsoft_kiota_authentication_oauth), [http](https://github.com/microsoft/kiota/tree/main/http/ruby/nethttp/microsoft_kiota_nethttplibrary), and [serialization](https://github.com/microsoft/kiota/tree/main/serialization/ruby/json/microsoft_kiota_serialization) packages from the GitHub feed.
Before you can compile and run the target project, you will need to initialize it. After initializing the test project, you will need to add references to the [abstraction](https://github.com/microsoft/kiota-abstractions-ruby), [authentication](https://github.com/microsoft/kiota-authentication-oauth-ruby), [http](https://github.com/microsoft/kiota-http-ruby), and [serialization JSON](https://github.com/microsoft/kiota-serialization-json-ruby) packages.
### Getting access to the packages
> **Note:** This is a temporary requirement while Kiota is in preview.
#### Install Bundler
### Install Bundler
1. To install bundler, execute the following line in the root directory of your project:
@ -26,44 +22,28 @@ Before you can compile and run the target project, you will need to initialize i
2. Create a gemfile named **Gemfile** in the root directory of your project.
#### Getting your Personal Access Token
1. Navigate to [New personal access token](https://github.com/settings/tokens/new) and generate a new token. (permissions: `package:read`, `repo`).
2. Copy the token, you will need it later.
3. Enable SSO for the Microsoft org on the token if you are a Microsoft employee.
#### Installing the necessary packages
### Installing the necessary packages
1. In your project, update your `Gemfile` with the required information. Add these lines to your application's Gemfile:
````ruby
source 'https://rubygems.org'
git_source(:github) { |repo_name| "https://rubygems.pkg.github.com/microsoft" }
source "https://rubygems.pkg.github.com/microsoft" do
gem "microsoft_kiota_abstractions"
gem "microsoft_kiota_serialization"
gem "microsoft_kiota_authentication_oauth"
gem "microsoft_kiota_nethttplibrary"
end
gem "microsoft_kiota_abstractions"
gem "microsoft_kiota_serialization_json"
gem "microsoft_kiota_authentication_oauth"
gem "microsoft_kiota_faraday"
````
Only the first package, `microsoft_kiota_abstractions`, is required. The other packages provide default implementations that you can choose to replace with your own implementations if you wish.
2. Use `bundler config` to globally specify the authentication information.
Execute this line:
````shell
bundle config https://rubygems.pkg.github.com/microsoft/kiota USERNAME:TOKEN
````
3. Finally, install your gems. Execute this line:
2. Finally, install your gems. Execute this line:
````shell
bundle install
````
### Generating the SDK
### Generating the client
Kiota generates SDKs from OpenAPI documents. Create a file named **getme.yml** and add the contents of the [Sample OpenAPI description](https://github.com/microsoft/kiota/blob/main/docs/get-started/reference-openapi.md).
@ -103,10 +83,10 @@ Follow the instructions in [Register an application for Microsoft identity platf
````ruby
# frozen_string_literal: true
require 'microsoft_kiota_serialization'
require 'microsoft_kiota_serialization_json'
require 'microsoft_kiota_abstractions'
require 'microsoft_kiota_authentication_oauth'
require 'microsoft_kiota_nethttplibrary'
require 'microsoft_kiota_faraday'
require_relative './client/api_client'
tenant_id = 'TENANT_ID'
@ -123,10 +103,10 @@ Follow the instructions in [Register an application for Microsoft identity platf
auth_provider = MicrosoftKiotaAuthenticationOAuth::OAuthAuthenticationProvider.new(token_request_context, allowed_hosts, graph_scopes)
request_adapter = MicrosoftKiotaNethttplibrary::NetHttpRequestAdapter.new(auth_provider, MicrosoftKiotaSerialization::JsonParseNodeFactory.new, MicrosoftKiotaSerialization::JsonSerializationWriterFactory.new)
request_adapter = MicrosoftKiotaNethttplibrary::NetHttpRequestAdapter.new(auth_provider)
client = Graph::ApiClient.new(request_adapter)
me = client.me.get
me = client.me.get.resume
puts "Hi! My name is #{me.display_name}, and my ID is #{me.id}."
````

Просмотреть файл

@ -6,6 +6,7 @@ Your project will need a reference to the abstraction package to build and run,
- [Dotnet](https://github.com/microsoft/kiota-http-dotnet): relies on [HttpClient](https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-7.0).
- [Go](https://github.com/microsoft/kiota-http-go/): relies on [NetHttp](https://pkg.go.dev/net/http).
- [Java](https://github.com/microsoft/kiota-java/tree/main/components/http/okHttp) : relies on [OkHttp](https://square.github.io/okhttp/).
- [Ruby](https://github.com/microsoft/kiota-http-ruby/): relies on [Faraday](https://github.com/lostisland/faraday).
- [TypeScript](https://github.com/microsoft/kiota-typescript/tree/main/packages/http/fetch) : relies on [node-fetch](https://www.npmjs.com/package/cross-fetch) for node users and global browser fetch for browser applications.
- [PHP](https://github.com/microsoft/kiota-http-guzzle-php) : relies on [Guzzle](http://guzzlephp.org/)
- [Python](https://github.com/microsoft/kiota-http-python) : relies on [Httpx](https://www.python-httpx.org/).

Просмотреть файл

@ -1,13 +0,0 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
# rspec failure tracking
.rspec_status
Gemfile.lock

Просмотреть файл

@ -1,3 +0,0 @@
--format documentation
--color
--require spec_helper

Просмотреть файл

@ -1,8 +0,0 @@
# frozen_string_literal: true
source "https://rubygems.org"
source 'https://rubygems.pkg.github.com/microsoft'
gemspec
# gem "microsoft_kiota_abstractions", path: "../../../../abstractions/ruby/microsoft_kiota_abstractions"

Просмотреть файл

@ -1,50 +0,0 @@
# MicrosoftKiotaFaraday
![Ruby](https://github.com/microsoft/kiota/actions/workflows/http-ruby-nethttp.yml/badge.svg)
## Using the core implementations
Option 1: Bundler config
```shell
bundle config https://rubygems.pkg.github.com/microsoft/kiota USERNAME:TOKEN
```
Option 2: Configuring `~/.gemrc` file
```
---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://rubygems.org/
- https://USERNAME:TOKEN@rubygems.pkg.github.com/microsoft/kiota
:update_sources: true
:verbose: true
```
## Installation
Add this line to your application's Gemfile:
```ruby
source "https://rubygems.pkg.github.com/microsoft" do
gem "microsoft_kiota_nethttplibrary", "0.4.0"
end
```
And then execute:
```shell
bundle install
```
Or install it yourself as:
```shell
gem install microsoft_kiota_faraday --version "0.4.0" --source "https://{USERNAME}{PASSWORD/TOKEN}rubygems.pkg.github.com/microsoft"
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/microsoft/kiota.

Просмотреть файл

@ -1,10 +0,0 @@
# frozen_string_literal: true
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec

Просмотреть файл

@ -1,11 +0,0 @@
# frozen_string_literal: true
require_relative 'microsoft_kiota_faraday/version'
require_relative 'microsoft_kiota_faraday/middleware/response_handler_option'
require_relative 'microsoft_kiota_faraday/middleware/parameters_name_decoding_option'
require_relative 'microsoft_kiota_faraday/middleware/parameters_name_decoding_handler'
require_relative 'microsoft_kiota_faraday/kiota_client_factory'
require_relative 'microsoft_kiota_faraday/faraday_request_adapter'
module MicrosoftKiotaFaraday
end

Просмотреть файл

@ -1,151 +0,0 @@
require 'microsoft_kiota_abstractions'
require 'faraday'
require 'net/http'
require_relative 'kiota_client_factory'
require_relative 'middleware/response_handler_option'
module MicrosoftKiotaFaraday
class FaradayRequestAdapter
include MicrosoftKiotaAbstractions::RequestAdapter
attr_accessor :authentication_provider, :content_type_header_key, :parse_node_factory, :serialization_writer_factory, :client
def initialize(authentication_provider, parse_node_factory=MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance, serialization_writer_factory=MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance, client = KiotaClientFactory::get_default_http_client)
if !authentication_provider
raise StandardError , 'authentication provider cannot be null'
end
@authentication_provider = authentication_provider
@content_type_header_key = 'Content-Type'
@parse_node_factory = parse_node_factory
if @parse_node_factory.nil?
@parse_node_factory = MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry.default_instance
end
@serialization_writer_factory = serialization_writer_factory
if @serialization_writer_factory.nil?
@serialization_writer_factory = MicrosoftKiotaAbstractions::SerializationWriterFactoryRegistry.default_instance
end
@client = client
if @client.nil?
@client = KiotaClientFactory::get_default_http_client
end
@base_url = ''
end
def set_base_url(base_url)
@base_url = base_url
end
def get_base_url()
@base_url
end
def get_serialization_writer_factory()
@serialization_writer_factory
end
def send_async(request_info, factory, errors_mapping)
raise StandardError, 'request_info cannot be null' unless request_info
raise StandardError, 'factory cannot be null' unless factory
Fiber.new do
@authentication_provider.authenticate_request(request_info).resume
request = self.get_request_from_request_info(request_info)
response = @client.run_request(request.http_method, request.path, request.body, request.headers)
response_handler = self.get_response_handler(request_info)
response_handler.call(response).resume unless response_handler.nil?
self.throw_if_failed_reponse(response, errors_mapping)
root_node = self.get_root_parse_node(response)
root_node.get_object_value(factory)
end
end
def get_response_handler(request_info)
option = request_info.get_request_option(MicrosoftKiotaFaraday::Middleware::ResponseHandlerOption::RESPONSE_HANDLER_KEY) unless request_info.nil?
return option.async_callback unless !option || option.nil?
end
def get_root_parse_node(response)
raise StandardError, 'response cannot be null' unless response
response_content_type = self.get_response_content_type(response);
raise StandardError, 'no response content type found for deserialization' unless response_content_type
return @parse_node_factory.get_parse_node(response_content_type, response.body)
end
def throw_if_failed_reponse(response, errors_mapping)
raise StandardError, 'response cannot be null' unless response
status_code = response.status;
if status_code < 400 then
return
end
error_factory = errors_mapping[status_code] unless errors_mapping.nil?
error_factory = errors_mapping['4XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code > 500
error_factory = errors_mapping['5XX'] unless !error_factory.nil? || errors_mapping.nil? || status_code < 500 || status_code > 600
raise MicrosoftKiotaAbstractions::ApiError, 'The server returned an unexpected status code and no error factory is registered for this code:' + status_code.to_s if error_factory.nil?
root_node = self.get_root_parse_node(response)
error = root_node.get_object_value(error_factory) unless root_node.nil?
raise error unless error.nil?
raise MicrosoftKiotaAbstractions::ApiError, 'The server returned an unexpected status code:' + status_code.to_s
end
def get_request_from_request_info(request_info)
request_info.path_parameters['baseurl'] = @base_url
case request_info.http_method
when :GET
request = @client.build_request(:get)
when :POST
request = @client.build_request(:post)
when :PATCH
request = @client.build_request(:patch)
when :DELETE
request = @client.build_request(:delete)
when :OPTIONS
request = @client.build_request(:options)
when :CONNECT
request = @client.build_request(:connect)
when :PUT
request = @client.build_request(:put)
when :TRACE
request = @client.build_request(:trace)
when :HEAD
request = @client.build_request(:head)
else
raise StandardError, 'unsupported http method'
end
request.path = request_info.uri
unless request_info.headers.nil? then
request.headers = Faraday::Utils::Headers.new
request_info.headers.get_all.select{|k,v|
if v.kind_of? Array then
request.headers[k] = v.join(',')
elsif v.kind_of? String then
request.headers[k] = v
else
request.headers[k] = v.to_s
end
}
end
request.body = request_info.content unless request_info.content.nil? || request_info.content.empty?
# TODO the json serialization writer returns a string at the moment, change to body_stream when this is fixed
request_options = request_info.get_request_options
if !request_options.nil? && !request_options.empty? then
request.options = Faraday::RequestOptions.new if request.options.nil?
request_options.each do |value|
request.options.context[value.get_key] = value
end
end
request
end
def get_response_content_type(response)
begin
response.headers['content-type'].split(';')[0].downcase()
rescue
return nil
end
end
end
end

Просмотреть файл

@ -1,35 +0,0 @@
require 'net/https'
require 'faraday'
require_relative 'middleware/parameters_name_decoding_handler'
module MicrosoftKiotaFaraday
class KiotaClientFactory
def self.get_default_middleware()
return [
MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler
]
end
def self.get_default_http_client(middleware=nil, default_middleware_options=Array.new)
if middleware.nil? #empty is fine in case the user doesn't want to use any middleware
middleware = self.get_default_middleware()
end
connection_options = Hash.new
connection_options[:request] = Hash.new
connection_options[:request][:context] = Hash.new
unless default_middleware_options.nil? || default_middleware_options.empty? then
default_middleware_options.each do |value|
connection_options[:request][:context][value.get_key] = value
end
end
conn = Faraday::Connection.new(nil, connection_options) do |builder|
builder.adapter Faraday.default_adapter
builder.ssl.verify = true
builder.ssl.verify_mode = OpenSSL::SSL::VERIFY_PEER
middleware.each do |handler|
builder.use handler
end
end
conn
end
end
end

Просмотреть файл

@ -1,29 +0,0 @@
require 'faraday'
require_relative 'parameters_name_decoding_option'
module MicrosoftKiotaFaraday
module Middleware
class ParametersNameDecodingHandler < Faraday::Middleware
@@default_option = ParametersNameDecodingOption.new
def call(request_env)
request_option = request_env[:request][:context][@@default_option.get_key] unless request_env[:request].nil? || request_env[:request][:context].nil?
request_option = @@default_option if request_option.nil?
unless request_env[:url].nil? || !request_option.enabled || request_option.characters_to_decode.nil? || request_option.characters_to_decode.empty? then
request_url = request_env[:url].to_s
request_option.characters_to_decode.each do |character|
request_url = request_url.gsub(get_regex_for_character(character), character)
end
request_env[:url] = URI.parse(request_url)
end
@app.call(request_env) unless @app.nil?
end
def get_regex_for_character(character)
@regex_cache ||= Hash.new
if @regex_cache[character].nil? then
@regex_cache[character] = Regexp.new("%#{character.ord.to_s(16)}", true)
end
return @regex_cache[character]
end
end
end
end

Просмотреть файл

@ -1,19 +0,0 @@
# frozen_string_literal: true
require 'microsoft_kiota_abstractions'
module MicrosoftKiotaFaraday
module Middleware
class ParametersNameDecodingOption
include MicrosoftKiotaAbstractions::RequestOption
attr_accessor :enabled, :characters_to_decode
def initialize(enabled = true, characters_to_decode = ['$', '.', '-', '~'])
@enabled = enabled
@characters_to_decode = characters_to_decode
end
def get_key()
"parametersNameDecoding"
end
end
end
end

Просмотреть файл

@ -1,14 +0,0 @@
# frozen_string_literal: true
require 'microsoft_kiota_abstractions'
module MicrosoftKiotaFaraday
module Middleware
class ResponseHandlerOption
RESPONSE_HANDLER_KEY = "responseHandler"
# a lambda that takes the native response type and returns a Fiber with a MicrosoftKiotaAbstractions::Parsable
attr_accessor :async_callback
def get_key()
RESPONSE_HANDLER_KEY
end
end
end
end

Просмотреть файл

@ -1,5 +0,0 @@
# frozen_string_literal: true
module MicrosoftKiotaFaraday
VERSION = '0.9.0'
end

Просмотреть файл

@ -1,36 +0,0 @@
# frozen_string_literal: true
require_relative "lib/microsoft_kiota_faraday/version"
Gem::Specification.new do |spec|
spec.name = "microsoft_kiota_faraday"
spec.version = MicrosoftKiotaFaraday::VERSION
spec.authors = 'Microsoft Corporation'
spec.email = 'graphsdkpub@microsoft.com'
spec.description = 'Kiota HttpCore implementation with Faraday'
spec.summary = "Microsoft Kiota Faraday - Kiota Ruby http request adapter for running requests"
spec.homepage = 'https://microsoft.github.io/kiota/'
spec.license = 'MIT'
spec.metadata = {
'bug_tracker_uri' => 'https://github.com/microsoft/kiota/issues',
'changelog_uri' => 'https://github.com/microsoft/kiota/blob/main/CHANGELOG.md',
'homepage_uri' => spec.homepage,
'source_code_uri' => 'https://github.com/microsoft/kiota',
'github_repo' => 'ssh://github.com/microsoft/kiota'
}
spec.required_ruby_version = ">= 2.7.0"
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
end
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.12.0', '>= 0.12.0'
spec.add_runtime_dependency 'faraday', '~> 2.7', '>= 2.7.2'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
end

Просмотреть файл

@ -1,5 +0,0 @@
require 'microsoft_kiota_abstractions'
class AuthenticationProvider
include MicrosoftKiotaAbstractions::AuthenticationProvider
end

Просмотреть файл

@ -1,18 +0,0 @@
# frozen_string_literal: true
require_relative 'authentication_provider'
RSpec.describe MicrosoftKiotaFaraday do
it "has a version number" do
expect(MicrosoftKiotaFaraday::VERSION).not_to be nil
end
it "does something useful" do
expect(true).to eq(true)
end
it "can instantiate a request adapter" do
auth_provider = AuthenticationProvider.new()
adapter = MicrosoftKiotaFaraday::FaradayRequestAdapter.new(auth_provider)
expect(adapter).to_not be nil
end
end

Просмотреть файл

@ -1,46 +0,0 @@
require 'faraday'
# frozen_string_literal: true
RSpec.describe MicrosoftKiotaFaraday do
it "decodes encoded query parameters" do
values = Hash.new
values["?%24select=diplayName&api%2Dversion=2"] = "?$select=diplayName&api-version=2"
values["?%24select=diplayName&api%7Eversion=2"] = "?$select=diplayName&api~version=2"
values["?%24select=diplayName&api%2Eversion=2"] = "?$select=diplayName&api.version=2"
values["/api-version/?%24select=diplayName&api%2Eversion=2"] = "/api-version/?$select=diplayName&api.version=2"
values[""] = ""
handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new()
values.each do |key, value|
env = {
url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}")
}
handler.call(env)
expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}")
end
end
it "doesn't decode when disabled on request" do
values = Hash.new
values["?%24select=diplayName&api%2Dversion=2"] = "?%24select=diplayName&api%2Dversion=2"
values["?%24select=diplayName&api%7Eversion=2"] = "?%24select=diplayName&api%7Eversion=2"
values["?%24select=diplayName&api%2Eversion=2"] = "?%24select=diplayName&api%2Eversion=2"
values["/api-version/?%24select=diplayName&api%2Eversion=2"] = "/api-version/?%24select=diplayName&api%2Eversion=2"
values[""] = ""
option = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingOption.new(false)
handler = MicrosoftKiotaFaraday::Middleware::ParametersNameDecodingHandler.new()
values.each do |key, value|
env = {
url: URI.parse("https://graph.microsoft.com/v1.0/users#{key}"),
request: {
context: {
option.get_key => option
}
}
}
handler.call(env)
expect(env[:url].to_s).to eq("https://graph.microsoft.com/v1.0/users#{value}")
end
end
end

Просмотреть файл

@ -1,17 +0,0 @@
# frozen_string_literal: true
require "microsoft_kiota_faraday"
Dir["#{File.dirname(__FILE__)}/./../lib/*.rb"].each { |f| load(f) }
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
end

Просмотреть файл

@ -9,7 +9,8 @@ Your project will need a reference to the abstraction package to build and run,
- [Go](https://github.com/microsoft/kiota-serialization-json-go): relies on [encoding/json](https://pkg.go.dev/encoding/json) for JSON serialization/deserialization.
- [Java](https://github.com/microsoft/kiota-java/tree/main/components/serialization/json) : relies on [Gson](https://github.com/google/gson) for JSON serialization/deserialization.
- [TypeScript](https://github.com/microsoft/kiota-typescript/tree/main/packages/serialization/json) : relies on the native JSON capabilities for JSON serialization/deserialization.
- [PHP](https://github.com/microsoft/kiota-serialization-json-php) : relies on the native JSON capabilities for JSON deserialization
- [Ruby](https://github.com/microsoft/kiota-serialization-json-ruby): relies on the native JSON capabilities for JSON deserialization.
- [PHP](https://github.com/microsoft/kiota-serialization-json-php) : relies on the native JSON capabilities for JSON deserialization.
- [Python](https://github.com/microsoft/kiota-serialization-json-python) : relies on the native JSON capabilities.
## Application/x-www-form-urlencoded

Просмотреть файл

@ -1,13 +0,0 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
# rspec failure tracking
.rspec_status
Gemfile.lock

Просмотреть файл

@ -1,3 +0,0 @@
--format documentation
--color
--require spec_helper

Просмотреть файл

@ -1,9 +0,0 @@
# frozen_string_literal: true
source "https://rubygems.org"
source "https://rubygems.pkg.github.com/microsoft"
gemspec
# gem "microsoft_kiota_abstractions", path: "../../../../abstractions/ruby/microsoft_kiota_abstractions"

Просмотреть файл

@ -1,50 +0,0 @@
# MicrosoftKiotaSerialization
![Ruby](https://github.com/microsoft/kiota/actions/workflows/serialization-ruby-json.yml/badge.svg)
## Using the Serialization JSON implementations
Option 1: Bundler config
```shell
bundle config https://rubygems.pkg.github.com/microsoft/kiota USERNAME:TOKEN
```
Option 2: Configuring `~/.gemrc` file
```
---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://rubygems.org/
- https://USERNAME:TOKEN@rubygems.pkg.github.com/microsoft/kiota
:update_sources: true
:verbose: true
```
## Installation
Add this line to your application's Gemfile:
```ruby
source "https://rubygems.pkg.github.com/microsoft" do
gem "microsoft_kiota_serialization", "0.1.0"
end
```
And then execute:
```shell
bundle install
```
Or install it yourself as:
```shell
gem install microsoft_kiota_serialization --version "0.1.0" --source "https://{USERNAME}{PASSWORD/TOKEN}rubygems.pkg.github.com/microsoft"
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/microsoft/kiota.

Просмотреть файл

@ -1,8 +0,0 @@
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task default: :spec

Просмотреть файл

@ -1,10 +0,0 @@
# frozen_string_literal: true
require_relative "microsoft_kiota_serialization/json_parse_node"
require_relative "microsoft_kiota_serialization/json_parse_node_factory"
require_relative "microsoft_kiota_serialization/json_serialization_writer"
require_relative "microsoft_kiota_serialization/json_serialization_writer_factory"
require_relative "microsoft_kiota_serialization/version"
module MicrosoftKiotaSerialization
end

Просмотреть файл

@ -1,128 +0,0 @@
require 'time'
require 'date'
require 'json'
require 'uuidtools'
require 'microsoft_kiota_abstractions'
module MicrosoftKiotaSerialization
class JsonParseNode
include MicrosoftKiotaAbstractions::ParseNode
def initialize(node)
@current_node = node
end
def get_string_value
@current_node.to_s
end
def get_boolean_value
@current_node
end
def get_number_value
@current_node.to_i
end
def get_float_value
@current_node.to_f
end
def get_guid_value
UUIDTools::UUID.parse(@current_node)
end
def get_date_value
Date.parse(@current_node)
end
def get_time_value()
Time.parse(@current_node)
end
def get_date_time_value()
DateTime.parse(@current_node)
end
def get_duration_value()
MicrosoftKiotaAbstractions::ISODuration.new(@current_node)
end
def get_collection_of_primitive_values(type)
@current_node.map do |x|
current_parse_node = JsonParseNode.new(x)
case type
when String
current_parse_node.get_string_value
when Float
current_parse_node.get_float_value
when Integer
current_parse_node.get_float_value
when "Boolean"
current_parse_node.get_float_value
when DateTime
current_parse_node.get_date_time_value
when Time
current_parse_node.get_time_value
when Date
current_parse_node.get_date_value
when MicrosoftKiotaAbstractions::ISODuration
current_parse_node.get_duration_value
when UUIDTools::UUID
current_parse_node.get_guid_value
else
current_parse_node.get_string_value
end
rescue StandardError => e
raise e.class, `Failed to fetch #{type} type`
end
end
def get_collection_of_object_values(factory)
raise StandardError, 'Factory cannot be null' if factory.nil?
@current_node.map do |x|
current_parse_node = JsonParseNode.new(x)
current_parse_node.get_object_value(factory)
end
end
def get_object_value(factory)
raise StandardError, 'Factory cannot be null' if factory.nil?
item = factory.call(self)
assign_field_values(item)
item
rescue StandardError => e
raise e.class, 'Error during deserialization'
end
def assign_field_values(item)
fields = item.get_field_deserializers
@current_node.each do |k, v|
deserializer = fields[k]
if deserializer
deserializer.call(JsonParseNode.new(v))
elsif item.additional_data
item.additional_data[k] = v
else
item.additional_data = Hash.new(k => v)
end
end
end
def get_enum_values(_type)
raw_values = get_string_value
raw_values.split(',').map(&:strip)
end
def get_enum_value(type)
items = get_enum_values(type).map(&:to_sym)
items[0] if items.length.positive?
end
def get_child_node(name)
raise StandardError, 'Name cannot be null' if name.nil? || name.empty?
raw_value = @current_node[name]
return JsonParseNode.new(raw_value) if raw_value
end
end
end

Просмотреть файл

@ -1,23 +0,0 @@
require 'json'
require 'microsoft_kiota_abstractions'
module MicrosoftKiotaSerialization
class JsonParseNodeFactory
include MicrosoftKiotaAbstractions::ParseNodeFactory
def get_valid_content_type
'application/json'
end
def get_parse_node(content_type, content)
if !content_type
raise StandardError, 'content type cannot be undefined or empty'
elsif get_valid_content_type != content_type
raise StandardError, `expected a #{get_valid_content_type} content type`
end
raise StandardError, 'content cannot be undefined or empty' unless content
JsonParseNode.new(JSON.parse(content))
end
end
end

Просмотреть файл

@ -1,228 +0,0 @@
require 'time'
require 'date'
require 'json'
require "uuidtools"
require 'microsoft_kiota_abstractions'
module MicrosoftKiotaSerialization
class JsonSerializationWriter
include MicrosoftKiotaAbstractions::SerializationWriter
@writer
def initialize()
@writer = Hash.new()
end
def writer
@writer
end
def write_string_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_string_value(key, value)"
end
if !key
return value.to_s
end
if !value
@writer[key] = nil
else
@writer[key] = value
end
end
def write_boolean_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_boolean_value(key, value)"
end
if !key
return value
end
@writer[key] = value
end
def write_number_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_number_value(key, value)"
end
if !key
return value
end
@writer[key] = value
end
def write_float_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_float_value(key, value)"
end
if !key
return value
end
@writer[key] = value
end
def write_guid_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_guid_value(key, value)"
end
if !key
return value.to_s
end
if !value
@writer[key] = nil
else
@writer[key] = value.to_s
end
end
def write_date_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_date_value(key, value)"
end
if !key
return value.strftime("%Y-%m-%d")
end
if !value
@writer[key] = nil
else
@writer[key] = value.strftime("%Y-%m-%d")
end
end
def write_time_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_time_value(key, value)"
end
if !key
return value.strftime("%H:%M:%S%Z")
end
if !value
@writer[key] = nil
else
@writer[key] = value.strftime("%H:%M:%S%Z")
end
end
def write_date_time_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_date_time_value(key, value)"
end
if !key
return value.strftime("%Y-%m-%dT%H:%M:%S%Z")
end
if !value
@writer[key] = nil
else
@writer[key] = value.strftime("%Y-%m-%dT%H:%M:%S%Z")
end
end
def write_duration_value(key, value)
if !key && !value
raise StandardError, "no key or value included in write_duration_value(key, value)"
end
if !key
return value.string
end
if !value
@writer[key] = nil
else
@writer[key] = value.string
end
end
def write_collection_of_primitive_values(key, values)
if values
if !key
return values.map do |v|
self.write_any_value(nil, v)
end
end
@writer[key] = values.map do |v|
self.write_any_value(key, v)
end
end
end
def write_collection_of_object_values(key, values)
if values
if !key
return values.map do |v|
self.write_object_value(nil, v)
end
end
@writer[key] = values.map do |v|
self.write_object_value(nil, v).writer
end
end
end
def write_object_value(key, value)
if value
if !key
temp = JsonSerializationWriter.new()
value.serialize(temp)
return temp
end
begin
temp = JsonSerializationWriter.new()
value.serialize(temp)
@writer[key] = temp.writer
rescue StandardError => e
raise e.class, "no key or value included in write_boolean_value(key, value)"
end
end
end
def write_enum_value(key, values)
self.write_string_value(key, values.to_s)
end
def get_serialized_content()
return @writer.to_json #TODO encode to byte array to stay content type agnostic
end
def write_additional_data(value)
if !value
return
end
value.each do |x, y|
self.write_any_value(x,y)
end
end
def write_any_value(key, value)
if value
if !!value == value
return value
elsif value.instance_of? String
return self.write_string_value(key, value)
elsif value.instance_of? Integer
return self.write_number_value(key, value)
elsif value.instance_of? Float
return self.write_float_value(key, value)
elsif value.instance_of? DateTime
return self.write_date_time_value(key, value)
elsif value.instance_of? Time
return self.write_time_value(key, value)
elsif value.instance_of? Date
return self.write_date_value(key, value)
elsif value.instance_of? MicrosoftKiotaAbstractions::ISODuration
return self.write_duration_value(key, value)
elsif value.instance_of? Array
return self.write_collection_of_primitive_values(key, value)
elsif value.is_a? Object
return value.to_s
else
raise StandardError, "encountered unknown value type during serialization #{value.to_s}"
end
else
if key
@writer[key] = nil
else
raise StandardError, "no key included when writing json property"
end
end
end
end
end

Просмотреть файл

@ -1,21 +0,0 @@
require 'microsoft_kiota_abstractions'
module MicrosoftKiotaSerialization
class JsonSerializationWriterFactory
include MicrosoftKiotaAbstractions::SerializationWriterFactory
def get_valid_content_type
'application/json'
end
def get_serialization_writer(content_type)
if !content_type
raise StandardError, 'content type cannot be undefined or empty'
elsif get_valid_content_type != content_type
raise StandardError, `expected a #{get_valid_content_type} content type`
end
JsonSerializationWriter.new
end
end
end

Просмотреть файл

@ -1,5 +0,0 @@
# frozen_string_literal: true
module MicrosoftKiotaSerialization
VERSION = "0.7.0"
end

Просмотреть файл

@ -1,37 +0,0 @@
# frozen_string_literal: true
require_relative "lib/microsoft_kiota_serialization/version"
Gem::Specification.new do |spec|
spec.name = "microsoft_kiota_serialization"
spec.version = MicrosoftKiotaSerialization::VERSION
spec.authors = 'Microsoft Corporation'
spec.email = 'graphsdkpub@microsoft.com'
spec.description = 'Implementation of Kiota Serialization interfaces for JSON'
spec.summary = 'Microsoft Kiota Serialization - Ruby serialization for building library agnostic http client'
spec.homepage = 'https://microsoft.github.io/kiota/'
spec.license = 'MIT'
spec.metadata = {
'bug_tracker_uri' => 'https://github.com/microsoft/kiota/issues',
'changelog_uri' => 'https://github.com/microsoft/kiota/blob/main/CHANGELOG.md',
'homepage_uri' => spec.homepage,
'source_code_uri' => 'https://github.com/microsoft/kiota',
'github_repo' => 'ssh://github.com/microsoft/kiota'
}
spec.required_ruby_version = ">= 2.7.0"
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
end
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_runtime_dependency 'microsoft_kiota_abstractions', '~> 0.12.0', '>= 0.12.0'
spec.add_runtime_dependency 'uuidtools'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
end

Просмотреть файл

@ -1,6 +0,0 @@
module Files
BodyType = {
Text: :Text,
Html: :Html,
}
end

Просмотреть файл

@ -1,98 +0,0 @@
require 'microsoft_kiota_abstractions'
module Files
class EmailAddress
include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable
##
# Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
@additional_data
##
# The email address of the person or entity.
@address
##
# The display name of the person or entity.
@name
##
## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
## @return a i_dictionary
##
def additional_data
return @additional_data
end
##
## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
## @param value Value to set for the AdditionalData property.
## @return a void
##
def additional_data=(value)
@additional_data = value
end
##
## Gets the address property value. The email address of the person or entity.
## @return a string
##
def address
return @address
end
##
## Sets the address property value. The email address of the person or entity.
## @param value Value to set for the address property.
## @return a void
##
def address=(value)
@address = value
end
##
## Instantiates a new emailAddress and sets the default values.
## @return a void
##
def initialize()
@additional_data = Hash.new
end
##
## Creates a new instance of the appropriate class based on discriminator value
## @param parseNode The parse node to use to read the discriminator value and create the object
## @return a email_address
##
def self.create_from_discriminator_value(parse_node)
raise StandardError, 'parse_node cannot be null' if parse_node.nil?
return EmailAddress.new
end
##
## The deserialization information for the current model
## @return a i_dictionary
##
def get_field_deserializers()
return {
"address" => lambda {|n| @address = n.get_string_value() },
"name" => lambda {|n| @name = n.get_string_value() },
}
end
##
## Gets the name property value. The display name of the person or entity.
## @return a string
##
def name
return @name
end
##
## Sets the name property value. The display name of the person or entity.
## @param value Value to set for the name property.
## @return a void
##
def name=(value)
@name = value
end
##
## Serializes information the current object
## @param writer Serialization writer to use to serialize this model
## @return a void
##
def serialize(writer)
raise StandardError, 'writer cannot be null' if writer.nil?
writer.write_string_value("address", @address)
writer.write_string_value("name", @name)
writer.write_additional_data(@additional_data)
end
end
end

Просмотреть файл

@ -1,78 +0,0 @@
require 'microsoft_kiota_abstractions'
module Files
class Entity
include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable
##
# Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
@additional_data
##
# The unique idenfier for an entity. Read-only.
@id
##
## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
## @return a i_dictionary
##
def additional_data
return @additional_data
end
##
## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
## @param value Value to set for the AdditionalData property.
## @return a void
##
def additional_data=(value)
@additional_data = value
end
##
## Instantiates a new entity and sets the default values.
## @return a void
##
def initialize()
@additional_data = Hash.new
end
##
## Creates a new instance of the appropriate class based on discriminator value
## @param parseNode The parse node to use to read the discriminator value and create the object
## @return a entity
##
def self.create_from_discriminator_value(parse_node)
raise StandardError, 'parse_node cannot be null' if parse_node.nil?
return Entity.new
end
##
## The deserialization information for the current model
## @return a i_dictionary
##
def get_field_deserializers()
return {
"id" => lambda {|n| @id = n.get_string_value() },
}
end
##
## Gets the id property value. The unique idenfier for an entity. Read-only.
## @return a string
##
def id
return @id
end
##
## Sets the id property value. The unique idenfier for an entity. Read-only.
## @param value Value to set for the id property.
## @return a void
##
def id=(value)
@id = value
end
##
## Serializes information the current object
## @param writer Serialization writer to use to serialize this model
## @return a void
##
def serialize(writer)
raise StandardError, 'writer cannot be null' if writer.nil?
writer.write_string_value("id", @id)
writer.write_additional_data(@additional_data)
end
end
end

Просмотреть файл

@ -1,12 +0,0 @@
require 'microsoft_kiota_abstractions'
require_relative './body_type'
require_relative './email_address'
require_relative './entity'
require_relative './item_body'
require_relative './message'
require_relative './messages_response'
require_relative './outlook_item'
require_relative './recipient'
module Files
end

Просмотреть файл

@ -1,98 +0,0 @@
require 'microsoft_kiota_abstractions'
module Files
class ItemBody
include MicrosoftKiotaAbstractions::AdditionalDataHolder, MicrosoftKiotaAbstractions::Parsable
##
# Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
@additional_data
##
# The content of the item.
@content
##
# The contentType property
@content_type
##
## Gets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
## @return a i_dictionary
##
def additional_data
return @additional_data
end
##
## Sets the additionalData property value. Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
## @param value Value to set for the AdditionalData property.
## @return a void
##
def additional_data=(value)
@additional_data = value
end
##
## Instantiates a new itemBody and sets the default values.
## @return a void
##
def initialize()
@additional_data = Hash.new
end
##
## Gets the content property value. The content of the item.
## @return a string
##
def content
return @content
end
##
## Sets the content property value. The content of the item.
## @param value Value to set for the content property.
## @return a void
##
def content=(value)
@content = value
end
##
## Gets the contentType property value. The contentType property
## @return a body_type
##
def content_type
return @content_type
end
##
## Sets the contentType property value. The contentType property
## @param value Value to set for the contentType property.
## @return a void
##
def content_type=(value)
@content_type = value
end
##
## Creates a new instance of the appropriate class based on discriminator value
## @param parseNode The parse node to use to read the discriminator value and create the object
## @return a item_body
##
def self.create_from_discriminator_value(parse_node)
raise StandardError, 'parse_node cannot be null' if parse_node.nil?
return ItemBody.new
end
##
## The deserialization information for the current model
## @return a i_dictionary
##
def get_field_deserializers()
return {
"content" => lambda {|n| @content = n.get_string_value() },
"contentType" => lambda {|n| @content_type = n.get_enum_value(Files::BodyType) },
}
end
##
## Serializes information the current object
## @param writer Serialization writer to use to serialize this model
## @return a void
##
def serialize(writer)
raise StandardError, 'writer cannot be null' if writer.nil?
writer.write_string_value("content", @content)
writer.write_enum_value("contentType", @content_type)
writer.write_additional_data(@additional_data)
end
end
end

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше