sec_api 1.0.0

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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.devcontainer/Dockerfile +54 -0
  3. data/.devcontainer/README.md +178 -0
  4. data/.devcontainer/devcontainer.json +46 -0
  5. data/.devcontainer/docker-compose.yml +28 -0
  6. data/.devcontainer/post-create.sh +51 -0
  7. data/.devcontainer/post-start.sh +44 -0
  8. data/.rspec +3 -0
  9. data/.standard.yml +3 -0
  10. data/CHANGELOG.md +5 -0
  11. data/CLAUDE.md +0 -0
  12. data/LICENSE.txt +21 -0
  13. data/MIGRATION.md +274 -0
  14. data/README.md +370 -0
  15. data/Rakefile +10 -0
  16. data/config/secapi.yml.example +57 -0
  17. data/docs/development-guide.md +291 -0
  18. data/docs/enumerator_pattern_design.md +483 -0
  19. data/docs/examples/README.md +58 -0
  20. data/docs/examples/backfill_filings.rb +419 -0
  21. data/docs/examples/instrumentation.rb +583 -0
  22. data/docs/examples/query_builder.rb +308 -0
  23. data/docs/examples/streaming_notifications.rb +491 -0
  24. data/docs/index.md +244 -0
  25. data/docs/migration-guide-v1.md +1091 -0
  26. data/docs/pre-review-checklist.md +145 -0
  27. data/docs/project-overview.md +90 -0
  28. data/docs/project-scan-report.json +60 -0
  29. data/docs/source-tree-analysis.md +190 -0
  30. data/lib/sec_api/callback_helper.rb +49 -0
  31. data/lib/sec_api/client.rb +606 -0
  32. data/lib/sec_api/collections/filings.rb +267 -0
  33. data/lib/sec_api/collections/fulltext_results.rb +86 -0
  34. data/lib/sec_api/config.rb +590 -0
  35. data/lib/sec_api/deep_freezable.rb +42 -0
  36. data/lib/sec_api/errors/authentication_error.rb +24 -0
  37. data/lib/sec_api/errors/configuration_error.rb +5 -0
  38. data/lib/sec_api/errors/error.rb +75 -0
  39. data/lib/sec_api/errors/network_error.rb +26 -0
  40. data/lib/sec_api/errors/not_found_error.rb +23 -0
  41. data/lib/sec_api/errors/pagination_error.rb +28 -0
  42. data/lib/sec_api/errors/permanent_error.rb +29 -0
  43. data/lib/sec_api/errors/rate_limit_error.rb +57 -0
  44. data/lib/sec_api/errors/reconnection_error.rb +34 -0
  45. data/lib/sec_api/errors/server_error.rb +25 -0
  46. data/lib/sec_api/errors/transient_error.rb +28 -0
  47. data/lib/sec_api/errors/validation_error.rb +23 -0
  48. data/lib/sec_api/extractor.rb +122 -0
  49. data/lib/sec_api/filing_journey.rb +477 -0
  50. data/lib/sec_api/mapping.rb +125 -0
  51. data/lib/sec_api/metrics_collector.rb +411 -0
  52. data/lib/sec_api/middleware/error_handler.rb +250 -0
  53. data/lib/sec_api/middleware/instrumentation.rb +186 -0
  54. data/lib/sec_api/middleware/rate_limiter.rb +541 -0
  55. data/lib/sec_api/objects/data_file.rb +34 -0
  56. data/lib/sec_api/objects/document_format_file.rb +45 -0
  57. data/lib/sec_api/objects/entity.rb +92 -0
  58. data/lib/sec_api/objects/extracted_data.rb +118 -0
  59. data/lib/sec_api/objects/fact.rb +147 -0
  60. data/lib/sec_api/objects/filing.rb +197 -0
  61. data/lib/sec_api/objects/fulltext_result.rb +66 -0
  62. data/lib/sec_api/objects/period.rb +96 -0
  63. data/lib/sec_api/objects/stream_filing.rb +194 -0
  64. data/lib/sec_api/objects/xbrl_data.rb +356 -0
  65. data/lib/sec_api/query.rb +423 -0
  66. data/lib/sec_api/rate_limit_state.rb +130 -0
  67. data/lib/sec_api/rate_limit_tracker.rb +154 -0
  68. data/lib/sec_api/stream.rb +841 -0
  69. data/lib/sec_api/structured_logger.rb +199 -0
  70. data/lib/sec_api/types.rb +32 -0
  71. data/lib/sec_api/version.rb +42 -0
  72. data/lib/sec_api/xbrl.rb +220 -0
  73. data/lib/sec_api.rb +137 -0
  74. data/sig/sec_api.rbs +4 -0
  75. metadata +217 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f33a11ec3b8cf4f6ab7cb5e484fa24f88e5446630868f67702b1ab1336011951
