DEV Community

Cover image for Use OVH API in Ruby
Bento
Bento

Posted on

1

Use OVH API in Ruby

If you're searching to quickly copy&paste some code to use OVH's API in Ruby... welcome my friend.
This post is for you. If not, you may not be interested.

Introduction

Lately I struggled to use OVH's API on a Ruby because there isn't any official wrapper made for Ruby.

So I followed OVH's tutorial to make a call to their API, and translated it in a simple Ruby script.

Step 1: Create your script keys

Fill the informations on this page to create your script credentials.

Step 2: Write the Ruby script

Create a file called app.rb for example, and put the code below :

require 'httparty'
require 'digest/sha1'

# CREDENTIALS
APPLICATION_KEY = "hDSISKsDSKdSOHIs" # Fill it with your own key
APPLICATION_SECRET = "hHkNkGHkGuyFliuHGIUGiohmoiHHIUGh" # Fill it with your own key
CONSUMER_KEY = "hIOHoiNkhIgfOYUmpioGPIuhihujIMUG" # Fill it with your own key

BASE_URL = "https://eu.api.ovh.com/1.0"
QUERY = BASE_URL + "/telephony/aliases"

######## STEP 1: CREATE SIGNATURE ########

METHOD = "GET"
QUERY = "https://eu.api.ovh.com/1.0/telephony/aliases"
BODY = ""
TSTAMP = HTTParty.get("https://eu.api.ovh.com/1.0/auth/time").to_s
SIGNATURE = "$1$" + Digest::SHA1.hexdigest(APPLICATION_SECRET + "+" + CONSUMER_KEY + "+" + METHOD + "+" + QUERY + "+" + BODY + "+" + TSTAMP)

######## STEP 2: GET TELEPHONY ALIASES (e.g) ########

options = {
  "headers": {
    "X-Ovh-Application": APPLICATION_KEY,
    "X-Ovh-Consumer": CONSUMER_KEY,
    "X-Ovh-Signature": SIGNATURE,
    "X-Ovh-Timestamp": TSTAMP,
  }
}

aliases = HTTParty.get(BASE_URL + QUERY, options)
puts aliases

Enter fullscreen mode Exit fullscreen mode

Then run :

> ruby app.rb
Enter fullscreen mode Exit fullscreen mode

And you should see something like :

[
    "xxxxxxxxxx",
    "xxxxxxxxxx",
    "xxxxxxxxxx",
    ...
  ]
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay