Class: GLSMech
- Inherits:
-
Object
- Object
- GLSMech
- Defined in:
- lib/gls_agent/gls_mech.rb
Overview
Utilize mechanize to do stuff on GLS webpage.
Instance Attribute Summary collapse
-
#mech ⇒ Object
Returns the value of attribute mech.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize ⇒ GLSMech
constructor
Setup the mech.
-
#log_to(filename) ⇒ Object
Enable logging to given file.
-
#save_parcel_label(parcel_job, filename) ⇒ Object
Saves parcel label as pdf, does not overwrite file if exists, returns filename that label was saved to.
Constructor Details
#initialize ⇒ GLSMech
Setup the mech.
11 12 13 14 |
# File 'lib/gls_agent/gls_mech.rb', line 11 def initialize @mech = Mechanize.new @mech.user_agent_alias = 'Windows Mozilla' end |
Instance Attribute Details
#mech ⇒ Object
Returns the value of attribute mech.
6 7 8 |
# File 'lib/gls_agent/gls_mech.rb', line 6 def mech @mech end |
#pass ⇒ Object
Returns the value of attribute pass.
8 9 10 |
# File 'lib/gls_agent/gls_mech.rb', line 8 def pass @pass end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/gls_agent/gls_mech.rb', line 7 def user @user end |
Instance Method Details
#log_to(filename) ⇒ Object
Enable logging to given file.
17 18 19 |
# File 'lib/gls_agent/gls_mech.rb', line 17 def log_to filename @mech.log = Logger.new filename end |
#save_parcel_label(parcel_job, filename) ⇒ Object
Saves parcel label as pdf, does not overwrite file if exists, returns filename that label was saved to. returns nil if login or redirection failed.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gls_agent/gls_mech.rb', line 24 def save_parcel_label parcel_job, filename return nil if !login! @user, @pass form = @mech.page.forms.first form.field_with(:name => 'txtName1').value = parcel_job.name form.field_with(:name => 'txtStreet').value = parcel_job.street form.field_with(:name => 'txtBlockNo').value = parcel_job.streetno form.field_with(:name => 'txtZipCodeDisplay').value = parcel_job.zip form.field_with(:name => 'txtCity').value = parcel_job.city form.field_with(:name => 'txtWeight').value = parcel_job.weight @mech.submit(form, form..first) @mech.page.iframes.first.content.save_as filename end |