Permalink
Browse files

Adding Kindle price fetching

  • Loading branch information...
1 parent d209884 commit 62451bf432303e2673cac057e149e5930fa8bed3 @swaroopch committed Jul 31, 2011
Showing with 20 additions and 1 deletion.
  1. +15 −0 app/models/bookprice.rb
  2. +5 −1 app/views/book/view.html.erb
View
@@ -256,6 +256,21 @@ def search_crossword(isbn)
{ :price => NOT_AVAILABLE, :url => url }
end
end
+
+ def search_kindle(isbn)
+ url = "http://www.amazon.com/s/ref=nb_sb_noss?url=node%3D1286228011&field-keywords=#{isbn}&x=0&y=0"
+ page = self.fetch_page(url)
+ unless page.nil?
+ text = page.search("span.sr_price")
+ if text.present?
+ text = text.text
+ end
+ text = "" if text.blank?
+ { :price => find_price_at_end(text), :url => url }
+ else
+ { :price => NOT_AVAILABLE, :url => url }
+ end
+ end
end
end
@@ -52,7 +52,11 @@
</td>
<td>
<% unless data[:price] == @not_available %>
- <span style="font-family:rupee">R</span> <%= data[:price] %>
+ <% if store == :kindle %>
+ $ <%= data[:price] %>
+ <% else %>
+ <span style="font-family:rupee">R</span> <%= data[:price] %>
+ <% end %>
<% else %>
not available
<% end %>

0 comments on commit 62451bf

Please sign in to comment.