sec_query 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2MyNjkwMGQyYzk4NmYwY2IxM2Q3YmU1NDlmZDJmNGI5NzQ0YzllMA==
5
+ data.tar.gz: !binary |-
6
+ YTQ1MThkMWUwYzFlYTFiMDMxMzVhMDVhMTIwMGVlZDlkNWU1OWFiYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjQyMmY0NzViYjY4ZDMwMzVmNDRkMDg2NzEzZWJjZGNjYjUyM2JhN2IwNzk1
10
+ YmE2YjI1Mjg5MTBhMjI5ODkwMGY1MGRjNjkyZDdkN2E3ZDg5M2E2MDU0MDA2
11
+ ZGU5MmFkOGEyOGZiNGNjMTU5YzNjMDdlZTFlYWU5N2RkODg1ZmE=
12
+ data.tar.gz: !binary |-
13
+ NWY4MzFmZjJlYmE1YTMyYWViNzY1MzgxOTExMjkyZWY4ZjdmZDJlOGRiNGVh
14
+ MWEyODVhMTdiYmM4MTk1M2U3ZGE1Yzk5MTI4MjA3MGFkYmQ3MTU0OGEzMTJh
15
+ ZDcwMjU1MDliNzFiNDU2OTA0Y2U4YzYxNGE3ODYwZTA0NjA2ZmE=
data/README.md CHANGED
@@ -80,15 +80,6 @@ For example,
80
80
 
81
81
  The above query will only return the last 20 transactions and filings. This is helpful when querying companies that may have thousands or tens of thousands of transactions or filings.
82
82
 
83
- ### Entity.log(entity)
84
-
85
- For doing terminal queries, there is a log function that formats and prints the entity data to your terminal window.
86
-
87
- `entity = SecQuery::Entity.find("AAPL", true)`
88
-
89
- `SecQuery::Entity.log(entity)`
90
-
91
-
92
83
  ## Classes
93
84
 
94
85
  This gem contains four classes - Entity, Relationship, Transaction and Filing. Each Class contains the listed fields. (Everything I could parse out of the query results.)
@@ -109,6 +100,21 @@ This gem contains four classes - Entity, Relationship, Transaction and Filing.
109
100
 
110
101
  `:cik, :title, :summary, :link, :term, :date, :file_id`
111
102
 
103
+ Filings can are fetched a few different ways. Here are some of the supported
104
+ methods:
105
+
106
+ ```rb
107
+ # prints the links for the most recent filings
108
+ SecQuery::Filing.recent do |filing|
109
+ p filing.link
110
+ end
111
+
112
+ # prints all of the links for cik 0000704051 (LEGG MASON, INC.)
113
+ SecQuery::Filing.for_cik('0000704051') do |filing|
114
+ p filing.link
115
+ end
116
+ ```
117
+
112
118
  ## To Whom It May Concern at the SEC
113
119
 
114
120
  Over the last decade, I have gotten to know Edgar quite extensively and I have grown quite fond of it and the information it contains. So it is with my upmost respect that I make the following suggestions:
data/lib/sec_query.rb CHANGED
@@ -4,7 +4,9 @@
4
4
  require 'active_support/all'
5
5
  require 'addressable/uri'
6
6
  require 'hpricot'
7
+ require 'open-uri'
7
8
  require 'rest-client'
9
+ require 'rss'
8
10
  require 'rubygems'
9
11
 
10
12
  # internal
@@ -217,87 +217,5 @@ module SecQuery
217
217
 
218
218
  temp
219
219
  end