4
+ data.tar.gz: 5d67a99ce1490136471f4a20346d57c506ea0bc75ac8ac03280f3d2690482a71
5
+ SHA512:
6
+ metadata.gz: a4acdf281ce2fb6345f1cbdd52c950d8602de26816fe0437cb4d40ee6502a74cd35e31b81d864cdef8f2f5c36ba3e4d5500d056dc3ce761bc390f3c72afec676
7
+ data.tar.gz: d7f8800563146e2a47979364fd9f3d0302502927a201def6b37b99745b07a6b9603b5390bdefcf8afc30c1d5983faf889a9d01ef87d8a4d9db2393a998a56fa9
@@ -0,0 +1,54 @@
1
+ # Use official Ruby image as base
2
+ ARG RUBY_VERSION=3.1
3
+ FROM ruby:${RUBY_VERSION}
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
7
+ && apt-get -y install --no-install-recommends \
8
+ build-essential \
9
+ git \
10
+ curl \
11
+ libssl-dev \
12
+ libreadline-dev \
13
+ zlib1g-dev \
14
+ libyaml-dev \
15
+ libffi-dev \
16
+ libgdbm-dev \
17
+ libncurses5-dev \
18
+ libsqlite3-dev \
19
+ && apt-get clean \
20
+ && rm -rf /var/lib/apt/lists/*
21
+
22
+ # Create vscode user with sudo access
23
+ ARG USERNAME=vscode
24
+ ARG USER_UID=1000
25
+ ARG USER_GID=$USER_UID
26
+
27
+ RUN groupadd --gid $USER_GID $USERNAME \
28
+ && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
29
+ && apt-get update \
30
+ && apt-get install -y sudo \
31
+ && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
32
+ && chmod 0440 /etc/sudoers.d/$USERNAME
33
+
34
+ # Install bundler
35
+ RUN gem update --system && gem install bundler
36
+
37
+ # Set up workspace directory
38
+ WORKDIR /workspace
39
+
40
+ # Switch to non-root user
41
+ USER $USERNAME
42
+
43
+ # Set environment variables for Ruby
44
+ ENV GEM_HOME=/home/$USERNAME/.gem
45
+ ENV PATH=$GEM_HOME/bin:$PATH
46
+
47
+ # Install common Ruby development tools
48
+ RUN gem install solargraph \
49
+ && gem install rubocop \
50
+ && gem install standard \
51
+ && gem install debug
52
+
53
+ # Default command
54
+ CMD ["/bin/bash"]
@@ -0,0 +1,178 @@
1
+ # DevContainer Setup for sec_api
2
+
3
+ This directory contains the development container configuration for the sec_api Ruby gem.
4
+
5
+ ## Prerequisites
6
+
7
+ - [Docker Desktop](https://www.docker.com/products/docker-desktop) or [Docker Engine](https://docs.docker.com/engine/install/)
8
+ - [Visual Studio Code](https://code.visualstudio.com/)
9
+ - [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code
10
+
11
+ ## Quick Start
12
+
13
+ 1. Open this project in VS Code
14
+ 2. When prompted, click "Reopen in Container" (or use Command Palette: `Dev Containers: Reopen in Container`)
15
+ 3. Wait for the container to build and start (first time may take a few minutes)
16
+ 4. The setup scripts will run automatically:
17
+ - `post-create.sh` runs once when the container is first created
18
+ - `post-start.sh` runs every time the container starts
19
+
20
+ ## What's Included
21
+
22
+ ### Base Environment
23
+ - Ruby 3.1 (configurable via RUBY_VERSION arg)
24
+ - Bundler (latest)
25
+ - Git
26
+ - Build tools and common system dependencies
27
+
28
+ ### Development Tools
29
+ - Solargraph (Ruby language server)
30
+ - RuboCop (linter)
31
+ - Standard (Ruby style guide)
32
+ - Debug gem
33
+
34
+ ### VS Code Extensions
35
+ - Ruby LSP (Shopify)
36
+ - Ruby extension pack
37
+ - EndWise (auto-close Ruby blocks)
38
+ - Solargraph
39
+
40
+ ## Configuration
41
+
42
+ ### Ruby Version
43
+
44
+ To change the Ruby version, edit `.devcontainer/Dockerfile` and `.devcontainer/docker-compose.yml`:
45
+
46
+ ```dockerfile
47
+ ARG RUBY_VERSION=3.2 # Change to desired version
48
+ ```
49
+
50
+ ### Environment Variables
51
+
52
+ Add environment variables in `.devcontainer/docker-compose.yml`:
53
+
54
+ ```yaml
55
+ environment:
56
+ - SECAPI_API_KEY=your_key_here
57
+ - SECAPI_BASE_URL=https://api.sec-api.io
58
+ ```
59
+
60
+ **Note:** For sensitive values like API keys, consider using a `.env` file (not committed to git) and reference it in docker-compose.yml.
61
+
62
+ ### Lifecycle Scripts
63
+
64
+ The devcontainer uses two lifecycle scripts:
65
+
66
+ **`.devcontainer/post-create.sh`** - Runs once when container is first created:
67
+ - Installs bundle dependencies
68
+ - Installs additional development gems (bundler-audit)
69
+ - Creates necessary directories
70
+ - Generates YARD documentation
71
+ - Runs initial test suite
72
+
73
+ **`.devcontainer/post-start.sh`** - Runs every time container starts:
74
+ - Checks for outdated gems
75
+ - Runs security vulnerability scan
76
+ - Verifies git configuration
77
+ - Checks API key configuration
78
+ - Shows current git branch and status
79
+
80
+ You can customize these scripts to add your own setup tasks. For example:
81
+
82
+ ```bash
83
+ # In post-create.sh - one-time setup
84
+ gem install specific_dev_tool
85
+ bundle exec rake db:setup
86
+
87
+ # In post-start.sh - every container start
88
+ echo "Welcome back!"
89
+ bundle outdated --only-explicit
90
+ ```
91
+
92
+ ### Additional Services
93
+
94
+ To add services like PostgreSQL or Redis, add them to `docker-compose.yml`:
95
+
96
+ ```yaml
97
+ services:
98
+ app:
99
+ # ... existing config ...
100
+ depends_on:
101
+ - postgres
102
+
103
+ postgres:
104
+ image: postgres:15
105
+ environment:
106
+ POSTGRES_PASSWORD: postgres
107
+ volumes:
108
+ - postgres-data:/var/lib/postgresql/data
109
+
110
+ volumes:
111
+ postgres-data:
112
+ ```
113
+
114
+ ## Common Tasks
115
+
116
+ Once inside the container, you can run all the usual development commands:
117
+
118
+ ```bash
119
+ # Install dependencies
120
+ bin/setup
121
+
122
+ # Run tests
123
+ bundle exec rspec
124
+
125
+ # Run linter
126
+ bundle exec standardrb
127
+
128
+ # Auto-fix linting issues
129
+ bundle exec standardrb --fix
130
+
131
+ # Interactive console
132
+ bin/console
133
+
134
+ # Install gem locally
135
+ bundle exec rake install
136
+ ```
137
+
138
+ ## SSH Keys
139
+
140
+ Your SSH keys from `~/.ssh` are mounted read-only into the container, so git operations that require authentication will work seamlessly.
141
+
142
+ ## Bash History
143
+
144
+ Bash history is persisted in a Docker volume, so your command history survives container rebuilds.
145
+
146
+ ## Rebuilding the Container
147
+
148
+ If you make changes to the Dockerfile or devcontainer.json:
149
+
150
+ 1. Open Command Palette (Cmd+Shift+P / Ctrl+Shift+P)
151
+ 2. Run `Dev Containers: Rebuild Container`
152
+
153
+ ## Troubleshooting
154
+
155
+ ### Container won't start
156
+ - Check Docker Desktop is running
157
+ - Try rebuilding: `Dev Containers: Rebuild Container`
158
+ - Check Docker logs for errors
159
+
160
+ ### Permission issues
161
+ - The container runs as `vscode` user (UID 1000)
162
+ - File ownership should match your host user
163
+
164
+ ### Bundle install fails
165
+ - Ensure Docker has enough memory (4GB+ recommended)
166
+ - Try running `bundle install` manually after container starts
167
+
168
+ ### VS Code extensions not working
169
+ - Try reloading the window: `Developer: Reload Window`
170
+ - Check extension installation in the container's Extensions panel
171
+
172
+ ## Benefits of This Setup
173
+
174
+ 1. **Consistent Environment**: Everyone uses the same Ruby version and dependencies
175
+ 2. **Isolated**: No conflicts with other Ruby projects or system Ruby
176
+ 3. **Reproducible**: Works the same on macOS, Linux, and Windows
177
+ 4. **Fast Onboarding**: New developers can get started with one click
178
+ 5. **No Local Ruby Required**: Don't need to manage rbenv, rvm, or system Ruby
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "sec_api Ruby Development",
3
+ "build": {
4
+ "dockerfile": "Dockerfile",
5
+ "args": {
6
+ "RUBY_VERSION": "3.1"
7
+ }
8
+ },
9
+
10
+ "customizations": {
11
+ "vscode": {
12
+ "extensions": [
13
+ "rebornix.ruby",
14
+ "Shopify.ruby-lsp",
15
+ "kaiwood.endwise",
16
+ "jnbt.vscode-rufo",
17
+ "misogi.ruby-rubocop",
18
+ "castwide.solargraph"
19
+ ],
20
+ "settings": {
21
+ "terminal.integrated.defaultProfile.linux": "bash",
22
+ "ruby.useLanguageServer": true,
23
+ "ruby.lint": {
24
+ "standard": true
25
+ },
26
+ "ruby.format": "standard"
27
+ }
28
+ }
29
+ },
30
+
31
+ "features": {
32
+ "ghcr.io/devcontainers/features/git:1": {}
33
+ },
34
+
35
+ "forwardPorts": [],
36
+
37
+ "postCreateCommand": ".devcontainer/post-create.sh",
38
+
39
+ "postStartCommand": ".devcontainer/post-start.sh",
40
+
41
+ "remoteUser": "vscode",
42
+
43
+ "mounts": [
44
+ "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,readonly,type=bind,consistency=cached"
45
+ ]
46
+ }
@@ -0,0 +1,28 @@
1
+ version: '3.8'
2
+
3
+ services:
4
+ app:
5
+ build:
6
+ context: ..
7
+ dockerfile: .devcontainer/Dockerfile
8
+ args:
9
+ RUBY_VERSION: "3.1"
10
+
11
+ volumes:
12
+ - ..:/workspace:cached
13
+ # Persist bash history
14
+ - devcontainer-bashhistory:/home/vscode/.bash_history
15
+
16
+ # Overrides default command so container stays running
17
+ command: sleep infinity
18
+
19
+ # Environment variables for development
20
+ environment:
21
+ # Add any default environment variables here
22
+ - SECAPI_BASE_URL=https://api.sec-api.io
23
+
24
+ # Use host network for easier local development
25
+ network_mode: host
26
+
27
+ volumes:
28
+ devcontainer-bashhistory:
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "Running post-create setup..."
5
+
6
+ # Install Claude Code CLI
7
+ echo "Installing Claude Code CLI..."
8
+ curl -fsSL https://claude.ai/install.sh | bash
9
+
10
+ # Install gem dependencies
11
+ echo "Installing bundle dependencies..."
12
+ bundle install
13
+
14
+ # Install any additional global gems needed for development
15
+ echo "Installing additional development gems..."
16
+ gem install bundler-audit
17
+
18
+ # Set up git hooks if needed (uncomment if you want to use them)
19
+ # echo "Setting up git hooks..."
20
+ # bundle exec overcommit --install
21
+
22
+ # Create any necessary directories
23
+ echo "Creating necessary directories..."
24
+ mkdir -p tmp
25
+ mkdir -p log
26
+
27
+ # Generate YARD documentation
28
+ echo "Generating YARD documentation..."
29
+ bundle exec yard doc --no-progress || true
30
+
31
+ # Run initial test suite to ensure everything works
32
+ echo "Running initial test suite..."
33
+ bundle exec rspec --fail-fast || echo "Warning: Some tests failed. You may want to investigate."
34
+
35
+ # Display useful information
36
+ echo ""
37
+ echo "========================================="
38
+ echo "Post-create setup complete!"
39
+ echo "========================================="
40
+ echo ""
41
+ echo "Available commands:"
42
+ echo " bundle exec rspec - Run tests"
43
+ echo " bundle exec standardrb - Run linter"
44
+ echo " bin/console - Interactive console"
45
+ echo " bundle exec rake - Run default task"
46
+ echo " claude - Claude Code CLI"
47
+ echo ""
48
+ echo "Ruby version: $(ruby -v)"
49
+ echo "Bundler version: $(bundle -v)"
50
+ echo "Claude Code: $(claude --version 2>/dev/null || echo 'not found in PATH yet - restart terminal')"
51
+ echo ""
@@ -0,0 +1,44 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "Running post-start tasks..."
5
+
6
+ # Check for outdated gems
7
+ echo "Checking for outdated gems..."
8
+ bundle outdated --only-explicit || true
9
+
10
+ # Check for security vulnerabilities
11
+ echo "Checking for security vulnerabilities..."
12
+ bundle-audit check --update || echo "Warning: Security vulnerabilities found. Run 'bundle-audit check' for details."
13
+
14
+ # Verify git configuration
15
+ echo "Verifying git configuration..."
16
+ git config --get user.name > /dev/null || echo "Warning: Git user.name not set. Run 'git config --global user.name \"Your Name\"'"
17
+ git config --get user.email > /dev/null || echo "Warning: Git user.email not set. Run 'git config --global user.email \"you@example.com\"'"
18
+
19
+ # Check if API key is configured (if needed)
20
+ if [ -f "config/secapi.yml" ]; then
21
+ echo "API configuration file found: config/secapi.yml"
22
+ elif [ -n "$SECAPI_API_KEY" ]; then
23
+ echo "API key configured via environment variable"
24
+ else
25
+ echo "Note: API key not configured. Set SECAPI_API_KEY environment variable if needed."
26
+ fi
27
+
28
+ # Update bundle if Gemfile.lock is stale (optional - uncomment if desired)
29
+ # if [ Gemfile -nt Gemfile.lock ]; then
30
+ # echo "Gemfile is newer than Gemfile.lock, running bundle install..."
31
+ # bundle install
32
+ # fi
33
+
34
+ # Display current branch and status
35
+ echo ""
36
+ echo "Git branch: $(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo 'unknown')"
37
+ echo "Git status:"
38
+ git status --short 2>/dev/null || echo "Not a git repository"
39
+
40
+ echo ""
41
+ echo "========================================="
42
+ echo "Development environment ready!"
43
+ echo "========================================="
44
+ echo ""
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-04-18
4
+
5
+ - Initial release
data/CLAUDE.md ADDED
Binary file
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Lauri Jutila
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.