Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reading bookmarks XML file.

  • Loading branch information...
commit 6f6f1c8b9e63a33815a8a525e08179c0aacbc950 1 parent 32f7a6d
@daviferreira authored
View
3  Gemfile
@@ -7,4 +7,5 @@ gem 'shotgun'
gem 'rspec'
gem 'haml'
gem 'curb'
-gem 'json'
+gem 'json'
+gem 'nokogiri'
View
1  Gemfile.lock
@@ -63,6 +63,7 @@ DEPENDENCIES
curb
haml
json
+ nokogiri
rspec
shotgun
sinatra
View
12 features/files/bookmarks.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<posts user="daviferreira" update="2010-12-16T19:03:13Z" tag="" total="8">
+ <post href="http://designshack.co.uk/articles/software/10-fresh-mac-apps-with-beautiful-interfaces-and-what-we-can-learn-from-them" hash="b2e64a857b942965129bed75eef84143" description="10 Fresh Mac Apps With Beautiful Interfaces (and What We Can Learn From Them) | Design Shack" tag="mac apps interface inspiration" time="2010-12-16T19:03:13Z" extended="" meta="73a569d3dd52e0bfd606df6f420c8e8b" />
+ <post href="http://maironbrasil.wordpress.com/2010/12/10/o-comovente-guia-de-ruby-do-why-em-pdf/" hash="d1e4592b3e769c1314a7e3388acb6ac5" description="O Comovente guia de Ruby do Why em PDF « Mairon D. Brasil Ruby on Rails" tag="ruby" time="2010-12-16T12:59:32Z" extended="" meta="f81f1746e827f62507cb32d111f3c0d0" />
+ <post href="http://goncin.wordpress.com/2010/12/16/normalizando-nomes-proprios-com-php/" hash="d277552377b562275a4196cd6ecabaa1" description="Normalizando nomes próprios com PHP « goncin@wordpress.com:~$ _" tag="php" time="2010-12-16T12:58:10Z" extended="" meta="9bd578a8bdf5f489bcfe2237ab9d75ef" />
+ <post href="http://www.candykiller.com/gallery1.htm" hash="5565e204b3ae15b9df25976a140d8928" description="Candykiller" tag="tattoo" time="2010-12-15T19:15:27Z" extended="" meta="2ee0f67e47c795e2ae5e9f9eea88eb61" />
+ <post href="http://art-history.tumblr.com/" hash="3b99b30b55387225ce604ec4948b0c0e" description="Art History" tag="art" time="2010-12-15T19:05:24Z" extended="" meta="000048f5a7b75ea921e817052565d714" />
+ <post href="http://tapmates.com/blog/instagram" hash="7698657f90867901126552555f8b8b73" description="Tapmates Blog — An open letter to Instagram" tag="inspiration" time="2010-12-14T18:39:33Z" extended="" meta="956b8a7ee08f956b8f5fb6cb00978f89" />
+ <post href="http://tympanus.net/Tutorials/MoleskineNotebook/" hash="3273f59e3037a5304a4240355a70294e" description="Moleskine Notebook with jQuery Booklet" tag="jquery" time="2010-12-14T18:20:16Z" extended="" meta="de3069af5f51ccd16f87e20e59743a75" />
+ <post href="http://thefrontiergroup.com.au/blog/2010/12/a-brief-introduction-to-the-rvm-ruby-api/" hash="31c3f708d7121363765cc8d36ab98bea" description="A brief introduction to the RVM Ruby API » Transcending Frontiers" tag="ruby rvm" time="2010-12-14T13:01:29Z" extended="" meta="a5837ee8f94efb21c51c7b31844ab01e" />
+</posts>
+<!-- fe06.api.del.ac4.yahoo.net uncompressed/chunked Fri Dec 17 16:07:24 UTC 2010 -->
View
12 features/step_definitions/gimmelicious_steps.rb
@@ -16,4 +16,16 @@
Then /^I should see a button named "([^"]*)"$/ do |text|
page.should have_button text
+end
+
+When /^I fill in "([^"]*)" with "([^"]*)"$/ do |element, text|
+ fill_in element, with: text
+end
+
+When /^I upload a file with valid data$/ do
+ attach_file("bookmarks", File.join(File.dirname(__FILE__), '/../files', 'bookmarks.xml'))
+end
+
+When /^I click "([^"]*)"$/ do |element|
+ click_on element
end
View
11 features/upload_bookmarks.feature
@@ -0,0 +1,11 @@
+Feature: Upload delicious xml files
+ In order to import my bookmarks
+ As a delicious user
+ I want to upload my bookmarks xml file
+
+ Scenario: Upload file
+ Given I am on the home page
+ When I upload a file with valid data
+ And I click "Upload!"
+ Then I should see "You have 8 bookmarks with 10 tags"
+
View
7 gimmelicious.rb
@@ -1,5 +1,6 @@
require 'sinatra/base'
require 'haml'
+require 'nokogiri'
class Gimmelicious < Sinatra::Base
@@ -7,4 +8,10 @@ class Gimmelicious < Sinatra::Base
haml :index
end
+ post '/upload' do
+ doc = Nokogiri::XML(File.open(params[:bookmarks][:tempfile]))
+ @bookmarks = doc.xpath("//post")
+ haml :bookmarks
+ end
+
end
View
6 test_curl/nokogiri.rb
@@ -0,0 +1,6 @@
+require 'nokogiri'
+
+doc = Nokogiri::XML(File.open(File.join(File.dirname(__FILE__), '/../features/files', 'bookmarks.xml')))
+doc.xpath("//post").each do |post|
+ p post.attributes["description"].value + "\n"
+end
View
3  views/bookmarks.haml
@@ -0,0 +1,3 @@
+-@bookmarks.each do |bookmark|
+ %p
+ =bookmark.attributes["description"].value
View
2  views/index.haml
@@ -15,7 +15,7 @@
%p Don't know how to backup your delicious bookmarks?
%a{:href => "http://lifehacker.com/5136845/backup-delicious-bookmarks-from-the-shell", :target => "_blank"} Backup Delicious Bookmarks from the Shell
- %form.form-stacked
+ %form.form-stacked{:method => "post", :action => "/upload", :enctype => "multipart/form-data"}
%fieldset
%label Locate your XML file
%div.field
Please sign in to comment.
Something went wrong with that request. Please try again.