Class: BaUpload::Connection
- Inherits:
-
Object
- Object
- BaUpload::Connection
- Defined in:
- lib/ba_upload/connection.rb
Instance Attribute Summary collapse
-
#m ⇒ Object
readonly
Returns the value of attribute m.
Instance Method Summary collapse
- #error_files(partner_id: nil) ⇒ Object
-
#initialize(key_file, cert_file, ca_cert_file) ⇒ Connection
constructor
A new instance of Connection.
- #misc(partner_id: nil) ⇒ Object
- #shutdown ⇒ Object
- #upload(file: nil, partner_id: nil) ⇒ Object
Constructor Details
#initialize(key_file, cert_file, ca_cert_file) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ba_upload/connection.rb', line 6 def initialize(key_file, cert_file, ca_cert_file) require 'mechanize' @key = key_file @cert = cert_file @ca_cert = ca_cert_file @m = Mechanize.new @m.key = @key.path @m.ca_file = @ca_cert.path @m.cert = @cert.path end |
Instance Attribute Details
#m ⇒ Object (readonly)
Returns the value of attribute m.
4 5 6 |
# File 'lib/ba_upload/connection.rb', line 4 def m @m end |
Instance Method Details
#error_files(partner_id: nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ba_upload/connection.rb', line 25 def error_files(partner_id: nil) url = base_url(partner_id) m.get url links = m.page.links_with(text: /ESP|ESV/) links.map do |link| ErrorFile.new(link) end end |
#misc(partner_id: nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/ba_upload/connection.rb', line 34 def misc(partner_id: nil) url = base_url(partner_id) m.get url m.page.links_with(text: /sonstiges/).first.click m.page.links.reject { |i| i.href[/^\?|mailto:/] || i.href == '/' } end |
#shutdown ⇒ Object
41 42 43 |
# File 'lib/ba_upload/connection.rb', line 41 def shutdown m.shutdown end |
#upload(file: nil, partner_id: nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ba_upload/connection.rb', line 17 def upload(file: nil, partner_id: nil) url = base_url(partner_id) + "in/" m.get url form = m.page.forms.first form.file_uploads.first.file_name = file form.submit end |