class Pijaz::SDK::Product
Public Class Methods
Create a new product instance.
@param inParameters
A hash with the following key/value pairs. serverManager: Required. An instance of the ServerManager class. workflowId: Required. The workflow ID for the product. renderParameters: Optional. A hash of render parameters to be included with every render request. They depend on the product, but these are typically supported params: message: Primary message to display. font: Font to use. halign: Horizontal justification (left, center, right, full). valign: Vertical justification (top, middle, bottom, full, even). quality: Image quality to produce (0-100).
# File lib/pijaz/product.rb, line 103 def initialize(inParameters) params = inParameters @serverManager = params['serverManager'] @workflowId = params['workflowId'] @renderParameters = (params['renderParameters'] or {}) @accessInfo = nil @productPropertyDefaults = {} end
Public Instance Methods
Set the final render parameters for the product.
@param additionalParams
A hash of additional render parameters.
# File lib/pijaz/product.rb, line 188 def _setFinalParams(additionalParams) finalParams = Marshal.load(Marshal.dump(@renderParameters)) if additionalParams.is_a?(Hash) additionalParams.each do |k, v| if v finalParams[k] = v end end end finalParams['workflow'] = @workflowId finalParams end
Clear out all current render parameters.
Any parameters currently stored with the product, including those passed when the product was instantiated, are cleared.
# File lib/pijaz/product.rb, line 37 def clearRenderParameters() @renderParameters = {} end
Build a fully formed URL which can be used to make a request for the product from a rendering server.
@param additionalParams
Optional. A hash of additional render parameters to be used for this request only.
@return
A fully formed URL that can be used in a render server HTTP request.
# File lib/pijaz/product.rb, line 49 def generateUrl(additionalParams={}) finalParams = self._setFinalParams(additionalParams) options = {} options['product'] = self options['renderParameters'] = finalParams params = @serverManager.buildRenderCommand(options) if params then url = @serverManager.buildRenderServerUrlRequest(params) url end end
Return the access info for the product.
Required method for products passed to the ServerManager
object. @return
The access info.
# File lib/pijaz/product.rb, line 66 def getAccessInfo() @accessInfo end
Retrieve a render parameter.
@param key: The parameter name. @return:
The render parameter, or the default render parameter if not set.
# File lib/pijaz/product.rb, line 75 def getRenderParameter(key) value = (@renderParameters[key] or @productPropertyDefaults[key]) value end
Return the workflow ID.
@return:
The workflow ID.
# File lib/pijaz/product.rb, line 84 def getWorkflowId() @workflowId end
Convenience method for saving a product directly to a file.
This takes care of generating the render URL, making the request to the render server for the product, and saving to a file.
@param filepath
Required. The full file path.
@param additionalParams
Optional. A hash of additional render parameters to be used for this request only.
@return
True on successful save of the file, false otherwise.
# File lib/pijaz/product.rb, line 124 def saveToFile(filepath, additionalParams) url = self.generateUrl(additionalParams) if url response = open(url).read if response File.open(filepath, 'wb') do |fo| fo.write response return true end end end false end
Set the access info for the product.
Required method for products passed to the ServerManager
object.
# File lib/pijaz/product.rb, line 141 def setAccessInfo(accessInfo) if accessInfo @accessInfo = accessInfo else @accessInfo = nil end end
Set a render parameter on the product.
@param key
The parameter name. Optionally a hash of parameter key/value pairs can be passed as the first argument, and each pair will be added.
@param newValue
The parameter value.
# File lib/pijaz/product.rb, line 156 def setRenderParameter(key, newValue=nil) if key.is_a?(Hash) key.each do |k, v| self.setRenderParameter(k, v) end else param = @renderParameters[key] default = @productPropertyDefaults[key] if param != newValue if newValue == nil or newValue == default @renderParameters[key] = nil else @renderParameters[key] = newValue end end end end
Set the workflow ID.
# File lib/pijaz/product.rb, line 175 def setWorkflowId(newWorkflowId) if @workflowId != newWorkflowId @accessInfo = nil @workflowId = newWorkflowId end end