Giter VIP home page Giter VIP logo

java-ovh's Introduction

Lightweight Java wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.

import com.ovh.api.OvhApi;

public class OvhApiTest {

        public void testCall() throws OvhApiException {
                String endpoint = "ovh-eu";
                String appKey = "0000000000000000";
                String appSecret = "00000000000000000000000000000000";
                String consumerKey = "00000000000000000000000000000000";

                OvhApi api = new OvhApi(endpoint, appKey, appSecret, consumerKey);
                try {
                        api.get("/me");
                } catch (OvhApiException e) {
                        System.out.prinln(e);
                }
        }
}

The wrapper accepts and returns raw json Strings. You can serialize/deserialize it with any external library, the following example uses Gson from Google.

import com.ovh.api.OvhApi;
import com.google.gson.Gson;

public class OvhApiTest {

        public class Me {

                public String firstname;
                public String name;
                public String nichandle;

                @Override
                public String toString() {
                        return "Me [firstname=" + firstname + ", name=" + name + ", nichandle=" + nichandle + "]";
                }

        }

        public void testCall() throws OvhApiException {
                String endpoint = "ovh-eu";
                String appKey = "0000000000000000";
                String appSecret = "00000000000000000000000000000000";
                String consumerKey = "00000000000000000000000000000000";

                OvhApi api = new OvhApi(endpoint, appKey, appSecret, consumerKey);
                try {
                        String json = api.get("/me");
                        Gson gson = new Gson();
                        Me me = gson.fromJson(json, Me.class);
                        System.out.println(json);
                        System.out.println(me.toString());
                } catch (OvhApiException e) {
                        System.out.prinln(e);
                }
        }
}

Configuration

The straightforward way to use OVH's API keys is to embed them directly in the application code. While this is very convenient, it lacks of elegance and flexibility.

Alternatively it is suggested to use configuration files or environment variables so that the same code may run seamlessly in multiple environments. Production and development for instance.

This wrapper will first look for direct instantiation parameters then OVH_ENDPOINT, OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET and OVH_CONSUMER_KEY environment variables. If either of these parameter is not provided, it will look for a configuration file of the form:

endpoint=ovh-eu
application_key=my_app_key
application_secret=my_application_secret
consumer_key=my_consumer_key

The client will successively attempt to locate this configuration file in

  1. Current working directory: ./ovh.conf
  2. Current user's home directory ~/.ovh.conf
  3. System wide configuration /etc/ovh.conf

This lookup mechanism makes it easy to overload credentials for a specific project or user.

Get the sources

The project is hosted on github and uses gradle as a build system.

git clone https://github.com/ovh/java-ovh.git
cd java-ovh
./gradlew build

The compiled library will be at build/libs/java-ovh.jar

You've developed a new cool feature ? Fixed an annoying bug ? We'd be happy to hear from you !

Run the tests

./gradlew test

See the report at buid/reports/tests/index.html

Supported APIs

OVH Europe

OVH North America

So you Start Europe

So you Start North America

Kimsufi Europe

Kimsufi North America

Runabove

License

3-Clause BSD

java-ovh's People

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.