220
-
221
- def self.log(entity)
222
- if entity
223
- puts '\n\t# # # # # # # # # # # # # # # # # # # # # # # # #\n\n'
224
- puts "\t#{ entity.name }"
225
- puts "\t(#{ entity.cik })"
226
- puts "\tSIC = #{ entity.sic }" if entity.sic
227
- puts "\tLocation: #{ entity.location }, " if entity.location
228
-
229
- if entity.formerly && entity.formerly != ''
230
- puts "\tFormerly: #{ entity.formerly }"
231
- end
232
-
233
- if entity.state_of_inc
234
- puts "\tState of Incorporation: #{ entity.state_of_inc }"
235
- end
236
-
237
- if entity.mailing_address
238
- puts "\tMailing Address:\t#{ entity.mailing_address.inspect.gsub('\n', ' ').squeeze(" ") }"
239
- end
240
-
241
- if entity.business_address
242
- puts "\tBusiness Address:\t#{ entity.business_address.inspect.gsub('\n', ' ').squeeze(" ") }"
243
- end
244
-
245
- if !entity.relationships
246
- puts '\n\tRELATIONSHIPS:\t0 Total'
247
- else
248
- puts "\n\tRELATIONSHIPS:\t#{ entity.relationships.count } Total"
249
- printf("\t%-40s %-15s %-30s %-10s\n\n",
250
- 'Entity',
251
- 'CIK',
252
- 'Position',
253
- 'Date')
254
- entity.relationships.each do |relationship|
255
- printf("\t%-40s %-15s %-30s %-10s\n",
256
- relationship.name,
257
- relationship.cik,
258
- relationship.position,
259
- relationship.date)
260
- end
261
- end
262
-
263
- if entity.transactions
264
- puts "\n\tTRANSACTIONS:\t#{ entity.transactions.count } Total"
265
- printf("\t%-20s %-10s %-5s %-10s %-10s %-10s %-15s %-10s\n\n",
266
- 'Owner',
267
- 'CIK',
268
- 'Modes',
269
- 'Type',
270
- 'Shares',
271
- 'Price',
272
- 'Owned',
273
- 'Date')
274
- entity.transactions.each do |transaction|
275
- printf("\t%-20s %-10s %-5s %-10s%-10s %-10s %-15s %-10s\n",
276
- transaction.reporting_owner,
277
- transaction.owner_cik,
278
- transaction.modes,
279
- transaction.type,
280
- transaction.shares,
281
- transaction.price,
282
- transaction.owned,
283
- transaction.date)
284
- end
285
- end
286
-
287
- if entity.filings
288
- puts "\n\tFILINGS:\t#{ entity.filings.count } Total"
289
- printf("\t%-10s %-30s %-20s\n\n", 'Type', 'File ID', 'Date')
290
- entity.filings.each do |filing|
291
- printf("\t%-10s %-30s %-20s\n",
292
- filing.term,
293
- filing.file_id,
294
- filing.date)
295
- end
296
- end
297
- puts "\t#{ entity.url }\n\n"
298
- else
299
- return 'No Entity found.'
300
- end
301
- end
302
220
  end
303
221
  end
@@ -13,16 +13,78 @@ module SecQuery
13
13
  end
14
14
  end
15
15
 
16
- def self.find(entity, start, count, limit)
17
- start ||= 0
18
- count ||= 80
19
- url = SecURI.browse_edgar_uri({
16
+ def self.fetch(uri, &blk)
17
+ open(uri) do |rss|
18
+ parse_rss(rss, &blk)
19
+ end
20
+ end
21
+
22
+ def self.recent(options = {}, &blk)
23
+ start = options.fetch(:start, 0)
24
+ count = options.fetch(:count, 100)
25
+ limit = options.fetch(:limit, 100)
26
+ limited_count = [limit - start, count].min
27
+ fetch(uri_for_recent(start, limited_count), &blk)
28
+ start += count
29
+ return if start >= limit
30
+ recent({ start: start, count: count, limit: limit }, &blk)
31
+ rescue OpenURI::HTTPError
32
+ return
33
+ end
34
+
35
+ def self.for_cik(cik, options = {}, &blk)
36
+ start = options.fetch(:start, 0)
37
+ count = options.fetch(:count, 100)
38
+ limit = options.fetch(:limit, 100)
39
+ fetch(uri_for_cik(cik, start, count), &blk)
40
+ start += count
41
+ return if start >= limit
42
+ for_cik(cik, { start: start, count: count, limit: limit }, &blk)
43
+ rescue OpenURI::HTTPError
44
+ return
45
+ end
46
+
47
+ def self.uri_for_recent(start = 0, count = 100)
48
+ SecURI.browse_edgar_uri(
49
+ action: :getcurrent,
50
+ owner: :include,
51
+ output: :atom,
52
+ start: start,
53
+ count: count
54
+ )
55
+ end
56
+
57
+ def self.uri_for_cik(cik, start = 0, count = 100)
58
+ SecURI.browse_edgar_uri(
20
59
  action: :getcompany,
21
- CIK: entity[:cik],
60
+ owner: :include,
22
61
  output: :atom,
62
+ start: start,
23
63
  count: count,
24
- start: start
25
- })
64
+ CIK: cik
65
+ )
66
+ end
67
+
68
+ def self.parse_rss(rss, &blk)
69
+ feed = RSS::Parser.parse(rss, false)
70
+ feed.entries.each do |entry|
71
+ filing = Filing.new({
72
+ cik: entry.title.content.match(/\((\w{10})\)/)[1],
73
+ file_id: entry.id.content.split('=').last,
74
+ term: entry.category.term,
75
+ title: entry.title.content,
76
+ summary: entry.summary.content,
77
+ date: DateTime.parse(entry.updated.content.to_s),
78
+ link: entry.link.href.gsub('-index.htm', '.txt')
79
+ })
80
+ blk.call(filing)
81
+ end
82
+ end
83
+
84
+ def self.find(entity, start, count, limit)
85
+ start ||= 0
86
+ count ||= 80
87
+ url = uri_for_cik(entity[:cik], start, count)
26
88
  response = Entity.query(url)
