sec 0.0.2 → 0.0.3
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/.travis.yml +0 -1
- data/README.rdoc +2 -0
- data/Rakefile +13 -0
- data/lib/sec/connection.rb +14 -7
- data/lib/sec/reader.rb +12 -13
- data/lib/sec/version.rb +1 -1
- data/spec/connection_spec.rb +27 -2
- data/spec/reader_spec.rb +27 -12
- data/spec/support/request_library/reader.yml +18 -15
- metadata +4 -4
    
        data/README.rdoc
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    | @@ -1 +1,14 @@ | |
| 1 1 | 
             
            require "bundler/gem_tasks"
         | 
| 2 | 
            +
            require "rspec/core/rake_task"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # https://github.com/mongoid/mongoid/blob/master/Rakefile
         | 
| 5 | 
            +
            RSpec::Core::RakeTask.new("spec") do |spec|
         | 
| 6 | 
            +
              spec.pattern = "spec/**/*_spec.rb"
         | 
| 7 | 
            +
            end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            RSpec::Core::RakeTask.new('spec:progress') do |spec|
         | 
| 10 | 
            +
              spec.rspec_opts = %w(--format progress)
         | 
| 11 | 
            +
              spec.pattern = "spec/**/*_spec.rb"
         | 
| 12 | 
            +
            end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            task :default => :spec
         | 
    
        data/lib/sec/connection.rb
    CHANGED
    
    | @@ -1,25 +1,32 @@ | |
| 1 1 | 
             
            module Sec
         | 
| 2 2 | 
             
              class Connection
         | 
| 3 | 
            +
                class Error < StandardError; end
         | 
| 3 4 |  | 
| 4 5 | 
             
                require 'patron'
         | 
| 5 6 |  | 
| 6 | 
            -
                 | 
| 7 | 
            +
                BASE_URL        = 'http://www.sec.gov'
         | 
| 8 | 
            +
                CONNECT_TIMEOUT = 30
         | 
| 9 | 
            +
                SUCCESSFUL_RESPONSE = 200
         | 
| 10 | 
            +
                TIMEOUT         = 120
         | 
| 7 11 |  | 
| 8 | 
            -
                 | 
| 12 | 
            +
                attr_accessor :session
         | 
| 9 13 |  | 
| 10 14 | 
             
                DEFAULT_SESSION_ATTRIBUTES = {
         | 
| 11 | 
            -
                  :base_url        =>  | 
| 12 | 
            -
                  :connect_timeout =>  | 
| 13 | 
            -
                  :timeout         =>  | 
| 15 | 
            +
                  :base_url        => BASE_URL,
         | 
| 16 | 
            +
                  :connect_timeout => CONNECT_TIMEOUT,
         | 
| 17 | 
            +
                  :timeout         => TIMEOUT
         | 
| 14 18 | 
             
                }
         | 
| 15 19 |  | 
| 16 20 | 
             
                def initialize(attrs={})
         | 
| 17 | 
            -
                   | 
| 21 | 
            +
                  self.session = Patron::Session.new
         | 
| 18 22 | 
             
                  configure_session(attrs)
         | 
| 19 23 | 
             
                end
         | 
| 20 24 |  | 
| 21 25 | 
             
                def get(uri)
         | 
| 22 | 
            -
                   | 
| 26 | 
            +
                  response = session.get(uri)
         | 
| 27 | 
            +
                  response.body if response.respond_to?(:body)
         | 
| 28 | 
            +
                rescue Patron::Error => error
         | 
| 29 | 
            +
                  raise Error, error.message
         | 
| 23 30 | 
             
                end
         | 
| 24 31 |  | 
| 25 32 | 
             
                private
         | 
    
        data/lib/sec/reader.rb
    CHANGED
    
    | @@ -6,6 +6,8 @@ module Sec | |
| 6 6 |  | 
| 7 7 | 
             
                MONTHLY_PATH = %q{/Archives/edgar/monthly/xbrlrss-%{year}-%{month}.xml}
         | 
| 8 8 |  | 
| 9 | 
            +
                attr_accessor :connection
         | 
| 10 | 
            +
             | 
| 9 11 | 
             
                def self.get_monthly_index(year, month)
         | 
| 10 12 | 
             
                  reader = Reader.new
         | 
| 11 13 | 
             
                  reader.get_monthly_index(year, month)
         | 
| @@ -16,25 +18,22 @@ module Sec | |
| 16 18 | 
             
                  reader.get_xbrl_file(url)
         | 
| 17 19 | 
             
                end
         | 
| 18 20 |  | 
| 21 | 
            +
                def initialize(attrs={})
         | 
| 22 | 
            +
                  self.connection = Connection.new(attrs)
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 19 25 | 
             
                def get_monthly_index(year, month)
         | 
| 20 | 
            -
                   | 
| 21 | 
            -
                   | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
                  else
         | 
| 25 | 
            -
                    nil
         | 
| 26 | 
            -
                  end
         | 
| 26 | 
            +
                  response = connection.get(monthly_query_uri(year, month))
         | 
| 27 | 
            +
                  Crack::XML.parse(response)
         | 
| 28 | 
            +
                rescue => error
         | 
| 29 | 
            +
                  raise Error, error.message
         | 
| 27 30 | 
             
                end
         | 
| 28 31 |  | 
| 29 32 | 
             
                def get_xbrl_file(url)
         | 
| 30 | 
            -
                   | 
| 33 | 
            +
                  connection.get(uri_path(url))
         | 
| 31 34 | 
             
                end
         | 
| 32 35 |  | 
| 33 36 | 
             
                private
         | 
| 34 | 
            -
                def connection(attrs={})
         | 
| 35 | 
            -
                  Connection.new
         | 
| 36 | 
            -
                end
         | 
| 37 | 
            -
             | 
| 38 37 | 
             
                def prepend_zero(month)
         | 
| 39 38 | 
             
                  month = month.to_s
         | 
| 40 39 | 
             
                  month.prepend("0") if month.size == 1
         | 
| @@ -45,7 +44,7 @@ module Sec | |
| 45 44 | 
             
                end
         | 
| 46 45 |  | 
| 47 46 | 
             
                def uri_path(url)
         | 
| 48 | 
            -
                  url.gsub( | 
| 47 | 
            +
                  url.gsub(/http:\/\/www\.sec\.gov/, '')
         | 
| 49 48 | 
             
                end
         | 
| 50 49 | 
             
              end
         | 
| 51 50 | 
             
            end
         | 
    
        data/lib/sec/version.rb
    CHANGED
    
    
    
        data/spec/connection_spec.rb
    CHANGED
    
    | @@ -10,11 +10,29 @@ module Sec | |
| 10 10 | 
             
                    expect(session).to be_kind_of(Patron::Session)
         | 
| 11 11 | 
             
                  end
         | 
| 12 12 |  | 
| 13 | 
            -
                  it 'should use the SEC  | 
| 14 | 
            -
                    expected =  | 
| 13 | 
            +
                  it 'should use the SEC BASE_URL value' do
         | 
| 14 | 
            +
                    expected = Sec::Connection::BASE_URL
         | 
| 15 15 |  | 
| 16 16 | 
             
                    expect(session.base_url).to eq(expected)
         | 
| 17 17 | 
             
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  it 'sets the default connect timeout to CONNECT_TIMEOUT value' do
         | 
| 20 | 
            +
                    expected = Sec::Connection::CONNECT_TIMEOUT
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    expect(session.connect_timeout).to eq(expected)
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  it 'sets the default timeout to TIMEOUT value' do
         | 
| 26 | 
            +
                    expected = Sec::Connection::TIMEOUT
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    expect(session.timeout).to eq(expected)
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  it 'sets custom attributes' do
         | 
| 32 | 
            +
                    connection = Connection.new({ :timeout => 600 })
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    expect(connection.session.timeout).to eq(600)
         | 
| 35 | 
            +
                  end
         | 
| 18 36 | 
             
                end
         | 
| 19 37 |  | 
| 20 38 | 
             
                describe '.get' do
         | 
| @@ -23,6 +41,13 @@ module Sec | |
| 23 41 |  | 
| 24 42 | 
             
                    connection.get('/some_path')
         | 
| 25 43 | 
             
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  it 'raises a Connection::Error when there is a Patron error' do
         | 
| 46 | 
            +
                    error = Patron::Error.new
         | 
| 47 | 
            +
                    session.stub(:get).and_raise(error)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    expect { connection.get('/some_path') }.to raise_error(Connection::Error)
         | 
| 50 | 
            +
                  end
         | 
| 26 51 | 
             
                end
         | 
| 27 52 | 
             
              end
         | 
| 28 53 | 
             
            end
         | 
    
        data/spec/reader_spec.rb
    CHANGED
    
    | @@ -4,34 +4,49 @@ module Sec | |
| 4 4 | 
             
              describe Reader do
         | 
| 5 5 | 
             
                use_vcr_cassette 'reader'
         | 
| 6 6 |  | 
| 7 | 
            -
                let(: | 
| 8 | 
            -
                let(:reader) { Reader.new }
         | 
| 7 | 
            +
                let(:monthly_index) { Reader.get_monthly_index(2012, 1) }
         | 
| 9 8 |  | 
| 10 9 | 
             
                describe '.get_monthly_index' do
         | 
| 11 | 
            -
                   | 
| 10 | 
            +
                  # TODO: figure out why this doesnt work
         | 
| 11 | 
            +
                  xit 'send a GET to Connection' do
         | 
| 12 | 
            +
                    connection = Connection.new
         | 
| 13 | 
            +
                    Connection.stub(:new).and_return(connection)
         | 
| 14 | 
            +
                    connection.should_receive(:get).with("/Archives/edgar/monthly/xbrlrss-2012-01.xml")
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    Reader.get_monthly_index(2012, 1)
         | 
| 17 | 
            +
                  end
         | 
| 12 18 |  | 
| 13 19 | 
             
                  it 'returns a hash' do
         | 
| 14 | 
            -
                    expect( | 
| 20 | 
            +
                    expect(monthly_index).to be_kind_of(Hash)
         | 
| 15 21 | 
             
                  end
         | 
| 16 22 |  | 
| 17 | 
            -
                  it ' | 
| 18 | 
            -
                    expect( | 
| 23 | 
            +
                  it 'returns the correct top level key' do
         | 
| 24 | 
            +
                    expect(monthly_index.keys).to eq(['rss'])
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  it 'raises an error when the response isnt valid' do
         | 
| 28 | 
            +
                    Crack::XML.stub(:parse).and_raise(StandardError)
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                    expect { Reader.get_monthly_index(2012, 1) }.to raise_error(Reader::Error)
         | 
| 19 31 | 
             
                  end
         | 
| 20 32 | 
             
                end
         | 
| 21 33 |  | 
| 22 34 | 
             
                describe '.get_xbrl_file' do
         | 
| 23 35 | 
             
                  url = "http://www.sec.gov/Archives/edgar/data/840715/000084071512000011/clro-20111231_pre.xml"
         | 
| 24 | 
            -
                  let(: | 
| 25 | 
            -
             | 
| 26 | 
            -
                  it 'should receive a 200 response code' do
         | 
| 27 | 
            -
                    expect(response.status).to eq(200)
         | 
| 28 | 
            -
                  end
         | 
| 36 | 
            +
                  let(:xbrl_file) { Reader.get_xbrl_file(url) }
         | 
| 29 37 |  | 
| 30 38 | 
             
                  # multiple file types, we'll test one
         | 
| 31 39 | 
             
                  # I want a more consistent return between the two,
         | 
| 32 40 | 
             
                  # one of the TODOs as I use this gem more
         | 
| 33 41 | 
             
                  it 'should return an XML string' do
         | 
| 34 | 
            -
                    expect( | 
| 42 | 
            +
                    expect(xbrl_file).to match(/xml\sversion/)
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  xit 'raises an error when the respone isnt valid' do
         | 
| 46 | 
            +
                    error = Connection::Error.new
         | 
| 47 | 
            +
                    Connection.stub(:get).and_raise(error)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    expect { Reader.get_xbrl_file(url) }.to raise_error(Connection::Error)
         | 
| 35 50 | 
             
                  end
         | 
| 36 51 | 
             
                end
         | 
| 37 52 | 
             
              end
         | 
| @@ -20,10 +20,10 @@ http_interactions: | |
| 20 20 | 
             
                    U0VD
         | 
| 21 21 | 
             
                  !binary "TGFzdC1Nb2RpZmllZA==":
         | 
| 22 22 | 
             
                  - !binary |-
         | 
| 23 | 
            -
                     | 
| 23 | 
            +
                    U3VuLCAyMiBBcHIgMjAxMiAxNjozMjo0OCBHTVQ=
         | 
| 24 24 | 
             
                  !binary "RXRhZw==":
         | 
| 25 25 | 
             
                  - !binary |-
         | 
| 26 | 
            -
                     | 
| 26 | 
            +
                    IjRiZTQ3MTI2ZTBjMDAi
         | 
| 27 27 | 
             
                  !binary "Q29udGVudC1UeXBl":
         | 
| 28 28 | 
             
                  - !binary |-
         | 
| 29 29 | 
             
                    YXBwbGljYXRpb24veG1s
         | 
| @@ -32,10 +32,10 @@ http_interactions: | |
| 32 32 | 
             
                    bWF4LWFnZT0w
         | 
| 33 33 | 
             
                  !binary "RXhwaXJlcw==":
         | 
| 34 34 | 
             
                  - !binary |-
         | 
| 35 | 
            -
                     | 
| 35 | 
            +
                    TW9uLCAyOCBKYW4gMjAxMyAyMjozNTo0NSBHTVQ=
         | 
| 36 36 | 
             
                  !binary "RGF0ZQ==":
         | 
| 37 37 | 
             
                  - !binary |-
         | 
| 38 | 
            -
                     | 
| 38 | 
            +
                    TW9uLCAyOCBKYW4gMjAxMyAyMjozNTo0NSBHTVQ=
         | 
| 39 39 | 
             
                  !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
         | 
| 40 40 | 
             
                  - !binary |-
         | 
| 41 41 | 
             
                    Y2h1bmtlZA==
         | 
| @@ -60,9 +60,9 @@ http_interactions: | |
| 60 60 | 
             
                    b3JnLzIwMDUvQXRvbSIvPgogICAgPGRlc2NyaXB0aW9uPlRoaXMgaXMgYSBs
         | 
| 61 61 | 
             
                    aXN0IGFsbCBvZiB0aGUgZmlsaW5ncyBjb250YWluaW5nIFhCUkwgZm9yIDIw
         | 
| 62 62 | 
             
                    MTItMDE8L2Rlc2NyaXB0aW9uPgogICAgPGxhbmd1YWdlPmVuLXVzPC9sYW5n
         | 
| 63 | 
            -
                     | 
| 63 | 
            +
                    dWFnZT4KICAgIDxwdWJEYXRlPlN1biwgMjIgQXByIDIwMTIgMTI6MzE6NTYg
         | 
| 64 64 | 
             
                    RURUPC9wdWJEYXRlPgogICAgPGxhc3RCdWlsZERhdGU+U3VuLCAyMiBBcHIg
         | 
| 65 | 
            -
                     | 
| 65 | 
            +
                    MjAxMiAxMjozMTo1NiBFRFQ8L2xhc3RCdWlsZERhdGU+CiAgICA8aXRlbT4K
         | 
| 66 66 | 
             
                    ICAgICAgPHRpdGxlPkFNQVpPTiBDT00gSU5DICgwMDAxMDE4NzI0KSAoRmls
         | 
| 67 67 | 
             
                    ZXIpPC90aXRsZT4KICAgICAgPGxpbms+aHR0cDovL3d3dy5zZWMuZ292L0Fy
         | 
| 68 68 | 
             
                    Y2hpdmVzL2VkZ2FyL2RhdGEvMTAxODcyNC8wMDAxMTkzMTI1MTIwMzI4NDYv
         | 
| @@ -94292,7 +94292,7 @@ http_interactions: | |
| 94292 94292 | 
             
                    ICAgPC9lZGdhcjp4YnJsRmlsZXM+CiAgICAgIDwvZWRnYXI6eGJybEZpbGlu
         | 
| 94293 94293 | 
             
                    Zz4KICAgIDwvaXRlbT4KICA8L2NoYW5uZWw+CjwvcnNzPgo=
         | 
| 94294 94294 | 
             
                http_version: 
         | 
| 94295 | 
            -
              recorded_at:  | 
| 94295 | 
            +
              recorded_at: Mon, 28 Jan 2013 22:36:22 GMT
         | 
| 94296 94296 | 
             
            - request:
         | 
| 94297 94297 | 
             
                method: get
         | 
| 94298 94298 | 
             
                uri: http://www.sec.gov/Archives/edgar/data/840715/000084071512000011/clro-20111231_pre.xml
         | 
| @@ -94308,15 +94308,15 @@ http_interactions: | |
| 94308 94308 | 
             
                  message: !binary |-
         | 
| 94309 94309 | 
             
                    T0s=
         | 
| 94310 94310 | 
             
                headers:
         | 
| 94311 | 
            -
                  !binary "U2VydmVy":
         | 
| 94312 | 
            -
                  - !binary |-
         | 
| 94313 | 
            -
                    U0VD
         | 
| 94314 94311 | 
             
                  !binary "TGFzdC1Nb2RpZmllZA==":
         | 
| 94315 94312 | 
             
                  - !binary |-
         | 
| 94316 | 
            -
                     | 
| 94313 | 
            +
                    TW9uLCAwMiBBcHIgMjAxMiAxMDoxMDowNCBHTVQ=
         | 
| 94317 94314 | 
             
                  !binary "RXRhZw==":
         | 
| 94318 94315 | 
             
                  - !binary |-
         | 
| 94319 | 
            -
                     | 
| 94316 | 
            +
                    IjRiY2FmNjRkN2I3MDAi
         | 
| 94317 | 
            +
                  !binary "U2VydmVy":
         | 
| 94318 | 
            +
                  - !binary |-
         | 
| 94319 | 
            +
                    U0VD
         | 
| 94320 94320 | 
             
                  !binary "Q29udGVudC1UeXBl":
         | 
| 94321 94321 | 
             
                  - !binary |-
         | 
| 94322 94322 | 
             
                    YXBwbGljYXRpb24veG1s
         | 
| @@ -94325,10 +94325,10 @@ http_interactions: | |
| 94325 94325 | 
             
                    bWF4LWFnZT0w
         | 
| 94326 94326 | 
             
                  !binary "RXhwaXJlcw==":
         | 
| 94327 94327 | 
             
                  - !binary |-
         | 
| 94328 | 
            -
                     | 
| 94328 | 
            +
                    TW9uLCAyOCBKYW4gMjAxMyAyMjo1MzowOCBHTVQ=
         | 
| 94329 94329 | 
             
                  !binary "RGF0ZQ==":
         | 
| 94330 94330 | 
             
                  - !binary |-
         | 
| 94331 | 
            -
                     | 
| 94331 | 
            +
                    TW9uLCAyOCBKYW4gMjAxMyAyMjo1MzowOCBHTVQ=
         | 
| 94332 94332 | 
             
                  !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
         | 
| 94333 94333 | 
             
                  - !binary |-
         | 
| 94334 94334 | 
             
                    Y2h1bmtlZA==
         | 
| @@ -94337,6 +94337,9 @@ http_interactions: | |
| 94337 94337 | 
             
                    VHJhbnNmZXItRW5jb2Rpbmc=
         | 
| 94338 94338 | 
             
                  - !binary |-
         | 
| 94339 94339 | 
             
                    a2VlcC1hbGl2ZQ==
         | 
| 94340 | 
            +
                  !binary "U2V0LUNvb2tpZQ==":
         | 
| 94341 | 
            +
                  - !binary |-
         | 
| 94342 | 
            +
                    ZGF0YWNlbnRlcj1kYzIgOyBQYXRoPS8=
         | 
| 94340 94343 | 
             
                body:
         | 
| 94341 94344 | 
             
                  encoding: ASCII-8BIT
         | 
| 94342 94345 | 
             
                  string: !binary |-
         | 
| @@ -96115,5 +96118,5 @@ http_interactions: | |
| 96115 96118 | 
             
                    ZGVyPScxLjAnLz4KCTwvbGluazpwcmVzZW50YXRpb25MaW5rPgo8L2xpbms6
         | 
| 96116 96119 | 
             
                    bGlua2Jhc2U+Cg==
         | 
| 96117 96120 | 
             
                http_version: 
         | 
| 96118 | 
            -
              recorded_at: Mon,  | 
| 96121 | 
            +
              recorded_at: Mon, 28 Jan 2013 22:53:13 GMT
         | 
| 96119 96122 | 
             
            recorded_with: VCR 2.3.0
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sec
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 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:  | 
| 12 | 
            +
            date: 2013-02-01 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: crack
         | 
| @@ -161,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 161 161 | 
             
                  version: '0'
         | 
| 162 162 | 
             
                  segments:
         | 
| 163 163 | 
             
                  - 0
         | 
| 164 | 
            -
                  hash:  | 
| 164 | 
            +
                  hash: -3634642483232780340
         | 
| 165 165 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 166 166 | 
             
              none: false
         | 
| 167 167 | 
             
              requirements:
         | 
| @@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 170 170 | 
             
                  version: '0'
         | 
| 171 171 | 
             
                  segments:
         | 
| 172 172 | 
             
                  - 0
         | 
| 173 | 
            -
                  hash:  | 
| 173 | 
            +
                  hash: -3634642483232780340
         | 
| 174 174 | 
             
            requirements: []
         | 
| 175 175 | 
             
            rubyforge_project: 
         | 
| 176 176 | 
             
            rubygems_version: 1.8.23
         |