Module: Alexandrite::OCLCAPI
- Includes:
- Helpers::Format, Helpers::Validation, Nokogiri
- Included in:
- OCLC
- Defined in:
- lib/alexandrite_oclc.rb
Overview
Consume OCLC API
Constant Summary collapse
- BASE_URL =
'http://classify.oclc.org/classify2/Classify?'
Instance Method Summary collapse
- #get_book_data(result) ⇒ Object
- #recommend_classification(key, query, length = 5, mode: 'ddc') ⇒ Object
- #search_by(key, query, summary: true) ⇒ Faraday::Response
Methods included from Helpers::Validation
#define_isbn_type, #valid_isbn_length?, #validate_isbn
Methods included from Helpers::Format
#add_fields, #remove_non_digits
Instance Method Details
#get_book_data(result) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/alexandrite_oclc.rb', line 33 def get_book_data(result) isbn = result.css('input').children.text isbn_type = define_isbn_type(isbn) { 'origin' => 'OCLC API', 'title' => result.css('work').attribute('title').value, 'authors' => result.css('work').attribute('author').value, 'ddc' => result.css('mostPopular').attribute('nsfa').value, isbn_type => isbn } end |
#recommend_classification(key, query, length = 5, mode: 'ddc') ⇒ Object
45 46 47 48 49 |
# File 'lib/alexandrite_oclc.rb', line 45 def recommend_classification(key, query, length = 5, mode: 'ddc') results = search_by(key, query) response_cases(results, length, mode) end |
#search_by(key, query, summary: true) ⇒ Faraday::Response
25 26 27 28 29 30 31 |
# File 'lib/alexandrite_oclc.rb', line 25 def search_by(key, query, summary: true) search = "#{BASE_URL}#{key}=#{query}&summary=#{summary}" conn = Faraday.new(search) do |r| r.get(search).body end Nokogiri::XML(conn.get(search).body) end |