Orshot Logo
OrshotDocs

Ruby

Get started with Orshot Ruby SDK

Installation

Add this line to your application's Gemfile:

gem 'orshot'

And then execute:

$ bundle

Or install it yourself as:

$ gem install orshot

Initialise a client

require 'orshot'
client = Orshot::Client.new('<ORSHOT_API_KEY>')

Render from a template

response = client.render_from_template({
  'template_id' => 'open-graph-image-1',
  'modifications' => {'title': 'From ruby sdk new'},
  'response_type' => 'base64',
  'response_format' => 'png'
})

Generate a Signed URL

response = client.generate_signed_url({
  'template_id' => 'open-graph-image-1',
  'modifications' => {'title': 'From ruby sdk new'},
  'render_type' => 'images',
  'response_format' => 'png',
  'expires_at': 1744276943
})

Example

base64 response format

require 'orshot'
client = Orshot::Client.new('<ORSHOT_API_KEY>')
response = client.render_from_template({
  'template_id' => 'open-graph-image-1', 
  'modifications' => {'title': 'From ruby sdk new'}, 
  'response_type' => 'base64', 
  'response_format' => 'png'
})

binary response format

require 'orshot'
 
client = Orshot::Client.new('<ORSHOT_API_KEY>')
 
File.open("og.png", "w") do |file|
  response = client.render_from_template({
    'template_id' => 'open-graph-image-1',
    'modifications' => {'title': 'From ruby sdk new'},
    'response_type' => 'binary',
    'response_format' => 'png'
  })
  file.binmode
  file.write(response)
end

Data is written to the file og.png

url response format

require 'orshot'
client = Orshot::Client.new('<ORSHOT_API_KEY>')
response = client.render_from_template({
  'template_id' => 'open-graph-image-1', 
  'modifications' => {'title': 'From ruby sdk new'}, 
  'response_type' => 'url', 
  'response_format' => 'png'
})

Signed URL

require 'orshot'
client = Orshot::Client.new('<ORSHOT_API_KEY>')
response = client.generate_signed_url({
  'template_id' => 'open-graph-image-1', 
  'modifications' => {'title': 'From ruby sdk new'}, 
  'render_type' => 'images', 
  'response_format' => 'png', 
  'expires_at' => 1744276943
})

render_from_template

Use this function to render an image/pdf. This method accepts a hash with the following keys

keyrequireddescription
template_idYesID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1, ...)
modificationsYesModifications for the selected template.
response_typeNobase64, binary, url (Defaults to base64).
response_formatNopng, webp, pdf, jpg, jpeg (Defaults to png).

For available templates and their modifications refer Orshot Templates Page

generate_signed_url

Use this function to generate signed URL. This method accepts a hash with the following keys

keyrequireddescription
template_idYesID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1, ...)
modificationsYesModifications for the selected template.
expires_atYesExpires at in unix timestamp (Number).
render_typeNoimages, pdfs (Defaults to images).
response_formatNopng, webp, pdf, jpg, jpeg (Defaults to png).

On this page