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.
- #job_proposals(partner_id: nil) ⇒ Object
- #misc(partner_id: nil) ⇒ Object
- #shutdown ⇒ Object
- #statistics(partner_id: nil) ⇒ 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.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ba_upload/connection.rb', line 8 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.
6 7 8 |
# File 'lib/ba_upload/connection.rb', line 6 def m @m end |
Instance Method Details
#error_files(partner_id: nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/ba_upload/connection.rb', line 27 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 |
#job_proposals(partner_id: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ba_upload/connection.rb', line 44 def job_proposals(partner_id: nil) url = base_url(partner_id) + "VV/" m.get(url) m.page.links.reject { |l| l.href.to_s[/^\?|mailto:/] || l.href == "/" }.map do |link| JobProposalFile.new(link) end rescue Mechanize::ResponseCodeError => e return [] if e.response_code.to_i == 404 raise end |
#misc(partner_id: nil) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/ba_upload/connection.rb', line 56 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
63 64 65 |
# File 'lib/ba_upload/connection.rb', line 63 def shutdown m.shutdown end |
#statistics(partner_id: nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/ba_upload/connection.rb', line 36 def statistics(partner_id: nil) url = base_url(partner_id) + "Statistiken" m.get(url) m.page.links_with(text: /xlsx/).map do |link| StatisticFile.new(link) end end |
#upload(file: nil, partner_id: nil) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ba_upload/connection.rb', line 19 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 |