Method: Rbeapi::Eapilib::EapiConnection#send
- Defined in:
- lib/rbeapi/eapilib.rb
#send(data, opts) ⇒ Hash
This method will send the request to the node over the specified transport and return a response message with the contents from the eAPI response. eAPI responds to request messages with either a success message or failure message.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/rbeapi/eapilib.rb', line 269 def send(data, opts) request = Net::HTTP::Post.new('/command-api') request.body = JSON.dump(data) request.basic_auth @username, @password open_timeout = opts.fetch(:open_timeout, @open_timeout) read_timeout = opts.fetch(:read_timeout, @read_timeout) begin @transport.open_timeout = open_timeout @transport.read_timeout = read_timeout response = @transport.request(request) decoded = JSON(response.body) if decoded.include?('error') code = decoded['error']['code'] msg = decoded['error']['message'] raise CommandError.new(msg, code) end rescue Timeout::Error raise ConnectionError, 'unable to connect to eAPI' end decoded end |