ecfs 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ require "mechanize"
2
+ require "spreadsheet"
3
+ require "pry"
4
+
5
+ module ECFS
6
+ class SpreadsheetParser < Mechanize::File
7
+ attr_reader :rows
8
+
9
+ def initialize(uri = nil, response = nil, body = nil, code = nil)
10
+ super(uri, response, body, code)
11
+ @body = body
12
+ extract_rows!
13
+ format_rows!
14
+ end
15
+
16
+ private
17
+
18
+ def extract_rows!
19
+ book = Spreadsheet.open(StringIO.new(@body))
20
+ sheet1 = book.worksheet 0
21
+ @rows = []
22
+ first = false
23
+ sheet1.each do |row|
24
+ @rows << row if first
25
+ first = true
26
+ end
27
+
28
+ @rows
29
+ end
30
+
31
+ def format_rows!
32
+ @rows.map! do |row|
33
+ urls = []
34
+ indices = (7..row.length-1).to_a
35
+ indices.each do |i|
36
+ text = row[i].data.split("id=")[1]
37
+ urls << "http://apps.fcc.gov/ecfs/document/view?id=#{extract_filing_id(text)}"
38
+ end
39
+
40
+ {
41
+ 'name_of_filer' => row[1],
42
+ 'docket_number' => row[0],
43
+ 'lawfirm_name' => row[2],
44
+ 'date_received' => format_date(row[3]),
45
+ 'date_posted' => format_date(row[4]),
46
+ 'exparte' => format_exparte(row[5]),
47
+ 'type_of_filing' => row[6],
48
+ 'document_urls' => urls
49
+ }
50
+ end
51
+ end
52
+
53
+ def format_date(date)
54
+ #input format 12/22/1988
55
+ # desired format "22-12-1988"
56
+ chunks = date.split("/")
57
+ "#{chunks[2]}-#{chunks[0]}-#{chunks[1]}"
58
+ end
59
+
60
+ def format_exparte(my_bool)
61
+ if my_bool == "Y"
62
+ return true
63
+ elsif my_bool == "N"
64
+ return false
65
+ else
66
+ return nil
67
+ end
68
+ end
69
+
70
+ def extract_filing_id(txt)
71
+ re1='(\\d+)' # Integer Number 1
72
+ re=(re1)
73
+ m=Regexp.new(re,Regexp::IGNORECASE);
74
+ if m.match(txt)
75
+ int1=m.match(txt)[1];
76
+ return int1
77
+ end
78
+ end
79
+
80
+ end # end class
81
+ end # end module
@@ -1,3 +1,3 @@
1
1
  module ECFS
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,5 +1,13 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
7
+ c.hook_into :webmock
8
+ c.allow_http_connections_when_no_cassette = true
9
+ end
10
+
3
11
  begin
4
12
  Bundler.setup(:default, :development)
5
13
  rescue Bundler::BundlerError => e
@@ -8,10 +16,8 @@ rescue Bundler::BundlerError => e
8
16
  exit e.status_code
9
17
  end
10
18
 
11
-
12
19
  require 'test/unit'
13
20
 
14
-
15
21
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
22
  $LOAD_PATH.unshift(File.dirname(__FILE__))
17
23
  require 'ecfs'
