Skip to main content

Ruby

Pika API Ruby Gem

View on Rubygems: rubygems.org/gems/pika_sdk

Installation

Add this line to your application's Gemfile:

gem 'pika_sdk'

And then execute:

bundle

Or install it yourself as:

gem install pika_sdk

Usage

If you don't have your API key, get one from pika.style. Check the documentation on how to get your API key

Initialise a client

require 'pika_sdk'

client = PikaSdk::Client.new('sk-he2jdus1cbz1dpt4mktgjyvx')

Generate image

response = client.generate_image_from_template('open-graph-image-1', {'title': 'From python sdk new'}, 'base64')
puts response['data']['base64']

Example

Base64 response format

require 'pika_sdk'

client = PikaSdk::Client.new('sk-he2jdus1cbz1dpt4mktgjyvx')

response = client.generate_image_from_template('open-graph-image-1', {'title': 'From ruby sdk'}, 'base64')
puts response['data']['base64']

Base64 output

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABLAAAAJ2CAYAAABPQHtcAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3XmYJXdZL/Bvna37dM90FghLCBAQkC1BCBAMShLFBJAgKnofroBeFUUF5LrhiihXcV8BQRYVUUAlIewIGPbFmLCFLWwCYZEtzPR+trp/TM/......

Binary response format

require 'pika_sdk'

client = PikaSdk::Client.new('sk-he2jdus1cbz1dpt4mktgjyvx')

File.open("og.png", "w") do |file|
response = client.generate_image_from_template('open-graph-image-1', {'title': 'From ruby sdk'}, 'binary')
file.binmode
file.write(response)
end

This example writes the binary image to the file og.png

generate_image_from_template

Use this function to generate an image. It takes in 3 arguments

argumentrequireddescription
template_idYesID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1, ...)
modificationsYesModifications for the selected template.
response_formatNobase64, url or binary (Defaults to base64).

For available templates and their modifications refer image generation api templates