27
89
  doc = Hpricot::XML(response)
28
90
  entries = doc.search(:entry)
@@ -37,7 +99,6 @@ module SecQuery
37
99
  filing[:term] = (entry/:category)[0].get_attribute('term')
38
100
  filing[:date] = (entry/:updated).innerHTML
39
101
  filing[:file_id] = (entry/:id).innerHTML.split('=').last
40
-
41
102
  entity[:filings] << Filing.new(filing)
42
103
  end
43
104
  if (query_more && limit.nil?) || (query_more && !limit)
@@ -1,5 +1,4 @@
1
1
  # encoding: UTF-8
2
- require 'debugger'
3
2
 
4
3
  module SecQuery
5
4
  class SecURI
@@ -22,8 +21,6 @@ module SecQuery
22
21
  instance
23
22
  end
24
23
 
25
- private_class_method :build_with_path
26
-
27
24
  def self.handle_string_args(string_arg)
28
25
  options = {}
29
26
  # Uhhhg. I hate using Float here. HACK
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  # => SecQuery::VERSION
3
3
  module SecQuery
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
data/sec_query.gemspec CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.version = SecQuery::VERSION
10
10
  s.authors = ['Ty Rauber']
11
11
  s.email = ['tyrauber@mac.com']
12
+ s.license = 'MIT'
12
13
  s.homepage = 'https://github.com/tyrauber/sec_query'
13
14
  s.summary = 'A ruby gem for querying the United States Securities and Exchange Commission Edgar System.'
14
15
  s.description = 'Search for company or person, by name, symbol or Central Index Key (CIK), and retrieve relationships, transactions and filings.'
@@ -19,11 +20,10 @@ Gem::Specification.new do |s|
19
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
21
  s.require_paths = ['lib']
21
22
 
22
- # specify any dependencies here; for example:
23
- s.add_development_dependency 'rspec', '>= 2.14'
24
- s.add_development_dependency 'vcr'
25
- s.add_development_dependency 'webmock'
26
- s.add_development_dependency 'rubocop'
27
- s.add_runtime_dependency 'rest-client'
28
- s.add_runtime_dependency 'hpricot'
23
+ s.add_development_dependency 'rspec', '~> 2.14'
24
+ s.add_development_dependency 'vcr', '~> 2.9'
25
+ s.add_development_dependency 'webmock', '~> 1.17'
26
+ s.add_development_dependency 'rubocop', '~> 0.20'
27
+ s.add_runtime_dependency 'rest-client', '~> 1.6'
28
+ s.add_runtime_dependency 'hpricot', '~> 0.8'
29
29
  end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ include SecQuery
