Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pacoesteban committed Sep 12, 2016
0 parents commit 8d2bdb6
Show file tree
Hide file tree
Showing 12 changed files with 856 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/.build/
/_build/
/Build
/Build.bat
/blib
/Makefile
/pm_to_blib

/carton.lock
/.carton/
/local/

nytprof.out
nytprof/

cover_db/

*.bak
*.old
*~
*.swp
*.o
*.obj

!LICENSE

/_build_params

MYMETA.*

/OvhApi-*
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: perl
sudo: false
perl:
- "5.12"
- "5.14"
- "5.16"
- "5.18"
- "5.20"
- "5.22"

12 changes: 12 additions & 0 deletions Build.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# =========================================================================
# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA.
# DO NOT EDIT DIRECTLY.
# =========================================================================

use 5.008_001;
use strict;

use Module::Build::Tiny 0.035;

Build_PL();

6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Revision history for Perl extension OvhApi

{{$NEXT}}

- original version

26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2013, OVH SAS.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of OVH SAS nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY OVH SAS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL OVH SAS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

57 changes: 57 additions & 0 deletions META.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"abstract" : "Official OVH Perl wrapper upon the OVH RESTful API.",
"author" : [
", OVH SAS."
],
"dynamic_config" : 0,
"generated_by" : "Minilla/v3.0.4, CPAN::Meta::Converter version 2.150005",
"license" : [
"unknown"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : "2"
},
"name" : "OvhApi",
"no_index" : {
"directory" : [
"t",
"xt",
"inc",
"share",
"eg",
"examples",
"author",
"builder"
]
},
"prereqs" : {
"configure" : {
"requires" : {
"Module::Build::Tiny" : "0.035"
}
},
"develop" : {
"requires" : {
"Test::CPAN::Meta" : "0",
"Test::MinimumVersion::Fast" : "0.04",
"Test::PAUSE::Permissions" : "0.04",
"Test::Pod" : "1.41",
"Test::Spellunker" : "v0.2.7"
}
},
"runtime" : {
"requires" : {
"perl" : "5.008001"
}
},
"test" : {
"requires" : {
"Test::More" : "0.98"
}
}
},
"release_status" : "unstable",
"version" : "1",
"x_serialization_backend" : "JSON::PP version 2.27300"
}
137 changes: 137 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# NAME

OvhApi - Official OVH Perl wrapper upon the OVH RESTful API.

# SYNOPSIS

use OvhApi;

my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $AK, applicationSecret => $AS, consumerKey => $CK);
my $Answer = $Api->get(path => '/me');

# DESCRIPTION

This module is an official Perl wrapper that OVH provides in order to offer a simple way to use its RESTful API.
`OvhApi` handles the authentication layer, and uses `LWP::UserAgent` in order to run requests.

Answer are retured as instances of [OvhApi::Answer](https://metacpan.org/pod/OvhApi::Answer).

# CLASS METHODS

## Constructor

There is only one constructor: `new`.

Its parameters are:

Parameter Mandatory Default Usage
------------ ------------ ---------- --------
type Carp if missing OVH_API_EU() Determine if you'll use european or canadian OVH API (possible values are OVH_API_EU and OVH_API_CA)
timeout No 10 Set the timeout LWP::UserAgent will use
applicationKey Yes - Your application key
applicationSecret Yes - Your application secret
consumerKey Yes, unless for a credential request - Your consumer key

## OVH\_API\_EU

[Constant](https://metacpan.org/pod/constant) that points to the root URL of OVH european API.

## OVH\_API\_CA

[Constant](https://metacpan.org/pod/constant) that points to the root URL of OVH canadian API.

## setRequestTimeout

This method changes the timeout `LWP::UserAgent` uses. You can set that in [new](#constructor) instead.

Its parameters are:

Parameter Mandatory
------------ ------------
timeout Yes

# INSTANCE METHODS

## rawCall

This is the main method of that wrapper. This method will take care of the signature, of the JSON conversion of your data, and of the effective run of the query.

Its parameters are:

Parameter Mandatory Default Usage
------------ ------------ ---------- --------
path Yes - The API URL you want to request
method Yes - The HTTP method of the request (GET, POST, PUT, DELETE)
body No '' The body to send in the query. Will be ignore on a GET
noSignature No false If set to a true value, no signature will be send

## get

Helper method that wraps a call to:

rawCall(method => 'get");

All parameters are forwarded to [rawCall](#rawcall).

## post

Helper method that wraps a call to:

rawCall(method => 'post');

All parameters are forwarded to [rawCall](#rawcall).

## put

Helper method that wraps a call to:

rawCall(method => 'put');

All parameters are forwarded to [rawCall](#rawcall).

## delete

Helper method that wraps a call to:

rawCall(method => 'delete');

All parameters are forwarded to [rawCall](#rawcall).

## requestCredentials

This method will request a Consumer Key to the API. That credential will need to be validated with the link returned in the answer.

Its parameters are:

Parameter Mandatory
------------ ------------
accessRules Yes

The `accessRules` parameter is an ARRAY of HASHes. Each hash contains these keys:

- method: an HTTP method among GET, POST, PUT and DELETE. ALL is a special values that includes all the methods;
- path: a string that represents the URLs the credential will have access to. `*` can be used as a wildcard. `/*` will allow all URLs, for example.

### Example

my $Api = OvhApi->new(type => OvhApi::OVH_API_EU, applicationKey => $AK, applicationSecret => $AS, consumerKey => $CK);
my $Answer = $Api->requestCredentials(accessRules => [ { method => 'ALL', path => '/*' }]);

if ($Answer)
{
my ($consumerKey, $validationUrl) = @{ $Answer->content}{qw{ consumerKey validationUrl }};

# $consumerKey contains the newly created Consumer Key
# $validationUrl contains a link to OVH website in order to login an OVH account and link it to the credential
}

# SEE ALSO

The guts of module are using: `LWP::UserAgent`, `JSON`, `Digest::SHA1`.

# COPYRIGHT

Copyright (c) 2013, OVH SAS.
All rights reserved.

This library is distributed under the terms of `license.txt`.
6 changes: 6 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requires 'perl', '5.008001';

on 'test' => sub {
requires 'Test::More', '0.98';
};

Loading

0 comments on commit 8d2bdb6

Please sign in to comment.