@@ -0,0 +1,50 @@
1
+ require "helper"
2
+ require "pp"
3
+
4
+ class TestFilingsQuery < Test::Unit::TestCase
5
+
6
+ def test_add_constraint
7
+ filings_query = ECFS::FilingsQuery.new
8
+ filings_query.eq("docket_number", "12-375")
9
+ assert_equal filings_query.constraints, {"docket_number" => "12-375"}
10
+ end
11
+
12
+ def test_constraints_dictionary
13
+ filings_query = ECFS::FilingsQuery.new
14
+ dictionary = filings_query.constraints_dictionary
15
+ assert_equal Hash, dictionary.class
16
+ end
17
+
18
+ def test_query_string
19
+ filings_query = ECFS::FilingsQuery.new
20
+ filings_query.eq("docket_number", "12-375")
21
+ filings_query.eq("lawfirm", "FCC")
22
+ assert_equal filings_query.query_string, "proceeding=12-375&lawfirm=FCC"
23
+ end
24
+
25
+ def test_url
26
+ filings_query = ECFS::FilingsQuery.new
27
+ filings_query.eq("docket_number", "12-375")
28
+ filings_query.eq("lawfirm", "FCC")
29
+ url = "http://apps.fcc.gov/ecfs/comment_search/execute?proceeding=12-375&lawfirm=FCC"
30
+ assert_equal filings_query.url, url
31
+ end
32
+
33
+ def test_get
34
+ VCR.use_cassette('test_filings_query_test_get') do
35
+ filings_query = ECFS::FilingsQuery.new
36
+ filings_query.eq("docket_number", "12-375")
37
+ rows = filings_query.get
38
+ assert_equal rows.class, Array
39
+ assert_equal rows.first.class, Hash
40
+ assert_equal rows.first["name_of_filer"].class, String
41
+ assert_equal rows.first["docket_number"], "12-375"
42
+ assert_equal rows.first["lawfirm_name"].class, String
43
+ assert_equal rows.first["date_received"].class, String
44
+ assert_equal rows.first["date_posted"].class, String
45
+ assert_equal !!rows.first["exparte"], rows.first["exparte"] # http://stackoverflow.com/a/3033645/94154
46
+ assert_equal rows.first["type_of_filing"].class, String
47
+ assert_equal rows.first["document_urls"].class, Array
48
+ end
49
+ end
50
+ end
@@ -5,7 +5,7 @@ class TestProceedingsQuery < Test::Unit::TestCase
5
5
  def test_add_constraint
6
6
  proceedings_query = ECFS::ProceedingsQuery.new
7
7
  proceedings_query.eq("docket_number", "12-375")
8
- proceedings_query.constraints
8
+ assert_equal proceedings_query.constraints, {"docket_number" => "12-375"}
9
9
  end
10
10
 
11
11
  def test_constraints_dictionary
@@ -30,16 +30,17 @@ class TestProceedingsQuery < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def test_get_proceeding_info
33
- proceedings_query = ECFS::ProceedingsQuery.new
34
- proceedings_query.eq("docket_number", "12-375")
35
- results = proceedings_query.get
36
- %w[
37
- bureau_name subject date_created status
38
- total_filings filings_in_last_30_days
39
- ].each do |key|
40
- assert results.keys.include?(key)
33
+ VCR.use_cassette('test_proceedings_query_test_get_proceeding_info') do
34
+ proceedings_query = ECFS::ProceedingsQuery.new
35
+ proceedings_query.eq("docket_number", "12-375")
36
+ results = proceedings_query.get
37
+ %w[
38
+ bureau_name subject date_created status
39
+ total_filings filings_in_last_30_days
40
+ ].each do |key|
41
+ assert results.keys.include?(key)
42
+ end
41
43
  end
42
- pp results
43
44
  end
44
45
 
45
46
  # TODO: Implement proceeding search result pages
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-13 00:00:00.000000000 Z
12
+ date: 2013-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -43,6 +43,54 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: vcr
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.9.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.9.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
46
94
  - !ruby/object:Gem::Dependency
47
95
  name: mechanize
48
96
  requirement: !ruby/object:Gem::Requirement
@@ -60,7 +108,7 @@ dependencies:
60
108
  - !ruby/object:Gem::Version
61
109
  version: '0'
62
110
  - !ruby/object:Gem::Dependency
63
- name: pry
111
+ name: spreadsheet
64
112
  requirement: !ruby/object:Gem::Requirement
65
113
  none: false
66
114
  requirements:
@@ -89,10 +137,16 @@ files:
89
137
  - README.md
90
138
  - Rakefile
91
139
  - ecfs.gemspec
140
+ - fixtures/vcr_cassettes/test_filings_query_test_get.yml
141
+ - fixtures/vcr_cassettes/test_proceedings_query_test_get_proceeding_info.yml
92
142
  - lib/ecfs.rb
143
+ - lib/ecfs/filings_query.rb
93
144
  - lib/ecfs/proceedings_query.rb
145
+ - lib/ecfs/query.rb
146
+ - lib/ecfs/spreadsheet_parser.rb
94
147
  - lib/ecfs/version.rb
95
148
  - test/helper.rb
149
+ - test/test_filings_query.rb
96
150
  - test/test_proceedings_query.rb
97
151
  homepage: ''
98
152
  licenses:
@@ -122,5 +176,6 @@ summary: ECFS helps you obtain comments and other filings from the FCC's Electro
122
176
  Comment Filing System
123
177
  test_files:
124
178
  - test/helper.rb
179
+ - test/test_filings_query.rb
125
180
  - test/test_proceedings_query.rb
126
181
  has_rdoc: