Class: RMB::MechanizeSubmitter
- Defined in:
- lib/mechanize_submitter.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
-
#daemon_name ⇒ Object
Returns the value of attribute daemon_name.
-
#delivery_url ⇒ Object
Returns the value of attribute delivery_url.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#login_url ⇒ Object
Returns the value of attribute login_url.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#connect ⇒ Object
connect
Uses the login_url property, along with the user and password properties, to log in to the rails app. -
#marshal_message_body(message) ⇒ Object
marshal_message_body
Extracts the message body from the rest of the message, and marshals it into a file. -
#properties=(hash) ⇒ Object
properties=(hash) Accepts a hash object containing all of the configuration properties required.
-
#send(message) ⇒ Object
send
This method uses thedelivery_url
property to issue a get request to retrieve thenew document
form from the rails app.
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
7 8 9 |
# File 'lib/mechanize_submitter.rb', line 7 def agent @agent end |
#daemon_name ⇒ Object
Returns the value of attribute daemon_name.
7 8 9 |
# File 'lib/mechanize_submitter.rb', line 7 def daemon_name @daemon_name end |
#delivery_url ⇒ Object
Returns the value of attribute delivery_url.
7 8 9 |
# File 'lib/mechanize_submitter.rb', line 7 def delivery_url @delivery_url end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/mechanize_submitter.rb', line 7 def logger @logger end |
#login_url ⇒ Object
Returns the value of attribute login_url.
7 8 9 |
# File 'lib/mechanize_submitter.rb', line 7 def login_url @login_url end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/mechanize_submitter.rb', line 7 def password @password end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/mechanize_submitter.rb', line 7 def user @user end |
Instance Method Details
#connect ⇒ Object
connect
Uses the login_url property, along with the user and password properties, to log in to the rails app.
31 32 33 34 |
# File 'lib/mechanize_submitter.rb', line 31 def connect super #this code requires completion of the User controller in the main app end |
#marshal_message_body(message) ⇒ Object
marshal_message_body
Extracts the message body from the rest of the message, and marshals it into a file. The name of this file will be submitted to the rails app, along with other message attributes.
38 39 40 41 42 43 44 |
# File 'lib/mechanize_submitter.rb', line 38 def () file = File.join("#{@hash[:working_dir]}", "tmp", "messages", "#{daemon_name}_#{.headers["timestamp"]}.message") File.open(file, "w+") do |f| Marshal.dump(.body, f) end file end |
#properties=(hash) ⇒ Object
properties=(hash) Accepts a hash object containing all of the configuration properties required. These properties are copied into instance variables.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mechanize_submitter.rb', line 11 def properties=(hash) super @hash = hash @daemon_name = "#{RMB::Properties.daemon_prefix}#{hash[:key]}" submitter = hash[:submitter] @user = submitter[:user] || "" @password = submitter[:password] || "" @login_url = submitter[:login_url] || "" @delivery_url = submitter[:delivery_url] || "" begin @agent = WWW::Mechanize.new @agent.user_agent_alias = 'Linux Mozilla' rescue Exception logger.fatal "#{__FILE__}:#{__LINE__} Exception #{$!}" raise end end |
#send(message) ⇒ Object
send
This method uses the delivery_url
property to issue a get request to retrieve the new document
form from the rails app. The form is filled in with message attributes and submitted to the rails app for processing.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mechanize_submitter.rb', line 48 def send() super file = () begin page = agent.get(delivery_url) rescue Exception logger.fatal "#{__FILE__}:#{__LINE__} Exception #{$!}" raise end form = page.forms.first # I can't seem to make the Mechanize code recognize fields as attributes, so # I am forced to treat them as an array form.fields[1].value = @hash[:key] form.fields[2].value = .headers["destination"] form.fields[3].value = .headers["message-id"] form.fields[4].value = .headers["content-type"] form.fields[5].value = .headers["priority"] form.fields[6].value = .headers["content-length"] form.fields[7].value = .headers["timestamp"] form.fields[8].value = .headers["expires"] form.fields[9].value = file #logger.info "final form: #{form.inspect}" #submit the form begin page = agent.submit(form) rescue Exception logger.fatal "#{__FILE__}:#{__LINE__} Exception #{$!}" raise end end |