GithubHelp home page GithubHelp logo

soyoustart-rest's Introduction

OVH-REST

OVH-REST is a (really) tiny, unofficial helper library OVH management API, wrapping the authentication parts and simplifying interaction in Ruby programs.

You need an appKey and an appSecret to use it, which can be obtained there.

Usage

First, you need to generate a consumerKey which is grants access to specific methods and parts of the API.

require 'ovh/rest'

access = {
  "accessRules" => [
    { "method" => "GET", "path" => "/sms/*" },
    { "method" => "POST", "path" => "/sms/*" },
    { "method" => "PUT", "path" => "/sms/*" },
    { "method" => "DELETE", "path" => "/sms/*" },
  ]
}

OVH::REST.generate_consumer_key("your_appKey", access)
=> {
  "validationUrl" => "https://www.ovh.com/fr/cgi-bin/api/requestCredential.cgi?credentialToken=XXXXXXXXXXXXXXXXXXXXXXX",
  "consumerKey" => "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
  "state" => "pendingValidation"
}

You now have your consumerKey, which needs validation before use. Validation is done by following the validationUrl and entering your credentials.

Then you can use API features:

require 'ovh/rest'

ovh = OVH::REST.new(apiKey, appSecret, consumerKey)

# Get sms account status
result = ovh.get("/sms/sms-xx12345-1")

puts JSON.pretty_generate(result)
=>
{
  "status": "enable",
  "creditsLeft": 42,
  "name": "sms-xx12345-1",
  "userQuantityWithQuota": 0,
  "description": "",
[...]
}

# Send sms
result = ovh.post("/sms/sms-xx12345-1/jobs", {
  "charset" => "UTF-8",
  "class" => "phoneDisplay",
  "coding" => "7bit",
  "priority" => "high",
  "validityPeriod" => 2880
  "message" => "Dude! Disk is CRITICAL!",
  "receivers" => ["+12345678900", "+12009876543"],
  "sender" => "+12424242424",
})

puts JSON.pretty_generate(result)
=>
{
  "totalCreditsRemoved": 2,
  "ids": [
    12345,
    12346
  ]
}

All methods and parameters are described on the API documentation

Setup

Only tested with MRI >= 1.9.3

Dependencies: none

Install:

Links

Introduction, in french: http://www.ovh.com/fr/g934.premiers-pas-avec-l-api

soyoustart-rest's People

Contributors

josqu4red avatar mareklipka 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.