Relaton-ISBN: retrieves bibliographic items using OpenLibrary API
RelatonIsbn is a Ruby gem that implements the IsoBibliographicItem model.
You can use it to retrieve metadata of Standards from https://openlibrary.org, and
access such metadata through the BibliographicItem
object.
Installation
Add this line to your application’s Gemfile:
gem 'relaton-isbn'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install relaton-isbn
Usage
Retrieving bibliographic items using OpenLibrary API
To retrieve bibliographic items, use RelatonIsbn::OpenLibrary.get
method with ISBN-10 or ISBN-13 as an argument. Allowed prefixes are ISBN
, isbn:
. Prefix and hyphens are optional. The method returns RelatonBib::BibliographicItem
object.
require 'relaton_isbn'
=> true
# get document by ISBN-13
> ibitem = RelatonIsbn::OpenLibrary.get "ISBN 978-0-12-064481-0"
[relaton-isbn] (ISBN 9780120644810) Fetching from OpenLibrary ...
[relaton-isbn] (ISBN 9780120644810) Found: `9780120644810`
=> #<RelatonBib::BibliographicItem:0x0000000113889258
...
# get document by ISBN-10
> RelatonIsbn::OpenLibrary.get "isbn:0120644819"
[relaton-isbn] (isbn:0120644819) Fetching from OpenLibrary ...
[relaton-isbn] (isbn:0120644819) Found: `9780120644810`
=> #<RelatonBib::BibliographicItem:0x00000001098ac960
...
Serializing bibliographic items
# serialize to XML
> puts bibitem.to_xml
<bibitem id="9780120644810" schema-version="v1.2.7">
<title type="main" format="text/plain">Graphics gems II</title>
<uri type="src">http://openlibrary.org/books/OL21119585M/Graphics_gems_II</uri>
<docidentifier type="ISBN" primary="true">9780120644810</docidentifier>
<date type="published">
<on>1991</on>
</date>
<contributor>
<role type="author"/>
<person>
<name>
<completename>James Arvo</completename>
</name>
</person>
</contributor>
<contributor>
<role type="publisher"/>
<organization>
<name>AP Professional</name>
</organization>
</contributor>
<place>
<city>Boston</city>
</place>
<place>
<city>London</city>
</place>
</bibitem>
# serialize to bibdata XML
> puts bibitem.to_xml bibdata: true
<bibdata schema-version="v1.2.7">
<title type="main" format="text/plain">Graphics gems II</title>
...
# serialize to hash
> bibitem.to_hash
=> {"schema-version"=>"v1.2.7",
"id"=>"9780120644810",
"title"=>[{"content"=>"Graphics gems II", "format"=>"text/plain", "type"=>"main"}],
"link"=>[{"content"=>"http://openlibrary.org/books/OL21119585M/Graphics_gems_II", "type"=>"src"}],
"docid"=>[{"id"=>"9780120644810", "type"=>"ISBN", "primary"=>true}],
"date"=>[{"type"=>"published", "value"=>"1991"}],
"contributor"=>
[{"person"=>{"name"=>{"completename"=>{"content"=>"James Arvo"}}, "url"=>"http://openlibrary.org/authors/OL2646519A/James_Arvo"}, "role"=>[{"type"=>"author"}]},
{"organization"=>{"name"=>[{"content"=>"AP Professional"}]}, "role"=>[{"type"=>"publisher"}]}],
"revdate"=>"1991",
"place"=>[{"city"=>"Boston"}, {"city"=>"London"}]}
Logging
RelatonIsbn uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the relaton-logger documentation.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run
rake spec
to run the tests. You can also run bin/console
for an interactive
prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To
release a new version, update the version number in version.rb
, and then run
bundle exec rake release
, which will create a git tag for the version, push
git commits and the created tag, and push the .gem
file to
rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/relaton/relaton-isbn.
License
The gem is available as open source under the terms of the MIT License.