我爲我的一個項目使用了這個非常好的LinkedIn ruby gem(https://github.com/pengwynn/linkedin),並且陷入了一個非常痛苦的地步過去的一天。Ruby Linkedin Gem人用嵌套字段選擇器搜索
我正在做一個人的搜索和使用嵌套的字段選擇器的「人」資源。我的查詢看起來是這樣的:
@client.search(:fields => [ { :people => %w(id first-name api-standard-profile-request) } ], :keywords => 'some keywords')
和我得到一個錯誤的URI例外
bad URI(is not URI?): /people-search:({:people=>["id", "first-name", "api-standard-profile-request"]})
當然這不是URL應該是什麼樣的。它應該像
/people-search:(people:(id,first-name,api-standard-profile-request))
花費在github上一段時間,並通過代碼去後,我能理解如何通過創業板所產生的路徑。在search.rb文件:
def field_selector(fields)
result = ":("
fields = fields.to_a.map do |field|
if field.is_a?(Hash)
innerFields = []
field.each do |key, value|
innerFields << key.to_s.gsub("_","-") + field_selector(value)
end
innerFields.join(',')
else
field.to_s.gsub("_","-")
end
end
result += fields.join(',')
result += ")"
result
end
其中領域是我傳遞到搜索方法的陣列。
奇怪的部分是,當我在控制檯中運行這段代碼(field_selector方法)時,以我的字段數組作爲輸入,我得到期望的輸出!
我完全失去了爲什麼我得到的錯誤,並不知道如何去解決它。任何指針都會很棒!
謝謝!
我很好奇,你發現了怎麼辦公共搜索用這種寶石的例子嗎?我甚至不知道它做了公開搜索,你會介意給我一個鏈接到你發現的地方嗎?謝謝! – botbot 2012-06-14 00:31:13