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



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

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

#constraints_dictionaryObject



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

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



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ecfs/filings_query.rb', line 85

def download_spreadsheet!
  agent = mechanize_agent
  page = agent.get(url)

  if page_contains_ecfs_error_message?(page)
    raise ECFS::TooManyFilingsError.new
  else
    link_text = "\r\n    \t    \t    \tExport to Excel file\r\n    \t        \t"
    link = page.link_with(:text => link_text)

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

#getObject



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

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

#mechanize_agentObject



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

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

#page_contains_ecfs_error_message?(page) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ecfs/filings_query.rb', line 73

def page_contains_ecfs_error_message?(page)
  xpath = "//*[@id='yui-main']/div/table/tbody/tr[2]/td/span[1]"
  text = page.search(xpath).text.gsub(/\s+/, " ").strip
  if text == "Retrieved the 10,000 most recent records. To view older records narrow your search criteria."
    result = true
  else
    result = false
  end

  result
end

#row_to_filing(row) ⇒ Object



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

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