Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ jobs:
env:
UPLOADCARE_PUBLIC_KEY: demopublickey
UPLOADCARE_SECRET_KEY: demoprivatekey
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.ruby-version == '3.3'
with:
file: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
Comment on lines +37 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update to a newer version of codecov/codecov-action

The static analysis tool indicates that codecov/codecov-action@v3 is too old to run on GitHub Actions. Consider updating to @v4 which is the current stable version.

-    - name: Upload coverage reports to Codecov
-      uses: codecov/codecov-action@v3
-      if: matrix.ruby-version == '3.3'
-      with:
-        file: ./coverage/lcov.info
-        flags: unittests
-        name: codecov-umbrella
-        fail_ci_if_error: false
+    - name: Upload coverage reports to Codecov
+      uses: codecov/codecov-action@v4
+      if: matrix.ruby-version == '3.3'
+      with:
+        file: ./coverage/lcov.info
+        flags: unittests
+        name: codecov-umbrella
+        fail_ci_if_error: false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: matrix.ruby-version == '3.3'
with:
file: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
if: matrix.ruby-version == '3.3'
with:
file: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
🧰 Tools
🪛 actionlint (1.7.7)

38-38: the runner of "codecov/codecov-action@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🤖 Prompt for AI Agents
In .github/workflows/ruby.yml around lines 37 to 44, the codecov GitHub Action
is using an outdated version v3. Update the version from
codecov/codecov-action@v3 to codecov/codecov-action@v4 to use the current stable
release compatible with GitHub Actions.


style-check:
runs-on: ubuntu-latest
Expand Down
6 changes: 0 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ Layout/LineLength:
Lint/IneffectiveAccessModifier:
Enabled: false

Style/HashTransformKeys:
Exclude:
- 'lib/uploadcare/entity/decorator/paginator.rb'
- 'lib/uploadcare/client/conversion/video_conversion_client.rb'
- 'lib/uploadcare/entity/file.rb'

Metrics/BlockLength:
Exclude:
- 'bin/'
Expand Down
122 changes: 122 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Uploadcare Ruby SDK - Ruby client library for Uploadcare's Upload and REST APIs, providing file upload, management, and transformation capabilities.

## Development Commands

### Environment Setup
- Ruby 3.0+ required (use mise for version management: `mise use ruby@latest`)
- Install dependencies: `bundle install`
- Add `gem 'base64'` to Gemfile if using Ruby 3.4+ to avoid vcr gem warnings

### Testing
- Run all tests: `bundle exec rake spec` or `bundle exec rspec`
- Run specific test file: `bundle exec rspec spec/uploadcare/resources/file_spec.rb`
- Run with documentation format: `bundle exec rspec --format documentation`
- Run with fail-fast: `bundle exec rspec --fail-fast`
- Test environment variables required:
- `UPLOADCARE_PUBLIC_KEY=demopublickey`
- `UPLOADCARE_SECRET_KEY=demoprivatekey`

### Code Quality
- Run linter: `bundle exec rubocop`
- Run linter with auto-fix: `bundle exec rubocop -a`
- Run all checks (tests + linter): `bundle exec rake`

## Architecture Overview

### Core Module Structure
The gem uses Zeitwerk autoloading with collapsed directories for resources and clients:

- **lib/uploadcare.rb** - Main module, configures Zeitwerk autoloading
- **lib/uploadcare/configuration.rb** - Configuration management
- **lib/uploadcare/api.rb** - Main API interface (deprecated pattern, use resources directly)
- **lib/uploadcare/client.rb** - New client pattern for API interactions

### Resource Layer (lib/uploadcare/resources/)
Domain objects representing Uploadcare entities:
- **file.rb** - File upload/management operations
- **group.rb** - File group operations
- **webhook.rb** - Webhook management
- **uploader.rb** - Upload coordination
- **paginated_collection.rb** - Pagination support for list operations
- **batch_file_result.rb** - Batch operation results
- **add_ons.rb** - Add-on services (AWS Rekognition, ClamAV, Remove.bg)
- **document_converter.rb** - Document conversion operations
- **video_converter.rb** - Video conversion operations

### Client Layer (lib/uploadcare/clients/)
HTTP client implementations for API communication:
- **rest_client.rb** - Base REST API client
- **upload_client.rb** - Upload API client
- **multipart_upload_client.rb** - Multipart upload handling
- **uploader_client.rb** - Upload coordination client
- **file_client.rb** - File management endpoints
- **group_client.rb** - Group management endpoints
- **webhook_client.rb** - Webhook endpoints
- **project_client.rb** - Project info endpoints

### Middleware Layer (lib/uploadcare/middleware/)
Request/response processing:
- **base.rb** - Base middleware class
- **retry.rb** - Retry logic for failed requests
- **logger.rb** - Request/response logging

### Error Handling
- **lib/uploadcare/error_handler.rb** - Central error parsing and handling
- **lib/uploadcare/exception/** - Custom exception types
- **request_error.rb** - Base request errors
- **auth_error.rb** - Authentication errors
- **throttle_error.rb** - Rate limiting errors
- **retry_error.rb** - Retry exhaustion errors

### Utilities
- **lib/uploadcare/authenticator.rb** - Request signing and authentication
- **lib/uploadcare/url_builder.rb** - CDN URL generation with transformations
- **lib/uploadcare/signed_url_generators/** - Secure URL generation (Akamai)
- **lib/uploadcare/throttle_handler.rb** - Rate limit handling

## Key Design Patterns

1. **Resource-Client Separation**: Resources handle business logic, clients handle HTTP communication
2. **Zeitwerk Autoloading**: Uses collapsed directories for cleaner require structure
3. **Middleware Pattern**: Extensible request/response processing pipeline
4. **Result Objects**: Many operations return Success/Failure result objects
5. **Lazy Loading**: Paginated collections fetch data on demand

## API Configuration

Configuration can be set via:
- Environment variables: `UPLOADCARE_PUBLIC_KEY`, `UPLOADCARE_SECRET_KEY`
- Code: `Uploadcare.config.public_key = "key"`
- Per-request: Pass config to individual resource methods

## Testing Approach

- Uses RSpec for testing
- VCR for recording/replaying HTTP interactions
- SimpleCov for code coverage reporting
- Tests are in `spec/uploadcare/` mirroring lib structure
- Fixtures and cassettes in `spec/fixtures/`

## Common Development Tasks

### Adding New API Endpoints
1. Create/update client in `lib/uploadcare/clients/`
2. Create/update resource in `lib/uploadcare/resources/`
3. Add corresponding specs in `spec/uploadcare/`
4. Update README.md with usage examples

### Handling API Responses
- Use `Uploadcare::ErrorHandler` for error parsing
- Return result objects for operations that can fail
- Parse JSON responses into Ruby objects/hashes

### Working with Batch Operations
- Use `BatchFileResult` for batch store/delete results
- Handle both successful results and problem items
- Follow pattern in `File.batch_store` and `File.batch_delete`
Loading
Loading