Class: Plotlyrb::PlotImage
- Inherits:
-
Object
- Object
- Plotlyrb::PlotImage
- Defined in:
- lib/plotlyrb/plot_image.rb
Constant Summary collapse
- VALID_IMAGE_FORMATS =
[:png, :svg, :pdf, :eps]
Instance Method Summary collapse
-
#initialize(headers) ⇒ PlotImage
constructor
A new instance of PlotImage.
- #plot_image(data, image_path, image_type, layout = {}) ⇒ Object
Constructor Details
#initialize(headers) ⇒ PlotImage
Returns a new instance of PlotImage.
9 10 11 12 13 |
# File 'lib/plotlyrb/plot_image.rb', line 9 def initialize(headers) @headers = headers @https = Net::HTTP.new(ApiV2::IMAGES.host, ApiV2::IMAGES.port) @https.use_ssl = true end |
Instance Method Details
#plot_image(data, image_path, image_type, layout = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/plotlyrb/plot_image.rb', line 15 def plot_image(data, image_path, image_type, layout = {}) raise "image_type #{image_type} not supported" unless VALID_IMAGE_FORMATS.include?(image_type) payload = { :figure => { :data => data, :layout => layout }, :format => image_type.to_s }.to_json request = Net::HTTP::Post.new(ApiV2::IMAGES.path, @headers) request.body = payload response = @https.request(request) image_path_with_ext = "#{image_path}" IO.binwrite(image_path_with_ext, response.body) end |