Class: Cute::G5K::G5KRest Private
- Inherits:
-
Object
- Object
- Cute::G5K::G5KRest
- Defined in:
- lib/cute/g5k_api.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Manages the low level operations for communicating with the REST API.
Instance Attribute Summary collapse
- #user ⇒ Object readonly private
Instance Method Summary collapse
-
#delete_json(path) ⇒ Object
private
Deletes a resource on the server.
-
#follow_parent(obj) ⇒ Object
private
The parent link.
-
#get_json(path) ⇒ Hash
private
The HTTP response.
-
#initialize(uri, api_version, user, pass, on_error) ⇒ G5KRest
constructor
private
Initializes a REST connection.
-
#post_json(path, json) ⇒ Object
private
Creates a resource on the server.
-
#resource(path) ⇒ Object
private
Returns a resource object.
Constructor Details
#initialize(uri, api_version, user, pass, on_error) ⇒ G5KRest
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes a REST connection
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/cute/g5k_api.rb', line 200 def initialize(uri,api_version,user,pass,on_error) @user = user @pass = pass @api_version = api_version.nil? ? "sid" : api_version if (user.nil? or pass.nil?) @endpoint = uri # Inside Grid'5000 else user_escaped = CGI.escape(user) pass_escaped = CGI.escape(pass) @endpoint = "https://#{user_escaped}:#{pass_escaped}@#{uri.split("https://")[1]}" end machine =`uname -ov`.chop @user_agent = "ruby-cute/#{VERSION} (#{machine}) Ruby #{RUBY_VERSION}" @api = RestClient::Resource.new(@endpoint, :timeout => 30) @on_error = on_error test_connection end |
Instance Attribute Details
#user ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
194 195 196 |
# File 'lib/cute/g5k_api.rb', line 194 def user @user end |
Instance Method Details
#delete_json(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes a resource on the server
257 258 259 260 261 262 263 |
# File 'lib/cute/g5k_api.rb', line 257 def delete_json(path) begin return resource(path).delete() rescue RestClient::InternalServerError => e raise RequestFailed.new("Service internal error", e) end end |
#follow_parent(obj) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the parent link.
266 267 268 |
# File 'lib/cute/g5k_api.rb', line 266 def follow_parent(obj) get_json(obj.rel_parent) end |
#get_json(path) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the HTTP response.
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/cute/g5k_api.rb', line 228 def get_json(path) begin r = resource(path).get(:content_type => "application/json", :user_agent => @user_agent) rescue => e handle_exception(e) end return G5KJSON.parse(r) end |
#post_json(path, json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a resource on the server
242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/cute/g5k_api.rb', line 242 def post_json(path, json) begin r = resource(path).post(json.to_json, :content_type => "application/json", :accept => "application/json", :user_agent => @user_agent) rescue => e handle_exception(e) end return G5KJSON.parse(r) end |
#resource(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a resource object
221 222 223 224 |
# File 'lib/cute/g5k_api.rb', line 221 def resource(path) path = path[1..-1] if path.start_with?('/') return @api[path] end |