0

ユーザー情報の認証と保存に OmniAuth LinkedIn を使用しています。これは、YAML::dump(response.env['omniauth.auth'].extra.raw_info) を実行したときに表示される出力です。

私の質問: この応答を解析して、ユーザーの職歴 (リストされているいくつかの企業) とユーザーの教育を保存するにはどうすればよいですか?

--- !ruby/hash:OmniAuth::AuthHash
educations: !ruby/hash:OmniAuth::AuthHash
  _total: 1
  values:
  - !ruby/hash:OmniAuth::AuthHash
    degree: ! '"BS"'
    endDate: !ruby/hash:OmniAuth::AuthHash
      year: 2014
    fieldOfStudy: Information Technology
    id: 154175914
    schoolName: Florida State University
    startDate: !ruby/hash:OmniAuth::AuthHash
      year: 2012
emailAddress: mci12@my.fsu.edu
firstName: Michael
headline: Co founder/CTO at Prept.co
id: 9rFcoUgX7u
industry: Information Technology and Services
lastName: Iglesias
location: !ruby/hash:OmniAuth::AuthHash
  country: !ruby/hash:OmniAuth::AuthHash
    code: us
  name: Miami/Fort Lauderdale Area
pictureUrl: http://m.c.lnkd.licdn.com/mpr/mprx/0_eyd5KS_5QNRWff1-HxoVKfQQX-yWSdi-EgjVKaLVRAeMtSqtXsJWOmlqospnaaGOWxIUxWULYrkb
positions: !ruby/hash:OmniAuth::AuthHash
  _total: 4
  values:
  - !ruby/hash:OmniAuth::AuthHash
    company: !ruby/hash:OmniAuth::AuthHash
      industry: Information Technology and Services
      name: InterviewChamp.co
    id: 409892806
    isCurrent: true
    startDate: !ruby/hash:OmniAuth::AuthHash
      month: 4
      year: 2013
    summary: Online marketplace where job seekers can connect with industry professionals
  in their desired fields for online video conferencing practice interviews. Job
  seekers are able to practice case, behavioral, and technical interviews to help
  them prepare and excel at real interviews.
    title: Founder/CTO
  - !ruby/hash:OmniAuth::AuthHash
    company: !ruby/hash:OmniAuth::AuthHash
      industry: Information Technology and Services
      name: Open Momento Web Development
    id: 385398346
    isCurrent: true
    startDate: !ruby/hash:OmniAuth::AuthHash
      month: 5
      year: 2012
    title: Software Engineer
  - !ruby/hash:OmniAuth::AuthHash
     company: !ruby/hash:OmniAuth::AuthHash
      industry: Information Technology and Services
      name: LetUsDorm.com
    id: 385404241
    isCurrent: true
    startDate: !ruby/hash:OmniAuth::AuthHash
      month: 1
      year: 2012
    title: Founder/CEO
  - !ruby/hash:OmniAuth::AuthHash
    company: !ruby/hash:OmniAuth::AuthHash
      id: 2780
       industry: Information Technology and Services
      name: Amadeus
      size: 10,001+ employees
      type: Public Company
    endDate: !ruby/hash:OmniAuth::AuthHash
      month: 5
      year: 2012
    id: 385401346
    isCurrent: false
    startDate: !ruby/hash:OmniAuth::AuthHash
      month: 5
      year: 2011
    title: IT Intern
publicProfileUrl: http://www.linkedin.com/in/iglesiasm

これは、シナトラに基づいた app.rb ファイルにあるものです...

%w(get post).each do |method|
    send(method, "/auth/:provider/callback") do

        response =  (request.env['omniauth.auth']).extra.raw_info
        "<pre>" + YAML::dump(response) + "</pre>" + "<br /><br />" 
    end
end
4

1 に答える 1

0

次のようなことを試してみます。

res = YAML::parse(response)

次に、次のようなことができます。

puts res.inspect # show the nested bits via  stdout
                 # or through some other logging

ominauth がないと確実にテストできませんが、そのように要素にアクセスできるようです。

res["lastname"] # -> Iglesias
res["educations]["id"] # -> 154175914
res["location"]["country"]...

sinatraを回避するための解決策を試してみてください。おそらくrackshです。モジュラー Sinatra アプリケーションで irb にアクセスする

于 2013-07-10T12:27:31.977 に答える