lib/ovh-api/client.rb
# Helper to make a request to the OVH api then return the body as parsed JSON tree
#
# If body cannot be parsed, error is rescued and :body is set to nil.
#
# This function raise OVHApiNotImplementedError if method is not valid
#
# @param method [Symbol]: :get, :post, :put, :delete
# @param path [String]
# @param arguments: [Hash]: will be encoded to be URL friendly with URI.encode_www_form and then pass as URL parameters
# @param body [String]: function parameters to be JSONified and sent as body in the request
# @return [Hash] { :resp => [Net::HTTPResponse] response, :body => [Hash|NilClass] (:resp body JSON parsed)  }
Helper to make a request to the OVH api then return the body as parsed JSON tree
If body cannot be parsed, error is rescued and :body is set to nil.

This function raise OVHApiNotImplementedError if method is not valid
Helper to make a request to the OVH api then return the body as parsed JSON tree If body cannot be parsed error is rescued and : body is set to nil . This function raise OVHApiNotImplementedError if method is not valid
def request_json(method, path, arguments = nil, body = '')
      raise OVHApiNotImplementedError.new(
        "#{method.to_s} is not implemented. Please refere to documentation."
      ) unless [:get, :post, :delete, :put].include?method
      method_str = method.to_s.upcase
      if arguments.nil? then
        url = path
      else
        url = "#{path}?#{URI.encode_www_form(arguments)}"
      end
      resp = request(url, method_str, body)
      body = nil
      begin
        body = JSON.parse(resp.body)
      rescue
      end
      return {
        :resp => resp,
        :body => body
      }
    end
def request_json ( method , path , arguments = nil , body = '' ) raise OVHApiNotImplementedError . new ( "#{method.to_s} is not implemented. Please refere to documentation." ) unless [ :get , :post , :delete , :put ] . include? method method_str = method . to_s . upcase if arguments . nil? then url = path else url = "#{path}?#{URI.encode_www_form(arguments)}" end resp = request ( url , method_str , body ) body = nil begin body = JSON . parse ( resp . body ) rescue end return { :resp => resp , :body => body } end
Helper to make a request to the OVH api then return the body as parsed JSON tree
If body cannot be parsed, error is rescued and :body is set to nil.
Helper to make a request to the OVH api then return the body as parsed JSON tree If body cannot be parsed error is rescued and : body is set to nil .
{ :resp => [Net::HTTPResponse] response, :body => [Hash|NilClass] (:resp body JSON parsed) }
{ : resp = > [ Net :: HTTPResponse ] response : body = > [ Hash|NilClass ] ( : resp body JSON parsed ) }
Hash
method
: :get, :post, :put, :delete
: : get : post : put : delete
path
<not_specific>
arguments
<not_specific>
body
: function parameters to be JSONified and sent as body in the request
: function parameters to be JSONified and sent as body in the request
<not_specific>
None
arguments:
<not_specific>
: will be encoded to be URL friendly with URI.encode_www_form and then pass as URL parameters
: will be encoded to be URL friendly with URI . encode_www_form and then pass as URL parameters