diff --git a/lib/metabase/endpoint/collection.rb b/lib/metabase/endpoint/collection.rb index 3e830f1..f1b9fe4 100644 --- a/lib/metabase/endpoint/collection.rb +++ b/lib/metabase/endpoint/collection.rb @@ -11,6 +11,26 @@ module Collection def collections(**params) get('/api/collection', **params) end + + # Fetch a specific collection. + # + # @param collection_id [Integer, String] Collection ID + # @return [Array] Parsed response JSON + # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apicollectionid + def collection(collection_id, **params) + get("/api/collection/#{collection_id}", **params) + end + + # Fetch a specific collection items. + # + # @param collection_id [Integer, String] Collection ID + # @param model [String] value may be nil, or card, collection, dashboard, pulse or snippet. + # @param archived [Boolean] + # @return [Array] Parsed response JSON + # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apicollectioniditems + def collection_items(collection_id, **params) + get("/api/collection/#{collection_id}/items", **params) + end end end end diff --git a/spec/metabase/endpoint/collection_spec.rb b/spec/metabase/endpoint/collection_spec.rb index fe4b328..09b3a7b 100644 --- a/spec/metabase/endpoint/collection_spec.rb +++ b/spec/metabase/endpoint/collection_spec.rb @@ -11,4 +11,22 @@ end end end + + describe 'collection', vcr: true do + context 'success' do + it 'returns collection' do + collection = client.collection(1) + expect(collection).to be_kind_of(Array) + end + end + end + + describe 'collection_items', vcr: true do + context 'success' do + it 'returns collection items' do + collection_items = client.collection_items(1) + expect(collection_items).to be_kind_of(Array) + end + end + end end