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
Then run :
> ruby app.rb
And you should see something like :
[
"xxxxxxxxxx",
"xxxxxxxxxx",
"xxxxxxxxxx",
...
]
Top comments (0)