Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- ruby: "4.0.1"
bundler: 2.6.3
- ruby: head
bundler: 2.6.3
bundler: 4.0.21
experimental: true
steps:
- uses: actions/checkout@v6
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Fixes

* **`Snippet.list` now requires `workspace_id:`** — Without it the API always returned an empty list. Also accepts `folders:` and `search:` filters.
* Adding `snippet_folder_id` to `Snippet` attributes

## 1.0.0 - 2026-02-18

### Breaking changes
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,12 @@ template = Pdfmonkey::Template.create(
Snippets are reusable HTML components that can be included in templates.

```ruby
# List snippets
snippets = Pdfmonkey::Snippet.list
# List snippets (workspace_id is required)
snippets = Pdfmonkey::Snippet.list(workspace_id: 'f4ab650c-…')

# Filter by folder or search by identifier
snippets = Pdfmonkey::Snippet.list(workspace_id: 'f4ab650c-…', folders: 'folder-id')
snippets = Pdfmonkey::Snippet.list(workspace_id: 'f4ab650c-…', search: 'header')

# Create a snippet
snippet = Pdfmonkey::Snippet.create(
Expand Down
11 changes: 11 additions & 0 deletions lib/pdfmonkey/snippet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Snippet < Resource
errors
id
identifier
snippet_folder_id
updated_at
updater_name
workspace_id
Expand All @@ -23,6 +24,16 @@ class Snippet < Resource
COLLECTION = 'snippets'
MEMBER = 'snippet'

FILTERS = {
workspace_id: 'q[workspace_id]',
folders: 'q[folders]',
search: 'q[search]'
}.freeze

def_delegators :attributes, *ATTRIBUTES

def self.list(workspace_id:, **)
super
end
end
end
2 changes: 1 addition & 1 deletion pdfmonkey.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 2.2'
spec.add_development_dependency 'bundler', '>= 2.2'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.8'
spec.add_development_dependency 'rubocop', '~> 1.68'
Expand Down
28 changes: 26 additions & 2 deletions spec/pdfmonkey/snippet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,39 @@
end

it 'returns a Collection' do
result = described_class.list
result = described_class.list(workspace_id: 'ws-1')
expect(result).to be_a(Pdfmonkey::Collection)
end

it 'contains Snippet items' do
result = described_class.list
result = described_class.list(workspace_id: 'ws-1')
expect(result.first).to be_a(described_class)
expect(result.first.identifier).to eq('header')
end

it 'requires workspace_id' do
expect { described_class.list }.to raise_error(ArgumentError)
end

it 'passes workspace_id, folders, search and page params' do
described_class.list(workspace_id: 'ws-1', folders: 'folder-1', search: 'head', page: 2)

expect(adapter).to have_received(:call).with(
:get, anything,
params: hash_including(
'q[workspace_id]' => 'ws-1',
'q[folders]' => 'folder-1',
'q[search]' => 'head',
'page[number]' => 2
),
extract: :collection
)
end

it 'rejects unknown filters' do
expect { described_class.list(workspace_id: 'ws-1', sort: 'name') }
.to raise_error(ArgumentError, /Unknown filter/)
end
end

describe '.fetch' do
Expand Down
Loading