4
+ require 'spec_helper'
5
+
6
+ describe SecQuery::Filing do
7
+ it '::uri_for_recent' do
8
+ expect(SecQuery::Filing.uri_for_recent.to_s)
9
+ .to eq('http://www.sec.gov/cgi-bin/browse-edgar?action=getcurrent&company&count=100&output=atom&owner=include&start=0')
10
+ end
11
+
12
+ it '::uri_for_cik' do
13
+ expect(SecQuery::Filing.uri_for_cik('testing').to_s)
14
+ .to eq('http://www.sec.gov/cgi-bin/browse-edgar?CIK=testing&action=getcompany&company&count=100&output=atom&owner=include&start=0')
15
+ end
16
+
17
+ describe '::recent', vcr: { cassette_name: 'recent' } do
18
+ let(:filings) { [] }
19
+ before(:each) do
20
+ SecQuery::Filing.recent({start: 0, count: 10, limit: 10}) do |filing|
21
+ filings.push filing
22
+ end
23
+ end
24
+
25
+ it 'should accept options' do
26
+ expect(filings.count).to eq(10)
27
+ end
28
+
29
+ it 'should have filing attributes', vcr: { cassette_name: 'recent' } do
30
+ filings.each do |filing|
31
+ expect(filing.cik).to be_present
32
+ expect(filing.title).to be_present
33
+ expect(filing.summary).to be_present
34
+ expect(filing.link).to be_present
35
+ expect(filing.term).to be_present
36
+ expect(filing.date).to be_present
37
+ expect(filing.file_id).to be_present
38
+ end
39
+ end
40
+ end
41
+ end
File without changes
metadata CHANGED
@@ -1,112 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sec_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
5
- prerelease:
4
+ version: 1.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ty Rauber
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-04-17 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '2.14'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ~>
28
25
  - !ruby/object:Gem::Version
29
26
  version: '2.14'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: vcr
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '2.9'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '2.9'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: webmock
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ~>
52
46
  - !ruby/object:Gem::Version
53
- version: '0'
47
+ version: '1.17'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: '0'
54
+ version: '1.17'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rubocop
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ~>
68
60
  - !ruby/object:Gem::Version
69
- version: '0'
61
+ version: '0.20'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ~>
76
67
  - !ruby/object:Gem::Version
77
- version: '0'
68
+ version: '0.20'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rest-client
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ~>
84
74
  - !ruby/object:Gem::Version
85
- version: '0'
75
+ version: '1.6'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ~>
92
81
  - !ruby/object:Gem::Version
93
- version: '0'
82
+ version: '1.6'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: hpricot
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ~>
100
88
  - !ruby/object:Gem::Version
101
- version: '0'
89
+ version: '0.8'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ~>
108
95
  - !ruby/object:Gem::Version
109
- version: '0'
96
+ version: '0.8'
110
97
  description: Search for company or person, by name, symbol or Central Index Key (CIK),
111
98
  and retrieve relationships, transactions and filings.
112
99
  email:
@@ -130,38 +117,40 @@ files:
130
117
  - pkg/sec_query-1.0.2.gem
131
118
  - pkg/sec_query-1.0.3.gem
132
119
  - sec_query.gemspec
133
- - spec/sec_query_spec.rb
134
- - spec/sec_uri_spec.rb
120
+ - spec/sec_query/filing_spec.rb
121
+ - spec/sec_query/sec_query_spec.rb
122
+ - spec/sec_query/sec_uri_spec.rb
135
123
  - spec/spec_helper.rb
136
124
  - spec/support/vcr.rb
137
125
  homepage: https://github.com/tyrauber/sec_query
138
- licenses: []
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
139
129
  post_install_message:
140
130
  rdoc_options: []
141
131
  require_paths:
142
132
  - lib
143
133
  required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
134
  requirements:
146
135
  - - ! '>='
147
136
  - !ruby/object:Gem::Version
148
137
  version: '0'
149
138
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
139
  requirements:
152
140
  - - ! '>='
153
141
  - !ruby/object:Gem::Version
154
142
  version: '0'
155
143
  requirements: []
156
144
  rubyforge_project: sec_query
157
- rubygems_version: 1.8.24
145
+ rubygems_version: 2.2.2
158
146
  signing_key:
159
- specification_version: 3
147
+ specification_version: 4
160
148
  summary: A ruby gem for querying the United States Securities and Exchange Commission
161
149
  Edgar System.
162
150
  test_files:
163
- - spec/sec_query_spec.rb
164
- - spec/sec_uri_spec.rb
151
+ - spec/sec_query/filing_spec.rb
152
+ - spec/sec_query/sec_query_spec.rb
153
+ - spec/sec_query/sec_uri_spec.rb
165
154
  - spec/spec_helper.rb
166
155
  - spec/support/vcr.rb
167
156
  has_rdoc: