ovh-api 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09ec251cfc3845c59d2ea805bb682de1cdf83d77
4
- data.tar.gz: d1e8e9dd24eb817ddc6e0f99ef3e45b2b51f6954
3
+ metadata.gz: e933d314a1697da8e6d10453aac95a8ffa1190fc
4
+ data.tar.gz: 3ca3fdc93e82ecc7b65767619212acf1b8067b00
5
5
  SHA512:
6
- metadata.gz: 39c4251f6441ff93d57924ee7c304dccff403d44fb9b4e342565650d87b850521d272395cda0ad5399f42ae8ec848ee3fe3774766254b8663e0b7be914cc9310
7
- data.tar.gz: 75312cf3524eb10c3cf4b34769aa8349ffc77ef26aca224ac8f8a9bc23f709e6f5baa45c4104ccecd8a54f2a65bf3b75dcf8a78c5f353c5061a1d0a9de296636
6
+ metadata.gz: 47356d383cd69a81c26971a86e05587f7f052fcd1c4cca53a889cbe900574e648410acbfb46b63ae88f3f089eef45a90ba11c4db61078ef728737afa7c4117f8
7
+ data.tar.gz: aed83ad2769f62bee3fe0eb99275b16c6ee7aebd0cbb74ede55fe968c219fc74f4bb9c8a67cda22517e53ee4e670c962984eabca8c274591a3fc48a473db665b
@@ -65,6 +65,32 @@ module OVHApi
65
65
  signature
66
66
  end
67
67
 
68
+
69
+ # Helper to make a request to the OVH api then return the body as parsed JSON tree
70
+ #
71
+ # If body cannot be parsed, error is rescued and :body is set to nil.
72
+ #
73
+ # This function raise OVHApiNotImplementedError if method is not valid
74
+ #
75
+ # @param method [Symbol]: :get, :post, :put, :delete
76
+ # @param url [String]
77
+ # @return [Hash] { :resp => [Net::HTTPResponse] response, :body => [Hash|NilClass] (:resp body JSON parsed) }
78
+ def request_json(method, url)
79
+ raise OVHApiNotImplementedError.new(
80
+ "#{method.to_s} is not implemented. Please refere to documentation."
81
+ ) unless [:get, :post, :delete, :put].include?method
82
+ resp = self.public_send(method, url)
83
+ body = nil
84
+ begin
85
+ body = JSON.parse(resp.body)
86
+ rescue
87
+ end
88
+ return {
89
+ :resp => resp,
90
+ :body => body
91
+ }
92
+ end
93
+
68
94
  # Make a get request to the OVH api
69
95
  #
70
96
  # @param url [String]
@@ -1,4 +1,5 @@
1
1
  module OVHApi
2
2
  class OVHApiError < RuntimeError; end
3
3
  class OVHApiNotConfiguredError < OVHApiError; end
4
+ class OVHApiNotImplementedError < OVHApiError; end
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module OVHApi
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovh-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Laurès