Class: Orsos::Webdownloader
- Inherits:
-
Object
- Object
- Orsos::Webdownloader
- Defined in:
- lib/orsos/webdownloader.rb
Instance Method Summary collapse
- #download_campaign_finance_transactions(from_date:, to_date:, filer_id: nil) ⇒ Object
- #download_candidate_filings(from_date:, to_date: nil) ⇒ Object
- #download_committees(committee_name: '', committee_name_search_type: 'contains') ⇒ Object
-
#initialize(verbose: false, csvbin: nil, stdout: false, filename: nil, raise_error_if_no_data: false) ⇒ Webdownloader
constructor
A new instance of Webdownloader.
- #save(msg, &block) ⇒ Object
- #save_campaign_finance_transactions(from_date:, to_date:, options: {}) ⇒ Object
- #save_candidate_filings(from_date:, to_date:, options: {}) ⇒ Object
- #save_committees(committee_name_contains:, options: {}) ⇒ Object
Constructor Details
#initialize(verbose: false, csvbin: nil, stdout: false, filename: nil, raise_error_if_no_data: false) ⇒ Webdownloader
Returns a new instance of Webdownloader.
10 11 12 13 14 15 16 |
# File 'lib/orsos/webdownloader.rb', line 10 def initialize(verbose: false, csvbin: nil, stdout: false, filename: nil, raise_error_if_no_data: false) @verbose = verbose @csvbin = csvbin @stdout = stdout @filename = filename @raise_error_if_no_data = raise_error_if_no_data end |
Instance Method Details
#download_campaign_finance_transactions(from_date:, to_date:, filer_id: nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/orsos/webdownloader.rb', line 61 def download_campaign_finance_transactions from_date:, to_date:, filer_id: nil set_agent export_page = nil @agent.get("#{@base_url}/orestar/gotoPublicTransactionSearch.do") do |search_page| search_page.form_with(name: 'cneSearchForm') do |form| form.cneSearchTranFiledStartDate = from_date.strftime("%m/%d/%Y") form.cneSearchTranFiledEndDate = to_date.strftime("%m/%d/%Y") form.cneSearchFilerCommitteeId = filer_id unless filer_id.nil? @results_page = @agent.submit(form, form.(value: "Search")) if link = @results_page.link_with(text: "Export To Excel Format") export_page = @agent.click(link) end end end return export_page end |
#download_candidate_filings(from_date:, to_date: nil) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/orsos/webdownloader.rb', line 113 def download_candidate_filings from_date: , to_date: nil set_agent export_page = nil @agent.get("#{@base_url}/orestar/CFSearchPage.do") do |search_page| search_page.form_with(name: 'cfSearchPageForm') do |form| form.cfFilingFromDate = from_date.strftime("%m/%d/%Y") form.cfFilingToDate = to_date.strftime("%m/%d/%Y") @results_page = @agent.submit(form, form.(value: "Submit")) if link = @results_page.link_with(text: "Export") export_page = @agent.click(link) end end end return export_page end |
#download_committees(committee_name: '', committee_name_search_type: 'contains') ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/orsos/webdownloader.rb', line 81 def download_committees committee_name: '', committee_name_search_type: 'contains' set_agent export_page = nil @agent.get("#{@base_url}/orestar/GotoSearchByName.do") do |search_page| @results_page = @agent.post('https://secure.sos.state.or.us/orestar/CommitteeSearchFirstPage.do', { buttonName: '', page: 100, committeeName: committee_name, committeeNameMultiboxText: committee_name_search_type, committeeId: '', firstName: '', firstNameMultiboxText: 'contains', lastName: '', lastNameMultiboxText: 'contains', discontinuedSOO: 'on', submit: 'Submit', approvedSOO: 'true', pendingApprovalSOO: 'false', insufficientSOO: 'false', resolvedSOO: 'false', rejectedSOO: 'false' }) if link = @results_page.link_with(text: "Export To Excel Format") export_page = @agent.click(link) end end return export_page end |
#save(msg, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/orsos/webdownloader.rb', line 36 def save msg, &block puts "[ORSOS] [#{Time.now}] downloading #{msg}" if !@stdout export_page = block.call if export_page.nil? if @raise_error_if_no_data raise "could not download file. no data returned" elsif !@stdout puts "[ORSOS] [#{Time.now}] no data returned" end else data = !@csvbin.nil? ? convert_to_csv(export.body) : export.body if @stdout $stdout.write data else File.open(@filename, 'wb') {|f| f.write(data) } puts "[ORSOS] [#{Time.now}] saved #{msg} to #{@filename}" end end end |
#save_campaign_finance_transactions(from_date:, to_date:, options: {}) ⇒ Object
18 19 20 21 22 |
# File 'lib/orsos/webdownloader.rb', line 18 def save_campaign_finance_transactions from_date:, to_date:, options: {} save("transactions for #{from_date.strftime('%Y-%m-%d')} till #{to_date.strftime('%Y-%m-%d')}") do download_campaign_finance_transactions from_date: from_date, to_date: to_date, filer_id: ['filer_id'] end end |
#save_candidate_filings(from_date:, to_date:, options: {}) ⇒ Object
30 31 32 33 34 |
# File 'lib/orsos/webdownloader.rb', line 30 def save_candidate_filings from_date: , to_date: , options: {} save("candidates filings for #{from_date.strftime('%Y-%m-%d')} till #{to_date.strftime('%Y-%m-%d')}") do download_candidate_filings from_date: from_date, to_date: to_date end end |
#save_committees(committee_name_contains:, options: {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/orsos/webdownloader.rb', line 24 def save_committees committee_name_contains:, options: {} save("committees searched by #{committee_name_contains}") do download_committees committee_name: committee_name_contains, committee_name_search_type: 'contains' end end |