# File lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb, line 38
  def request(resource, data='', method='GET')
    headers = {"Accept" => "application/json", "Content-Type" => "application/json"}
    if(!@auth.nil?)
      headers["Authorization"] = @auth
    end
    safely do
    r = @service.send_request(method, @uri.path + resource, data, headers)
         puts r.body
    res = JSON.parse(r.body)
    res = res[res.keys[0]]

    if(res['response_type'] == "ERROR" and ( (res['error_info']['error_class'] == "PermissionException") or
                                             (res['error_info']['error_class'] == "LoginRequired") ))
      raise "AuthFailure"
    end
    res
  end

  def list_images
    request('/distributions')["distro_infos"]
  end

  def list_plans
    request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
  end

  def list_nodes
    request('/orders;include_inactive=N')["about_orders"]
  end

  def set_server_state(id, state)
    json = {"reboot_request" => {"running_state" => state}}.to_json
    request("/orders/order-#{id}-a/vps/running-state", json, 'PUT')
  end

  def delete_server(id)
    request("/orders/order-#{id}-a/vps",'', 'DELETE')
  end

  def create_server(image_id, plan_code, name)
    json = {:new_vps => {:instantiation_options => {:domain_name => name, :distro => image_id},
                        :pricing_plan_code => plan_code}}.to_json
    request('/orders/new-vps',json, 'POST')[:about_order]
  end
end