Ruby wrapper
The Ruby wrapper allows you to seamlessly interface with the Cloudimage API.
Supported with Ruby 2.4+, JRuby, and TruffleRuby github
Installation
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
Usage
The only requirement to get started is your customer token. You can find it within your Admin interface.
In order to interact with Cloudimage, we'll first initialize a client service object:
The Cloudimage client accepts the following options:
token
string
Required if cname
is missing.
cname
string
Required if token
is missing. See CNAME.
salt
string
Optional. See Security. Needed if you are using URL sealing or URL signatures.
signature_length
integer
Optional. Integer value in the range 6..40
. Defaults to 18.
sign_urls
boolean
Optional. Defaults to true. See Security.
aliases
hash
Optional. See URL aliases.
The calling path on the client object returns an instance of Cloudimage::URI. It accepts the path to the image as a string and we we will use it to build Cloudimage URLs.
Here are some common approaches for constructing Cloudimage URLs using this gem:
Hash of params
Pass a hash to to_url
. Every key becomes a param in the final Cloudimage URL so this gives you the freedom to pass arbitrary params if need be.
Chainable helpers
Every param supported by Cloudimage can be used as a helper method.
While every key passed into the to_url
method gets appended to the URL, chainable helper methods will throw a NoMethodError
when using an unsupported method.
This is useful for catching typos and identifying deprecated methods in case Cloudimage's API changes.
Method aliases
The gem comes with a handful of useful aliases. Consult the Cloudimage::Params module for their full list.
From the example above you can see that parameters that only serve as a flag don't need to accept arguments and will be translated into param=1
within the final URL.
For the full set of parameters and detailed implementation instructions, please consult the github page.
Last updated