Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:06:03+00:00 2026-06-15T21:06:03+00:00

This is my first attempt at getting data back from an API, and getting

  • 0

This is my first attempt at getting data back from an API, and getting the data to output to a view.

I want to put an ISBN number into a search form and get the data back for that particular book using http://isbndb.com/. This is what I have so far:

Controller:

require 'open-uri'
class BookController < ApplicationController
  def searchbook
  resp = open("http://isbndb.com/api/books.xml?access_key=#{'API KEY HERE'}&results=texts&index1=isbn&value1=#{params[:isbn]}")
  doc = Nokogiri.XML(resp.read)
  # ... process response here

 end
end

Form:

<%= form_tag({:controller => 'book', :action => 'searchbook'}, {:method => 'get'}) do |select| %>
<%= label_tag :isbn, "Enter ISBN Number" %>
<%= text_field_tag :isbn, params[:isbn] %>
<%= submit_tag "Search" %>
<% end %>

The XML to be returned

  <?xml version="1.0" encoding="UTF-8"?>
  <ISBNdb server_time="2005-07-29T03:02:22">
  <BookList total_results="1" page_size="10" page_number="1" shown_results="1">
  <BookData book_id="paul_laurence_dunbar" isbn="0766013502">
  <Title>Paul Laurence Dunbar</Title>
  <TitleLong>Paul Laurence Dunbar: portrait of a poet</TitleLong>
  <AuthorsText>Catherine Reef</AuthorsText>
  <PublisherText publisher_id="enslow_publishers">Berkeley Heights, NJ: Enslow Publishers, c2000.</PublisherText>
  <Summary>A biography of the poet who faced racism and devoted himself to depicting the black experience in America.</Summary>
  <Notes>"Works by Paul Laurence Dunbar": p. 113-114. Includes bibliographical references (p. 124) and index.</Notes>
  <UrlsText></UrlsText>
  <AwardsText></AwardsText>
  </BookData>
</BookList>
  </ISBNdb>

How do I process an XML request or what can I read to find out how?

Where can I view the data being returned in the console (if any)? I’m not even sure that this is doing anything as yet, however upon clicking “search” in my form I am taken to the searchbook action which is a blank page for now.

I may be a long way off from the whole answer but this is my first time doing this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:06:04+00:00Added an answer on June 15, 2026 at 9:06 pm

    Parsing the XML is easy:

    require 'nokogiri'
    
    doc = Nokogiri::XML(<<EOT)
      <?xml version="1.0" encoding="UTF-8"?>
      <ISBNdb server_time="2005-07-29T03:02:22">
      <BookList total_results="1" page_size="10" page_number="1" shown_results="1">
      <BookData book_id="paul_laurence_dunbar" isbn="0766013502">
      <Title>Paul Laurence Dunbar</Title>
      <TitleLong>Paul Laurence Dunbar: portrait of a poet</TitleLong>
      <AuthorsText>Catherine Reef</AuthorsText>
      <PublisherText publisher_id="enslow_publishers">Berkeley Heights, NJ: Enslow Publishers, c2000.</PublisherText>
      <Summary>A biography of the poet who faced racism and devoted himself to depicting the black experience in America.</Summary>
      <Notes>"Works by Paul Laurence Dunbar": p. 113-114. Includes bibliographical references (p. 124) and index.</Notes>
      <UrlsText></UrlsText>
      <AwardsText></AwardsText>
      </BookData>
    </BookList>
      </ISBNdb>
    EOT
    
    isbn_data = doc.search('BookData').map{ |book_data|
    
      hash = {}
    
      %w[ book_id isbn ].each do |p|
        hash[p.downcase.to_sym] = book_data[p]
      end
    
      %w[ Title TitleLong AuthorsText PublisherText Summary ].each do |t|
        hash[t.downcase.to_sym] = book_data.at(t).text
      end
    
      hash
    }
    
    pp isbn_data
    

    Which outputs:

    [{:book_id=>"paul_laurence_dunbar",
      :isbn=>"0766013502",
      :title=>"Paul Laurence Dunbar",
      :titlelong=>"Paul Laurence Dunbar: portrait of a poet",
      :authorstext=>"Catherine Reef",
      :publishertext=>"Berkeley Heights, NJ: Enslow Publishers, c2000.",
      :summary=>
       "A biography of the poet who faced racism and devoted himself to depicting the black experience in America."}]
    

    This code was based on the idea you might be receiving multiple <BookData> blocks, so it returns an array of hashes. If you’ll only have one use:

    hash = {}
    book_data = doc.at('BookData')
    
    %w[ book_id isbn ].each do |p|
      hash[p.downcase.to_sym] = book_data[p]
    end
    
    %w[ Title TitleLong AuthorsText PublisherText Summary ].each do |t|
      hash[t.downcase.to_sym] = book_data.at(t).text
    end
    
    pp hash
    

    The output now looks like:

    {:book_id=>"paul_laurence_dunbar",
     :isbn=>"0766013502",
     :title=>"Paul Laurence Dunbar",
     :titlelong=>"Paul Laurence Dunbar: portrait of a poet",
     :authorstext=>"Catherine Reef",
     :publishertext=>"Berkeley Heights, NJ: Enslow Publishers, c2000.",
     :summary=>
      "A biography of the poet who faced racism and devoted himself to depicting the black experience in America."}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first attempt at using the Google Data API, and I'm getting
This is my first attempt to prototype. I want to initiate an AJAX request
This is my first attempt with JQgrid and I am confused from the documentation
This is my first attempt at responsive design, so I'm keeping it simple. I
This is my first attempt to write shorthand if statements however am befuddled by
this if my first attempt at using streaming for WCF, and I am struggling
This is my first attempt to create a GUI in MATLAB. I haven't been
this is my first attempt at a responsive design so excuse me if this
Because this is my first attempt at an extension method that seems quite useful
Up front: This is my first attempt at an Android app. I'm in that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.