sec 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in sec.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Gregory Graf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,45 @@
1
+ == SEC
2
+
3
+ Retrieve information from the U.S. Securities and Exchange Commission.
4
+
5
+ == Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sec'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sec
18
+
19
+ == Usage
20
+
21
+ To retrieve all XBRL filings for March 2012:
22
+
23
+ > response = Sec::MonthlyReader.get_xbrl_index(2012, 3)
24
+
25
+ The response is an RSS document, with each filing in response['channel']['item']
26
+
27
+ > response = ['rss']['channel']['item'].count
28
+ => 4195
29
+
30
+ == Thanks
31
+ Many thanks are owed to the following for me to be able to release my first gem:
32
+ * {Mike Sassak}[http://github.com/msassak]
33
+ * {Josh Schairbaum}[http://github.com/jschairb]
34
+ * {Philip Toland}[http://github.com/toland]
35
+
36
+ == Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
44
+ == Licensing
45
+ The SEC gem is released under the {MIT License}[http://www.opensource.org/licenses/MIT].
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ module Sec
2
+ class Connection
3
+
4
+ require 'patron'
5
+
6
+ SEC_BASE_URL = 'http://www.sec.gov'
7
+
8
+ attr_reader :session
9
+
10
+ DEFAULT_SESSION_ATTRIBUTES = {
11
+ :base_url => SEC_BASE_URL,
12
+ :connect_timeout => 5000,
13
+ :timeout => 5000
14
+ }
15
+
16
+ def initialize(attrs={})
17
+ @session = Patron::Session.new
18
+ configure_session(attrs)
19
+ end
20
+
21
+ def get(uri)
22
+ @session.get(uri)
23
+ end
24
+
25
+ private
26
+ def configure_session(attrs={})
27
+ session_attrs = DEFAULT_SESSION_ATTRIBUTES.merge(attrs)
28
+ session_attrs.each_pair do |k, v|
29
+ session.send("#{k}=".to_sym, v)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ module Sec
2
+ class MonthlyReader
3
+ class Error < StandardError; end
4
+
5
+ require 'crack'
6
+
7
+ MONTHLY_PATH = %q{/Archives/edgar/monthly/xbrlrss-%{year}-%{month}.xml}
8
+
9
+ attr_reader :xbrl_hash
10
+
11
+ def self.get_xbrl_index(year, month)
12
+ reader = MonthlyReader.new
13
+ reader.get_xbrl_index(year, month)
14
+ end
15
+
16
+ def get_xbrl_index(year, month)
17
+ resp = connection.get(monthly_query_uri(year, month))
18
+ if resp.status == 200
19
+ # items are in ["rss"]["channel"]
20
+ @xbrl_hash = Crack::XML.parse(resp.body)
21
+ else
22
+ nil
23
+ end
24
+ end
25
+
26
+ private
27
+ def connection(attrs={})
28
+ Sec::Connection.new
29
+ end
30
+
31
+ def prepend_zero(month)
32
+ month = month.to_s
33
+ month.prepend("0") if month.size == 1
34
+ end
35
+
36
+ def monthly_query_uri(year, month)
37
+ MONTHLY_PATH % {:year => year, :month => prepend_zero(month)}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Sec
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sec.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Sec
2
+ end
3
+
4
+ require "sec/connection"
5
+ require "sec/monthly_reader"
6
+ require "sec/version"
data/sec.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sec/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sec"
8
+ gem.version = Sec::VERSION
9
+ gem.authors = ["Gregory Graf"]
10
+ gem.email = ["graf.gregory@gmail.com"]
11
+ gem.description = %q{Reads information from the U.S. Securities and Exchange Commission}
12
+ gem.summary = %q{SEC Reader}
13
+ gem.homepage = "https://github.com/reinventinghorses/sec"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'crack'
21
+ gem.add_dependency 'patron'
22
+
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'vcr'
25
+ gem.add_development_dependency 'webmock'
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Sec
4
+ describe 'Connection' do
5
+ let(:connection) { Connection.new }
6
+ let(:session) { connection.session }
7
+
8
+ describe '.new' do
9
+ it 'should set up a Patron session' do
10
+ expect(session).to be_kind_of(Patron::Session)
11
+ end
12
+
13
+ it 'should use the SEC base url' do
14
+ expected = 'http://www.sec.gov'
15
+
16
+ expect(session.base_url).to eq(expected)
17
+ end
18
+ end
19
+
20
+ describe '.get' do
21
+ it 'sends a get to the session' do
22
+ session.should_receive('get').with('/some_path')
23
+
24
+ connection.get('/some_path')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Sec
4
+ describe MonthlyReader do
5
+ use_vcr_cassette 'monthly_reader'
6
+
7
+ let(:connection) { Sec::Connection.new }
8
+ let(:monthly_reader) { MonthlyReader.new }
9
+ let(:response) { monthly_reader.get_xbrl_index(2012, 1) }
10
+
11
+ describe '.get_xbrl_index' do
12
+ it 'returns a hash' do
13
+ expect(response).to be_kind_of(Hash)
14
+ end
15
+
16
+ it 'has a top level rss key' do
17
+ expect(response.keys).to eq(['rss'])
18
+ end
19
+ end
20
+ end
21
+ end
data/spec/sec_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Sec' do
4
+ it 'should return true' do
5
+ expect(true).to eq(true)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'rspec'
3
+ require 'sec'
4
+
5
+ # require everything in spec/support, not assuming forward or backward slash
6
+ Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each {|f| require f }
7
+