sabcio_ovh_savoni 1.54.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +167 -0
- data/README.md +113 -0
- data/Rakefile +5 -0
- data/lib/ovh_savoni.rb +16 -0
- data/lib/ovh_savoni/error.rb +2 -0
- data/lib/ovh_savoni/response_builder.rb +43 -0
- data/lib/ovh_savoni/soapi.rb +91 -0
- data/lib/ovh_savoni/version.rb +3 -0
- data/lib/soapi-dlw-1.54.wsdl +31540 -0
- data/spec/ovh_savoni_spec.rb +6 -0
- data/spec/spec_helper.rb +7 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MWJiMzYxZGY2MDA0ZjZlMjQ5MGQxM2RjY2Q5ZWZkZjFkZGNmNzUzOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWQ1ZmViZDBkYzBjYjg2MGNiNGIyZDM0YzNkNzYxYmI0NjdhNDRmZg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OWE4YjgyNjllNGI4MWFlNGYwYTE3ZDJhYTQwZmQ2ZTU0MDJkZWFmNmFlMDE3
|
10
|
+
MjEzNzExNTY2YjgyZjJhNWEzOGVlZDhlMmU4OTVlYTYxYzY0MDE5ZjNjM2Yy
|
11
|
+
Y2U5ZGU1OTY2N2EwYTI1MDllMjc3MmIzNGRiNDQ4NTc0ODFjMTQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjQyMTQ2ZTNiMDI4NTA0ZGFlODk0NmFhY2MxY2E4NWRhMTcxODkzNTIyYzgz
|
14
|
+
N2M3YzIxZmRjNGNhODIzYjk4NDYxNzk2ZDMwMGM2MWVmNmY2NTUxNjM4YmJj
|
15
|
+
NDMwNjFjNTJmNDVhZmFjY2UzZDZmZmQxMWFlOGI2OGQyOTIwODI=
|
data/LICENSE
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
Copyright (C) 2012 Thibault Poncelet <thibaultponcelet@gmail.com>
|
2
|
+
|
3
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
4
|
+
Version 3, 29 June 2007
|
5
|
+
|
6
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
7
|
+
Everyone is permitted to copy and distribute verbatim copies
|
8
|
+
of this license document, but changing it is not allowed.
|
9
|
+
|
10
|
+
|
11
|
+
This version of the GNU Lesser General Public License incorporates
|
12
|
+
the terms and conditions of version 3 of the GNU General Public
|
13
|
+
License, supplemented by the additional permissions listed below.
|
14
|
+
|
15
|
+
0. Additional Definitions.
|
16
|
+
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
19
|
+
General Public License.
|
20
|
+
|
21
|
+
"The Library" refers to a covered work governed by this License,
|
22
|
+
other than an Application or a Combined Work as defined below.
|
23
|
+
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
27
|
+
of using an interface provided by the Library.
|
28
|
+
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
30
|
+
Application with the Library. The particular version of the Library
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
32
|
+
Version".
|
33
|
+
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
37
|
+
based on the Application, and not on the Linked Version.
|
38
|
+
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
40
|
+
object code and/or source code for the Application, including any data
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
43
|
+
|
44
|
+
1. Exception to Section 3 of the GNU GPL.
|
45
|
+
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
48
|
+
|
49
|
+
2. Conveying Modified Versions.
|
50
|
+
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
53
|
+
that uses the facility (other than as an argument passed when the
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
55
|
+
version:
|
56
|
+
|
57
|
+
a) under this License, provided that you make a good faith effort to
|
58
|
+
ensure that, in the event an Application does not supply the
|
59
|
+
function or data, the facility still operates, and performs
|
60
|
+
whatever part of its purpose remains meaningful, or
|
61
|
+
|
62
|
+
b) under the GNU GPL, with none of the additional permissions of
|
63
|
+
this License applicable to that copy.
|
64
|
+
|
65
|
+
3. Object Code Incorporating Material from Library Header Files.
|
66
|
+
|
67
|
+
The object code form of an Application may incorporate material from
|
68
|
+
a header file that is part of the Library. You may convey such object
|
69
|
+
code under terms of your choice, provided that, if the incorporated
|
70
|
+
material is not limited to numerical parameters, data structure
|
71
|
+
layouts and accessors, or small macros, inline functions and templates
|
72
|
+
(ten or fewer lines in length), you do both of the following:
|
73
|
+
|
74
|
+
a) Give prominent notice with each copy of the object code that the
|
75
|
+
Library is used in it and that the Library and its use are
|
76
|
+
covered by this License.
|
77
|
+
|
78
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
79
|
+
document.
|
80
|
+
|
81
|
+
4. Combined Works.
|
82
|
+
|
83
|
+
You may convey a Combined Work under terms of your choice that,
|
84
|
+
taken together, effectively do not restrict modification of the
|
85
|
+
portions of the Library contained in the Combined Work and reverse
|
86
|
+
engineering for debugging such modifications, if you also do each of
|
87
|
+
the following:
|
88
|
+
|
89
|
+
a) Give prominent notice with each copy of the Combined Work that
|
90
|
+
the Library is used in it and that the Library and its use are
|
91
|
+
covered by this License.
|
92
|
+
|
93
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
94
|
+
document.
|
95
|
+
|
96
|
+
c) For a Combined Work that displays copyright notices during
|
97
|
+
execution, include the copyright notice for the Library among
|
98
|
+
these notices, as well as a reference directing the user to the
|
99
|
+
copies of the GNU GPL and this license document.
|
100
|
+
|
101
|
+
d) Do one of the following:
|
102
|
+
|
103
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
104
|
+
License, and the Corresponding Application Code in a form
|
105
|
+
suitable for, and under terms that permit, the user to
|
106
|
+
recombine or relink the Application with a modified version of
|
107
|
+
the Linked Version to produce a modified Combined Work, in the
|
108
|
+
manner specified by section 6 of the GNU GPL for conveying
|
109
|
+
Corresponding Source.
|
110
|
+
|
111
|
+
1) Use a suitable shared library mechanism for linking with the
|
112
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
113
|
+
a copy of the Library already present on the user's computer
|
114
|
+
system, and (b) will operate properly with a modified version
|
115
|
+
of the Library that is interface-compatible with the Linked
|
116
|
+
Version.
|
117
|
+
|
118
|
+
e) Provide Installation Information, but only if you would otherwise
|
119
|
+
be required to provide such information under section 6 of the
|
120
|
+
GNU GPL, and only to the extent that such information is
|
121
|
+
necessary to install and execute a modified version of the
|
122
|
+
Combined Work produced by recombining or relinking the
|
123
|
+
Application with a modified version of the Linked Version. (If
|
124
|
+
you use option 4d0, the Installation Information must accompany
|
125
|
+
the Minimal Corresponding Source and Corresponding Application
|
126
|
+
Code. If you use option 4d1, you must provide the Installation
|
127
|
+
Information in the manner specified by section 6 of the GNU GPL
|
128
|
+
for conveying Corresponding Source.)
|
129
|
+
|
130
|
+
5. Combined Libraries.
|
131
|
+
|
132
|
+
You may place library facilities that are a work based on the
|
133
|
+
Library side by side in a single library together with other library
|
134
|
+
facilities that are not Applications and are not covered by this
|
135
|
+
License, and convey such a combined library under terms of your
|
136
|
+
choice, if you do both of the following:
|
137
|
+
|
138
|
+
a) Accompany the combined library with a copy of the same work based
|
139
|
+
on the Library, uncombined with any other library facilities,
|
140
|
+
conveyed under the terms of this License.
|
141
|
+
|
142
|
+
b) Give prominent notice with the combined library that part of it
|
143
|
+
is a work based on the Library, and explaining where to find the
|
144
|
+
accompanying uncombined form of the same work.
|
145
|
+
|
146
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
147
|
+
|
148
|
+
The Free Software Foundation may publish revised and/or new versions
|
149
|
+
of the GNU Lesser General Public License from time to time. Such new
|
150
|
+
versions will be similar in spirit to the present version, but may
|
151
|
+
differ in detail to address new problems or concerns.
|
152
|
+
|
153
|
+
Each version is given a distinguishing version number. If the
|
154
|
+
Library as you received it specifies that a certain numbered version
|
155
|
+
of the GNU Lesser General Public License "or any later version"
|
156
|
+
applies to it, you have the option of following the terms and
|
157
|
+
conditions either of that published version or of any later version
|
158
|
+
published by the Free Software Foundation. If the Library as you
|
159
|
+
received it does not specify a version number of the GNU Lesser
|
160
|
+
General Public License, you may choose any version of the GNU Lesser
|
161
|
+
General Public License ever published by the Free Software Foundation.
|
162
|
+
|
163
|
+
If the Library as you received it specifies that a proxy can decide
|
164
|
+
whether future versions of the GNU Lesser General Public License shall
|
165
|
+
apply, that proxy's public statement of acceptance of any version is
|
166
|
+
permanent authorization for you to choose that version for the
|
167
|
+
Library.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
ovh_savoni
|
2
|
+
===
|
3
|
+
OVH SoAPI wrapper.
|
4
|
+
|
5
|
+
Super easy access to the OVH Soap API for Ruby >1.9, with extra support for SMS handling.
|
6
|
+
|
7
|
+
Please refer to http://www.ovh.com/soapi/en/ for the API definition.
|
8
|
+
|
9
|
+
##Install
|
10
|
+
|
11
|
+
Install it on your system:
|
12
|
+
|
13
|
+
gem install ovh_savoni
|
14
|
+
|
15
|
+
Or add it to your Gemfile:
|
16
|
+
|
17
|
+
gem 'ovh_savoni', 'x.x.x'
|
18
|
+
|
19
|
+
|
20
|
+
### Version
|
21
|
+
|
22
|
+
|
23
|
+
Be carefull that methods will change with versions to follow the updates done by OVH in their WSDL file.
|
24
|
+
Version number of this gem match the WSDL version of OVH (see the changelog here: http://www.ovh.com/soapi/fr/changelog.xml).
|
25
|
+
An additional version number will be added if required by the gem.
|
26
|
+
|
27
|
+
## Example
|
28
|
+
|
29
|
+
|
30
|
+
### SMS sending
|
31
|
+
|
32
|
+
|
33
|
+
require "ovh_savoni"
|
34
|
+
savoni = OvhSavoni::SoAPI.new :sms_user=>"*****",:sms_password=>"*****",:sms_account=>"*****"
|
35
|
+
|
36
|
+
puts savoni.telephony_sms_user_credit_left
|
37
|
+
puts savoni.telephony_sms_user_multi_send("+320000000",["+321111111","+32111111"],"SMS content")
|
38
|
+
|
39
|
+
This will display the credit left, send a SMS to two recipients using a sms user from OVH and display the returned ids.
|
40
|
+
|
41
|
+
### Domain info
|
42
|
+
|
43
|
+
|
44
|
+
require "ovh_savoni"
|
45
|
+
|
46
|
+
savoni = OvhSavoni::SoAPI.new(:nichandle=>"******",:password=>"******")
|
47
|
+
result = savoni.domain_info("example.com")
|
48
|
+
|
49
|
+
'result' is now a Struct with accessors for all response elements defined by OVH. In this case:
|
50
|
+
- dns
|
51
|
+
- nicbilling
|
52
|
+
- nicadmin
|
53
|
+
- domain
|
54
|
+
- modification
|
55
|
+
- expiration
|
56
|
+
- nicowner
|
57
|
+
- authinfo
|
58
|
+
- creation
|
59
|
+
|
60
|
+
## Usage
|
61
|
+
|
62
|
+
### Connection establishment
|
63
|
+
|
64
|
+
|
65
|
+
For actions with authentications:
|
66
|
+
|
67
|
+
savoni = OvhSavoni::SoAPI.new(:nickhandle=>"******",:password=>"******")
|
68
|
+
|
69
|
+
For SMS user:
|
70
|
+
|
71
|
+
savoni = OvhSavoni::SoAPI.new(:sms_user=>"*****",:sms_password=>"*****",:sms_account=>"*****")
|
72
|
+
|
73
|
+
Both can be specified if needed to have always full access:
|
74
|
+
|
75
|
+
savoni = OvhSavoni::SoAPI.new(:nickhandle=>"******",:password=>"password", :sms_user=>"*****",:sms_password=>"*****",:sms_account=>"*****")
|
76
|
+
|
77
|
+
In case you do not want the gem to handle the authentification for you just create a new instance without parameters:
|
78
|
+
(This mean that you will have to perfom a login call explicitely and pass the result with each action that requires authentication.)
|
79
|
+
|
80
|
+
savoni = OvhSavoni::SoAPI.new
|
81
|
+
|
82
|
+
|
83
|
+
### API access
|
84
|
+
|
85
|
+
|
86
|
+
OvhSavoni::SoAPI instances define one method for each SOAP action defined by OVH
|
87
|
+
parameters have to be passed in the same order than the one defined at http://www.ovh.com/soapi/en/ (optional parameters can be omited)
|
88
|
+
savoni.action_name(arg1,arg2,arg3)
|
89
|
+
|
90
|
+
The *session* parameter must be skipped when the SoAPI instance has been initialized with the *nichandle* and *passowrd* parameters
|
91
|
+
|
92
|
+
The *sms_account*, *sms_user*, *sms_password* parameters for sms users methods must also be skipped when setted at initialization.
|
93
|
+
|
94
|
+
N.B. The actions are to be in snake case in order to follow Ruby conventions.
|
95
|
+
|
96
|
+
Results are sub-classes of Struct mapped on the returned XML for comppound values and basic values for simple return values such as String, Dates,etc
|
97
|
+
|
98
|
+
## Contributions
|
99
|
+
|
100
|
+
If you want to contribute, please open an issue or:
|
101
|
+
|
102
|
+
* Fork the project.
|
103
|
+
* Make your feature addition or bug fix.
|
104
|
+
* Send a pull request on Github with a clear description.
|
105
|
+
|
106
|
+
## TODO
|
107
|
+
|
108
|
+
* Tests
|
109
|
+
* Check methods arity
|
110
|
+
|
111
|
+
## Copyright
|
112
|
+
|
113
|
+
Copyright 2011-2012 Thibault Poncelet - See LICENCE for details.
|
data/Rakefile
ADDED
data/lib/ovh_savoni.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Load the gem files in the system
|
2
|
+
require "savon"
|
3
|
+
|
4
|
+
# Configure savon
|
5
|
+
HTTPI.log = false
|
6
|
+
Nori.parser = :nokogiri
|
7
|
+
Savon.configure do |config|
|
8
|
+
config.log = false
|
9
|
+
end
|
10
|
+
|
11
|
+
module OvhSavoni
|
12
|
+
end
|
13
|
+
|
14
|
+
require_relative "./ovh_savoni/error.rb"
|
15
|
+
require_relative "./ovh_savoni/response_builder.rb"
|
16
|
+
require_relative "./ovh_savoni/soapi.rb"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class OvhSavoni::ResponseBuilder
|
2
|
+
|
3
|
+
# Build a Response class
|
4
|
+
def self.build(r,action)
|
5
|
+
if r.is_a?(Hash) # Build the class from the hash
|
6
|
+
const = "OvhSavoniResponse_#{action}"
|
7
|
+
|
8
|
+
klass=Struct.new(const,*r.keys)
|
9
|
+
build_class(klass,action)
|
10
|
+
|
11
|
+
ret = klass.new(*r.values) # Instanciate the class
|
12
|
+
if ret.members.include?(:item) && [:item].is_a?(Array)
|
13
|
+
ret.item
|
14
|
+
else
|
15
|
+
ret
|
16
|
+
end
|
17
|
+
else # Return the value in case of basic type
|
18
|
+
r
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add recursive construction behavior to the class initializer
|
23
|
+
def self.build_class(klass,action)
|
24
|
+
klass.class_eval do
|
25
|
+
define_method(:initialize) do |*args|
|
26
|
+
super(*args)
|
27
|
+
each do |inst|
|
28
|
+
each_pair do |k,v|
|
29
|
+
if v.is_a?(Hash)
|
30
|
+
self[k]=OvhSavoni::ResponseBuilder.build(v,"#{action}__#{k}")
|
31
|
+
# replace response_info.item[] by response_info[]
|
32
|
+
if self[k].respond_to?(:item) && self[k].item.is_a?(Array)
|
33
|
+
self[k]=self[k].item
|
34
|
+
end
|
35
|
+
elsif v.is_a?(Array)
|
36
|
+
self[k].map!{|i| OvhSavoni::ResponseBuilder.build(i,"#{action}__#{k}")}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
class OvhSavoni::SoAPI
|
2
|
+
# Init Class
|
3
|
+
class << self
|
4
|
+
attr_reader :soap
|
5
|
+
end
|
6
|
+
# Initialize soap connection
|
7
|
+
@soap = Savon::Client.new do
|
8
|
+
wsdl.document =File.expand_path("../../soapi-dlw-1.54.wsdl" , __FILE__)
|
9
|
+
end
|
10
|
+
# Initialize the class structure on the basis of the WSDL file
|
11
|
+
# Meta definition of one method for each action
|
12
|
+
# Return value is the values in return[:#{action}_response][:return]
|
13
|
+
@soap.wsdl.soap_actions.each do |action|
|
14
|
+
arg_names = @soap.wsdl.type_namespaces.find_all do |i|
|
15
|
+
i[0][0]==@soap.wsdl.soap_input(action)
|
16
|
+
end.map{|j| j[0][1]}.compact
|
17
|
+
|
18
|
+
define_method(action) do |*arg_values|
|
19
|
+
begin
|
20
|
+
r = request(action,arg_names,arg_values)["#{action}_response".to_sym][:return]
|
21
|
+
rescue Savon::SOAP::Fault => e
|
22
|
+
raise OvhSavoni::Error.new(e.message)
|
23
|
+
end
|
24
|
+
OvhSavoni::ResponseBuilder.build(r,action)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Create a new instance and connect to OVH if nic and pwd provided
|
29
|
+
def initialize(logins={}, lang=:en)
|
30
|
+
@nichandle = logins[:nichandle]
|
31
|
+
@password = logins[:password]
|
32
|
+
@sms_account = logins[:sms_account]
|
33
|
+
@sms_user = logins[:sms_user]
|
34
|
+
@sms_password= logins[:sms_password]
|
35
|
+
#Connect if login infos provided
|
36
|
+
if @nichandle && @password
|
37
|
+
@session = self.login(@nichandle,@password,lang.to_s)
|
38
|
+
end
|
39
|
+
@session
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
# Handle generic requests
|
44
|
+
def request(method, arg_names, arg_values)
|
45
|
+
structured_args = set_default_args(method,arg_names)
|
46
|
+
preset_args = structured_args.keys
|
47
|
+
custom_args = arg_names[preset_args.size-1..-1]
|
48
|
+
custom_args.each_index do |i|
|
49
|
+
key = custom_args[i].snakecase.to_sym
|
50
|
+
structured_args[key] = arg_values[i]
|
51
|
+
if structured_args[key].is_a?(Array)
|
52
|
+
set_array_arg(structured_args,key,custom_args[i],arg_values[i])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
self.class.soap.request(method) do
|
56
|
+
soap.namespaces["xmlns:soapenc"]="http://schemas.xmlsoap.org/soap/encoding/"
|
57
|
+
http.headers["SOAPAction"] = ""
|
58
|
+
soap.body = structured_args
|
59
|
+
end.body
|
60
|
+
end
|
61
|
+
|
62
|
+
# Add xml attributes for array arguments
|
63
|
+
def set_array_arg(structured_args,key,original_key,value)
|
64
|
+
structured_args[:attributes!] ||= {}
|
65
|
+
# ins0 to workaround savon bug
|
66
|
+
structured_args[:attributes!]["ins0:#{original_key}"]=
|
67
|
+
{ "soapenc:arrayType"=>"xsd:#{structured_args[key].first.class.name.downcase}[]" }
|
68
|
+
structured_args[key]={:item=>value}
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set default args with ones defined at initialization
|
72
|
+
def set_default_args(method,arg_names)
|
73
|
+
default_args={}
|
74
|
+
if arg_names.include?("session") && !@session.nil?
|
75
|
+
default_args[:session] = @session
|
76
|
+
end
|
77
|
+
if arg_names.include?("smsAccount") && !@sms_account.nil?
|
78
|
+
default_args[:smsAccount] = @sms_account
|
79
|
+
end
|
80
|
+
if method.to_s.match(/sms_user/i)
|
81
|
+
if arg_names.include?("login") && !@sms_user.nil?
|
82
|
+
default_args[:login] = @sms_user
|
83
|
+
end
|
84
|
+
if arg_names.include?("password") && !@sms_password.nil?
|
85
|
+
default_args[:password] = @sms_password
|
86
|
+
end
|
87
|
+
end
|
88
|
+
default_args[:order!]=arg_names.dup # Dup to avoid savon changing args
|
89
|
+
default_args
|
90
|
+
end
|
91
|
+
end
|