Git Product home page Git Product logo

cognitive-services-ruby-create-account's Introduction

services platforms author
cognitive-services
ruby
veronicagg

Manage Azure Cognitive Services with Ruby

This sample demonstrates how to manage your Azure cognitive services account using a ruby client.

On this page

  1. If you don't already have it, install Ruby and the Ruby DevKit.

  2. If you don't have bundler, install it.

    gem install bundler
    
  3. Clone the repository.

    git clone https://github.com/Azure-Samples/cognitive-services-ruby-create-account.git
    
  4. Install the dependencies using bundle.

    cd cognitive-services-ruby-create-account
    bundle install
    
  5. Create an Azure service principal either through Azure CLI, PowerShell or the portal.

  6. Set the following environment variables using the information from the service principle that you created.

    export AZURE_TENANT_ID={your tenant id}
    export AZURE_CLIENT_ID={your client id}
    export AZURE_CLIENT_SECRET={your client secret}
    export AZURE_SUBSCRIPTION_ID={your subscription id}
    

    [AZURE.NOTE] On Windows, use set instead of export.

  7. Run the sample.

    bundle exec ruby example.rb
    

What does example.rb do?

This sample starts by setting up a ResourceManagementClient object using your subscription and credentials.

subscription_id = ENV['AZURE_SUBSCRIPTION_ID'] || '11111111-1111-1111-1111-111111111111' # your Azure Subscription Id
provider = MsRestAzure::ApplicationTokenProvider.new(
    ENV['AZURE_TENANT_ID'],
    ENV['AZURE_CLIENT_ID'],
    ENV['AZURE_CLIENT_SECRET'])
credentials = MsRest::TokenCredentials.new(provider)
cs_client = Azure::ARM::CognitiveServices::CognitiveServicesManagementClient.new(credentials)
cs_client.long_running_operation_retry_timeout = ENV.fetch('RETRY_TIMEOUT', 30).to_i
resource_client = Azure::ARM::Resources::ResourceManagementClient.new(credentials)
resource_client.subscription_id = cs_client.subscription_id = subscription_id
resource_client.providers.register("Microsoft.CognitiveServices")
resource_client.long_running_operation_retry_timeout = ENV.fetch('RETRY_TIMEOUT', 30).to_i

The sample then sets up a resource group.

resource_group_params = Azure::ARM::Resources::Models::ResourceGroup.new.tap do |rg|
  rg.location = WEST_US
end

resource_group_params.class.class

resource_client.resource_groups.create_or_update(GROUP_NAME, resource_group_params)

Create a cognitive services account

cs_acc_params = Azure::ARM::CognitiveServices::Models::CognitiveServicesAccountCreateParameters.new
sku = Azure::ARM::CognitiveServices::Models::Sku.new
sku.name = Azure::ARM::CognitiveServices::Models::SkuName::F0
cs_acc_params.sku = sku
cs_acc_params.kind = Azure::ARM::CognitiveServices::Models::Kind::TextAnalytics
cs_acc_params.location = 'westus'
cs_acc_params.properties = {:prop1 => 'prop1'}
cs_account = cs_client.cognitive_services_accounts.create(GROUP_NAME, ACCOUNT_NAME, cs_acc_params)

Delete a cognitive services account

cs_client.cognitive_services_accounts.delete(GROUP_NAME, ACCOUNT_NAME)

More information

Please refer to Azure SDK for Ruby for more information.

cognitive-services-ruby-create-account's People

Contributors

acomsmpbot avatar allclark avatar devigned avatar sarangan12 avatar

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.