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)


220
221
222
# File 'plugins/ticket/ticket.rb', line 220

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)


244
245
246
# File 'plugins/ticket/ticket.rb', line 244

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)


282
283
284
# File 'plugins/ticket/ticket.rb', line 282

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)


291
292
293
# File 'plugins/ticket/ticket.rb', line 291

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)


321
322
323
# File 'plugins/ticket/ticket.rb', line 321

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)


331
332
333
# File 'plugins/ticket/ticket.rb', line 331

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



311
312
313
# File 'plugins/ticket/ticket.rb', line 311

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

#openObject



125
126
127
128
129
130
# File 'plugins/ticket/ticket.rb', line 125

def open
  super
  unless RSence.session_manager.nil?
    set_db_state( RSence.session_manager.db_avail )
  end
end

#proto_objBlobObj

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

Returns:



261
262
263
# File 'plugins/ticket/ticket.rb', line 261

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.



180
181
182
# File 'plugins/ticket/ticket.rb', line 180

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.



232
233
234
# File 'plugins/ticket/ticket.rb', line 232

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.



256
257
258
# File 'plugins/ticket/ticket.rb', line 256

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.



272
273
274
# File 'plugins/ticket/ticket.rb', line 272

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.



301
302
303
# File 'plugins/ticket/ticket.rb', line 301

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

#set_db_state(state) ⇒ Object



132
133
134
# File 'plugins/ticket/ticket.rb', line 132

def set_db_state( state )
  @ticketserve.set_db_state( state )
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)


208
209
210
# File 'plugins/ticket/ticket.rb', line 208

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:



344
345
346
# File 'plugins/ticket/ticket.rb', line 344

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