# Purée Metadata extraction from the Pure Research Information System. ## Status [![Gem Version](https://badge.fury.io/rb/puree.svg)](https://badge.fury.io/rb/puree) [![Maintainability](https://api.codeclimate.com/v1/badges/0a0a8249dcadb444eb9e/maintainability)](https://codeclimate.com/github/lulibrary/puree/maintainability) ## Installation Add this line to your application's Gemfile: gem 'puree' And then execute: $ bundle Or install it yourself as: $ gem install puree ## Configuration ```ruby # For Extractor and REST modules. config = { url: 'https://YOUR_HOST/ws/api/59', username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD', api_key: 'YOUR_API_KEY' } ``` ## Extractor module ```ruby # Configure an extractor for a resource extractor = Puree::Extractor::Dataset.new config ``` ```ruby # Find out how many records are available extractor.count #=> 1000 ``` ```ruby # Fetch a random record extractor.random #=> # ``` ```ruby # Fetch the metadata for a record with a particular identifier dataset = extractor.find 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' #=> # ``` ```ruby # Access specific metadata e.g. an internal person's name dataset.persons_internal[0].name #=> # ``` ```ruby # Select a formatting style for a person's name dataset.persons_internal[0].name.last_initial #=> "Bar, F." ``` ## XMLExtractor module Get Ruby objects from Pure XML. ### Single record ```ruby xml = ' ... ' ``` ```ruby # Configure an XML extractor xml_extractor = Puree::XMLExtractor::Project.new xml ``` ```ruby # Get a single piece of metadata xml_extractor.title #=> "An interesting project title" ``` ```ruby # Get all the metadata together xml_extractor.model #=> # ``` ### Homogeneous record collection ```ruby xml = ' ... ... ... ' ``` ```ruby # Get an array of datasets Puree::XMLExtractor::Collection.datasets xml #=> [#, ...] ``` ### Heterogeneous record collection ```ruby xml = ' ... ... ... ' ``` ```ruby # Get a hash of research outputs Puree::XMLExtractor::Collection.research_outputs xml #=> { # journal_articles: [#, ...], # conference_papers: [#, ...], # theses: [#, ...], # other: [#, ...] # } ``` ## REST module Query the Pure REST API. ### Client ```ruby # Configure a client client = Puree::REST::Client.new config ``` ```ruby # Find a person client.persons.find id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' #=> # ``` ```ruby # Find a person, limit the metadata to ORCID and employee start date client.persons.find id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx', params: {fields: ['orcid', 'employeeStartDate']} #=> # ``` ```ruby # Find five people, response body as JSON client.persons.all params: {size: 5}, accept: :json #=> # ``` ```ruby # Find three active academics params = { size: 3, employmentTypeUri: ['/dk/atira/pure/person/employmenttypes/academic'], employmentStatus: 'ACTIVE' } client.persons.all_complex params: params #=> # ``` ```ruby # Find research outputs for a person client.persons.research_outputs id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' #=> # ``` ### Resource ```ruby # Configure a resource persons = Puree::REST::Person.new config ``` ```ruby # Find a person persons.find id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' #=> # ``` ## REST module with XMLExtractor module Query the Pure REST API and get Ruby objects from Pure XML. ```ruby # Configure a client client = Puree::REST::Client.new config ``` ```ruby # Find projects for a person response = client.persons.projects id: 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' ``` ```ruby # Extract metadata from XML Puree::XMLExtractor::Collection.projects response.to_s #=> [#, ...] ```