I’ve been busy with a family situation.  But in my downtime, late at night, I’ve been learning and writing code.  I came up with a web application that I created in Rails.

Below I’ll provide a summary of what the webapp does, and then a step through of the program.

The program itself is housed at:
https://github.com/wbwarnerb/wowlookup

You can see this in action at my Heroku publish point:

What it does:
I wrote a web application to test some items I learned. The application ties to a public available API from World of Warcraft.  The API I’m talking to is a Quest API.  It’s a simple REST call, that needs a ID appended to the URL.  World of Warcraft responds with JSON.  I convert the JSON into a hash, and then finally output specific elements of the HASH to a results view.

Step Through:
I modified the routes file to point the app to search#index.
From search#index, a view is presented with a very simple form.  The form has only one text field, and a submit button.
When a number is input into the field and a user submits, the number is added as a parameter to the URL being called to World of Warcraft:
This is the WoW URL:
http://us.battle.net/api/wow/quest/
Adding a number to the end, will call the WoW database for quest info for that quest id.

I make this call, and associate it to a instanced variable in the controller, like this:

@output = JSON.parse(open(“http://us.battle.net/api/wow/quest/”+params[:qid]).read)

The instanced variable is @output.  The code: JSON.parse is going to parse the results of the URL we’re calling.  Next the code opens a URL, and I’m passing the ID the user input in the text field with: +params[:qid].  the .read at the end, is just the return of the value.

The data that returns, has some useful info and some not so useful.  I take the hash that’s returned from World of Warcraft (it looks like this:

{"id":9877,"title":"A Restorative Draught","reqLevel":17,"suggestedPartyMembers":0,"category":"Ghostlands","level":20})
and I create a results view.  In the results view I added:
<%= @output['title'] %>
<%= @output['level'] %>
<%= @output['suggestedPartyMembers'] %>
<%= @output['category'] %> 

At the bottom of the results view, I added a link to go back to the search page:
<%= link_to("Go back to Search", { :controller => "search", :action => "index" }) %>

 The code to go back is simple enough. It's just saying Link this text "Go back to Search" with a link to the controller (search) and action (index) - which looks like "/search#index"
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *