Class: TicketPlugin

Inherits:
Plugin
  • Object
show all
Defined in:
plugins/ticket/ticket.rb

Overview

TicketPlugin serves static and disposable data and images. It accepts Magick::Image objects too to render them only when really needed. Each serve-call returns an unique uri to pass to the client. It performs clean-ups based on session and request time-outs.

It’s available to other plugins as @plugins.ticket

Defined Under Namespace

Classes: BlobObj

Instance Method Summary collapse

Instance Method Details

#del_file(msg, file_id) ⇒ nil

Removes a downloadable file resource served from memory.

Does not delete any files from the file system.

Parameters:

  • msg (Message)

    The message instance.

  • file_id (String)

    The file url returned by #serve_file

Returns:

  • (nil)


218
219
220
# File 'plugins/ticket/ticket.rb', line 218

def del_file( msg, file_id )
  @ticketserve.del_file( file_id, msg.ses_id )
end

#del_img(msg, img_id) ⇒ nil

Removes a downloadable file resource served from memory.

Does not delete any files from the file system.

Parameters:

  • msg (Message)

    The message instance.

  • img_id (String)

    The image url returned by #serve_img

Returns:

  • (nil)


242
243
244
# File 'plugins/ticket/ticket.rb', line 242

def del_img( msg, img_id )
  @ticketserve.del_img( img_id, msg.ses_id )
end

#del_obj(msg, ticket_id) ⇒ nil

Deletes a custom object served by #serve_obj

Parameters:

  • msg (Message)

    The message instance.

  • ticket_id (String)

    The object url returned by #serve_img

Returns:

  • (nil)


280
281
282
# File 'plugins/ticket/ticket.rb', line 280

def del_obj( msg, ticket_id )
  @ticketserve.del_blobobj( ticket_id, msg.ses_id )
end

#del_rsrc(rsrc_id) ⇒ nil

Removes static resource served by #serve_rsrc

Parameters:

  • rsrc_id (String)

    The object url returned by #serve_rsrc

Returns:

  • (nil)


289
290
291
# File 'plugins/ticket/ticket.rb', line 289

def del_rsrc( rsrc_id )
  @ticketserve.del_rsrc( rsrc_id )
end

#del_upload(ticket_id, row_id) ⇒ nil

Removes the uploaded data matching both ticket id as well as row id.

Parameters:

  • ticket_id (String)

    The key for the upload, returned by #upload_key

  • row_id (Number)

    The row id returned by #get_uploads

Returns:

  • (nil)


319
320
321
# File 'plugins/ticket/ticket.rb', line 319

def del_upload( ticket_id, row_id )
  @ticketserve.del_upload( ticket_id, row_id )
end

#del_uploads(msg, ticket_id) ⇒ nil

Removes all uploaded data matching the ticket id

Parameters:

  • msg (Message)

    The message instance.

  • ticket_id (String)

    The key for the upload, returned by #upload_key

Returns:

  • (nil)


329
330
331
# File 'plugins/ticket/ticket.rb', line 329

def del_uploads( msg, ticket_id )
  @ticketserve.del_uploads( ticket_id, msg.ses_id )
end

#get_uploads(ticket_id, with_data = false) ⇒ Array

Returns a list of uploads matching the ticket id.

Parameters:

  • ticket_id (String)

    The key for the upload, returned by #upload_key

  • with_data (Boolean) (defaults to: false)

    Return data also

Returns:

  • (Array)

    List of uploaded data matching the ticket_id



309
310
311
# File 'plugins/ticket/ticket.rb', line 309

def get_uploads( ticket_id, with_data=false )
  @ticketserve.get_uploads( ticket_id, with_data )
end

#proto_objBlobObj

Returns to be used for custom objects served by #serve_obj.

Returns:



259
260
261
# File 'plugins/ticket/ticket.rb', line 259

def proto_obj
  return BlobObj
end

#serve(msg, content, format = 'PNG', type = :img) ⇒ String

Serves an RMagick::Image object accessible by a disposable ticket URL.

Parameters:

  • msg (Message)

    The message instance.

  • content (#to_blob)

    Image data to serve

  • format (String) (defaults to: 'PNG')

    To pass on as a { self.format = format } block of content#to_blob

  • type (Symbol) (defaults to: :img)

    The type of the object.

Returns:

  • (String)

    Disposable URL. Destroyed after being requested.



178
179
180
# File 'plugins/ticket/ticket.rb', line 178

def serve( msg, content, format='PNG', type=:img )
  @ticketserve.serve( msg, content, format, type )
end

#serve_file(msg, content = '', content_type = 'text/plain', filename = nil) ⇒ String

Serves a downloadable file resource to be served from memory using a generated url.

Parameters:

  • msg (Message)

    The message instance.

  • content (String) (defaults to: '')

    The file attachment file data in binary.

  • content_type (String) (defaults to: 'text/plain')

    The content-type of the file attachment.

  • filename (String) (defaults to: nil)

    The filename of the download (not the url)

Returns:

  • (String)

    Disposable URL. Destroyed after being requested.



230
231
232
# File 'plugins/ticket/ticket.rb', line 230

def serve_file( msg, content='', content_type='text/plain', filename=nil )
  @ticketserve.serve_file( msg, content, content_type, filename )
end

#serve_img(msg, content, format = 'PNG', type = :img) ⇒ String

Serves a downloadable file resource to be served from memory using a generated url.

Parameters:

  • msg (Message)

    The message instance.

  • content (#to_blob)

    Image data to serve

  • format (String) (defaults to: 'PNG')

    To pass on as a { self.format = format } block of content#to_blob

  • type (Symbol) (defaults to: :img)

    The type of the object.

Returns:

  • (String)

    Disposable URL. Destroyed after being requested.



254
255
256
# File 'plugins/ticket/ticket.rb', line 254

def serve_img( msg, content, format='PNG', type=:img )
  @ticketserve.serve_img( msg, content, format, type )
end

#serve_obj(msg, blob_obj, no_expire = false) ⇒ String

Serves custom object using the BlobObj API (Binary Large Object)

Parameters:

  • msg (Message)

    The message instance.

  • blob_obj (BlobObj)

    The custom object to serve.

  • no_expire (Boolean) (defaults to: false)

    When true, keeps in memory until #del_obj is called manually.

Returns:

  • (String)

    URL. Destroyed after being requested, unless no_expire is true.



270
271
272
# File 'plugins/ticket/ticket.rb', line 270

def serve_obj( msg, blob_obj, no_expire=false )
  @ticketserve.serve_blobobj( msg, blob_obj, no_expire )
end

#serve_rsrc(content, content_type) ⇒ String

Serves static resource as from raw binary data.

Parameters:

  • content (String)

    Any binary data to serve

  • content_type (String)

    The content-type to serve the content as.

Returns:

  • (String)

    A static url. Use #del_rsrc manually to free the memory occupied by the content.



299
300
301
# File 'plugins/ticket/ticket.rb', line 299

def serve_rsrc( content, content_type )
  @ticketserve.serve_rsrc( content, content_type )
end

#set_favicon(ico_data, content_type = false) ⇒ nil

Sets a custom favicon for RSence

Parameters:

  • ico_data (String)

    Favicon-compatible image data in binary.

  • content_type (String) (defaults to: false)

    The content-type of the favicon image data.

Returns:

  • (nil)


206
207
208
# File 'plugins/ticket/ticket.rb', line 206

def set_favicon( ico_data, content_type=false )
  @ticketserve.set_favicon( ico_data, content_type )
end

#upload_key(msg, value_key, max_size = 1000000, mime_allow = /(.*?)\/(.*?)/, allow_multi = true) ⇒ String

Allocates an upload slot and returns the ticket id to use for #get_uploads, #del_upload and #del_uploads

Parameters:

  • msg (Message)

    The message instance.

  • value_key (String)

    The key for the value associated with the upload. See RSence::HValue#value_id

  • max_size (Number) (defaults to: 1000000)

    The maximum size allowed to upload.

  • mime_allow (RegExp) (defaults to: /(.*?)\/(.*?)/)

    A regular expression to match what types of data are allowed to be uploaded

  • allow_multi (Boolean) (defaults to: true)

    When false, allows uploading only once per key.

Returns:



342
343
344
# File 'plugins/ticket/ticket.rb', line 342

def upload_key( msg, value_key, max_size=1000000, mime_allow=/(.*?)\/(.*?)/, allow_multi=true )
  @ticketserve.upload_key( msg, value_key, max_size, mime_allow, allow_multi )
end