class Flayyer::FlayyerURL
Attributes
deck[RW]
extension[RW]
meta[RW]
template[RW]
tenant[RW]
variables[RW]
version[RW]
Public Class Methods
create(&block)
click to toggle source
# File lib/flayyer.rb, line 93 def self.create(&block) self.new(&block) end
new(tenant = nil, deck = nil, template = nil, version = nil, extension = 'jpeg', variables = {}, meta = {}) { |self| ... }
click to toggle source
# File lib/flayyer.rb, line 97 def initialize(tenant = nil, deck = nil, template = nil, version = nil, extension = 'jpeg', variables = {}, meta = {}) @tenant = tenant @deck = deck @template = template @version = version @extension = extension @variables = variables @meta = meta yield(self) if block_given? end
Public Instance Methods
href()
click to toggle source
Create a flayyer.com string. If you are on Ruby on Rails please use .html_safe when rendering this string into the HTML
# File lib/flayyer.rb, line 132 def href raise Error.new('Missing "tenant" property') if @tenant.nil? raise Error.new('Missing "deck" property') if @deck.nil? raise Error.new('Missing "template" property') if @template.nil? if @version.nil? "https://flayyer.io/v2/#{@tenant}/#{@deck}/#{@template}.#{@extension}?#{self.querystring}" else "https://flayyer.io/v2/#{@tenant}/#{@deck}/#{@template}.#{@version}.#{@extension}?#{self.querystring}" end end
querystring()
click to toggle source
# File lib/flayyer.rb, line 108 def querystring # Allow accesing the keys of @meta with symbols and strings # https://stackoverflow.com/a/10786575 @meta.default_proc = proc do |h, k| case k when String then sym = k.to_sym; h[sym] if h.key?(sym) when Symbol then str = k.to_s; h[str] if h.key?(str) end end defaults = { __v: @meta[:v].nil? ? Time.now.to_i : @meta[:v], # This forces crawlers to refresh the image __id: @meta[:id] || nil, _w: @meta[:width] || nil, _h: @meta[:height] || nil, _res: @meta[:resolution] || nil, _ua: @meta[:agent] || nil } result = FlayyerHash.new(@variables.nil? ? defaults : defaults.merge(@variables)) result.to_query end