2012-04-12 7 views
0

Ich create Linked-Client wie folgt.So konvertieren Sie Linkedin-Client in Rails zu Hash

client = LinkedIn::Client.new("3333", "rrrrrrr") 
    client.authorize_from_access(session[:atoken], session[:asecret]) 

und erhalten Informationen über die Profile wie dieses

@profile = client.profile 

, wenn ich das Profil drucken wie "puts client.profile", bekomme ich nach dem löschte

#<LinkedIn::Profile:0x4a77770 @doc=#<Nokogiri::XML::Document:0x253bb64 name="document" children=[#<Nokogiri::XML::Element:0x253b9fc name="pers 
on" children=[#<Nokogiri::XML::Text:0x253b87c "\n ">, #<Nokogiri::XML::Element:0x253b84c name="first-name" children=[#<Nokogiri::XML::Text:0x 
253b684 "Anthony">]>, #<Nokogiri::XML::Text:0x253b5ac "\n ">, #<Nokogiri::XML::Element:0x253b57c name="last-name" children=[#<Nokogiri::XML:: 
Text:0x253b3b4 "Raj S">]>, #<Nokogiri::XML::Text:0x253b2dc "\n ">, #<Nokogiri::XML::Element:0x253b2ac name="headline" children=[#<Nokogiri::X 
ML::Text:0x253b0e4 "Senior Software Engineer at AB Innovative Software Pvt. Ltd">]>, #<Nokogiri::XML::Text:0x253b00c "\n ">, #<Nokogiri::XML: 
:Element:0x253afdc name="site-standard-profile-request" children=[#<Nokogiri::XML::Text:0x253ae14 "\n ">, #<Nokogiri::XML::Element:0x253ade 
4 name="url" children=[#<Nokogiri::XML::Text:0x253ac1c "http://www.linkedin.com/profile?viewProfile=&key=78718913&authToken=XE_V&authType=name 
&trk=api*a178337*s186521*">]>, #<Nokogiri::XML::Text:0x253ab44 "\n ">]>, #<Nokogiri::XML::Text:0x253aa6c "\n">]>]>> 

Wie Parsen Sie dies in eine Hasmap oder in eine Zeichenkette?

Bitte helfen Sie mir, wie ich neu auf Schienen bin.

+0

in XML zu sehen ... http://stackoverflow.com/questions/10122342/how-to-convert-nokogiri-object-to- xml-file-in-rails/10122666 # 10122666 – davidb

+0

Was willst du in der hashmap/string? – Phrogz

Antwort

0
  1. umrechnen Profil 2.manipulate mit nokogiri
2
  1. Holen Sie sich das Nokogiri XML-Dokument

    xml = @profile.instance_variable_get :@doc 
    
  2. umrechnen Nokogiri XML-Dokument an einen Hash:
    https://stackoverflow.com/a/10144623/405017

Wenn Sie eine andere Form möchten Sie Hash, dann Sie sollten Ihre gewünschte Ausgabe in der Frage angegeben haben. : p Es gibt sehr viele Möglichkeiten, ein XML-Dokument als Hash darzustellen.