Class: ECFS::FilingsQuery

Inherits:
Object
  • Object
show all
Includes:
Query
Defined in:
lib/ecfs/filings_query.rb

Instance Attribute Summary

Attributes included from Query

#constraints

Instance Method Summary collapse

Methods included from Query

#eq, #format_constraint, #initialize, #query_string, #url

Instance Method Details

#base_urlObject



52
53
54
# File 'lib/ecfs/filings_query.rb', line 52

def base_url
  "http://apps.fcc.gov/ecfs/comment_search/execute"
end

#constraints_dictionaryObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ecfs/filings_query.rb', line 12

def constraints_dictionary
  {
    "docket_number"               => "proceeding",
    "applicant"                   => "applicant",
    "lawfirm"                     => "lawfirm",
    "author"                      => "author",
    "posted_after"                => "disseminated.minDate",
    "posted_before"               => "disseminated.maxDate",
    "received_after"              => "recieved.minDate",
    "received_before"             => "recieved.maxDate",
    "comment_period_after"        => "dateCommentPeriod.minDate",
    "comment_period_before"       => "dateCommentPeriod.maxDate",
    "reply_comment_period_after"  => "dateReplyComment.minDate",
    "reply_comment_period_before" => "dateReplyComment.maxDate",
    "city"                        => "address.city",
    "state_code"                  => "address.state.stateCd",
    "zip"                         => "address.zip",
    "da_number"                   => "daNumber",
    "file_number"                 => "fileNumber",
    "bureau_id_number"            => "bureauIdentificationNumber",
    "report_number"               => "reportNumber",
    "submission_type_id"          => "submissionTypeId",
    "exparte"                     => "__checkbox_exParte"
  }
end

#download_spreadsheet!Object



72
73
74
75
76
77
78
# File 'lib/ecfs/filings_query.rb', line 72

def download_spreadsheet!
  agent = mechanize_agent
  link_text = "\r\n    \t    \t    \tExport to Excel file\r\n    \t        \t"
  link = agent.get(url).link_with(:text => link_text)

  @rows = agent.click(link).rows
end

#getObject



56
57
58
59
# File 'lib/ecfs/filings_query.rb', line 56

def get
  download_spreadsheet!
  @typecast_results ? @rows.map {|row| row_to_filing(row)} : @rows
end

#mechanize_agentObject



65
66
67
68
69
70
# File 'lib/ecfs/filings_query.rb', line 65

def mechanize_agent
  Mechanize.new.tap do |agent|
    agent.follow_meta_refresh = true
    agent.pluggable_parser["application/vnd.ms-excel"] = ECFS::SpreadsheetParser
  end
end

#row_to_filing(row) ⇒ Object



61
62
63
# File 'lib/ecfs/filings_query.rb', line 61

def row_to_filing(row)
  ECFS::Filing.new(row)
end