The following code uses Stingray's RESTful API to a file to the extra directory. The code is written in Ruby. This program adds the file 'validserialnumbers' to the extra directory and if the file already exists it will be overwrite it. If this is not the desired behavior, code can be added to to check for the existence of the file as was done in the addpool example.
addextrafile.rb
require 'rest_client' require 'base64' require 'json' fileName = 'validserialnumbers' url = 'https://stingray.example.com:9070/api/tm/1.0/config/active/extra/' + fileName auth = 'Basic ' + Base64.encode64('admin:admin') validSerialNumbers = < 'application/octet-stream', :authorization => auth}) # If the file already exists, it will be replaced with this version and 204 will be returned # otherwise 201 will be returned. if response.code == 201 || response.code == 204 puts "File #{fileName} added" else puts "Bad status code #{response.code} when adding file #{fileName}" end rescue => e puts "Error: URL=#{url} Error: #{e.message}" end
Running the example
This code was tested with Ruby 1.9.3 and version 1.6.7 of the rest-client module.
Run the Ruby script as follows:
$ addextrafile.rb
File added
Notes
Since this is a file and not a configuration resource, JSON will not be used and the MIME type will be "application/octet-stream". Another difference when dealing with files is how Stingray handles adding a file that already exists. If the file already exists, Stingray will overwrite the it and return a HTTP status code of 204. If the file doesn't already exist, the HTTP status code will be a 201.
Read More