Exposing Collections in External Applications
- Lobby with a list of top level collections
- Collection home page which includes sub-collections and collection members
We’ll add this functionality to the My Alma Library sample app that we’ve used in the past. The application is written in Ruby on Rails.
Collection Lobby
One possible entry point for our collection interface is a lobby which lists the top level collections. To build this list, we’ll use the Get Collections API. The Get Collections API returns a list of collections, and takes a parameter which indicates how many levels in the hierarchy to provide. Since we only want to display the top level collections, we’ll use the default of 1 for the level parameter. So in our collection controller, we’ll use a helper method to call the Get Collections API:
def index @collections = alma_api_get "/bibs/collections" end
Then in our collection index view, we’ll loop through all of the top level collections and display the collection name, description and thumbnail using the appropriate properties. From each top level collection we’ll provide a link to view the collection’s home page.
Collection Home Page
The collection home page will need to support the display of both sub-collections and collection titles. In the controller, we first use the Get Collection API to retrieve the collection details with a level parameter of 2, indicating that we’d like sub-collections that are direct descendants of our collection. We also retrieve the first page of titles using the Get Collection Titles API.
def show @collection = alma_api_get "/bibs/collections/#{params[:id]}?level=2" @titles = get_titles params[:id] end def get_titles(collection_id) start = params["start"] || 0 @limit = params["limit"] || 6 alma_api_get "/bibs/collections/#{collection_id}/bibs?offset=#{start}&limit=#{@limit}" end
Sub Collections

Titles

Displaying the titles in a partial view allows us to perform paging without refreshing the entire screen by updating the titles panel with subsequent AJAX calls. When a user clicks on the page number or the next/previous buttons, we use some jQuery magic to show a loading icon and call the titles path.
$("#titles").on("click", "a.paging-link", function(e) { $("#titles").html('<%= image_tag "loading.gif" %>'); var url='<%= collection_titles_path(@collection["pid"]["value"])%>'; $("#titles").load(url + '?' + (this.href.split('?')[1] || '')); return false; });
Integrating with the View It
To accomplish this we create a hidden iFrame:
<iframe style="display: none" id="delivery"></iframe>
When a user clicks the View link, we intercept the click with some jQuery and populate the iFrame with the view-it:
$("#titles").on("click", "a.popup", function(e){ e.preventDefault(); var url = $(this).attr('href'); // hidden iFrame method (requires automatic open setting in Alma) $("#delivery").attr('src', url); }

Further Exploration
