Hello i''ve made a class to Get an XML response from an API.
My problem is, i have to map the response into a usable format.
What i want is an array of listitems with elements.
What i did is create some arrays of the elemens but i have to put them
together.
and i have to sort all the elements by title.
is it best to make it a hash?
[title => id, word_count, .... ]
I would be able te put in my view
@list.each do |list|
list.title, list.id, list.word_count, list.lang_a, list.lang_b
end
Thie is what my class looks like:
class List
attr_reader :list
LOGIN = "XXXXXXX"
PASSWORD = "XXXXXXX"
def fetch_lists
Net::HTTP.start(''www.wrts.nl'') {|http|
req = Net::HTTP::Get.new(''/api/lists/'')
req.basic_auth LOGIN, PASSWORD
response = http.request(req)
doc = Nokogiri::XML(response.body)
@doc = doc.xpath(''/list-index//list'')
}
end
def zip_and_sort
title = @doc.xpath(''title'').map {|x| x.text} => Title1,
Title2.....
id = @doc.xpath(''id'').map {|x| x.text} => id1, id2.....
word_count = @doc.xpath(''word-count'').map {|x| x.text}
=> word-
coun1, word-count2.....
lang_a = @doc.xpath(''lang-a'').map {|x| x.text} =>
lang-a1, lang-
a2.....
lang_b = @doc.xpath(''lang-b'').map {|x| x.text} =>
lang-b1, lang-
b2.....
end
end
What is the best way to put this in a usable format?
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.