Class: PdfExtract::Resolve::SimpleTextQuery
- Inherits:
-
Object
- Object
- PdfExtract::Resolve::SimpleTextQuery
- Defined in:
- lib/references/resolve.rb
Constant Summary collapse
nil
Class Method Summary collapse
Class Method Details
.create_session ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/references/resolve.rb', line 82 def self.create_session if @@cookie.nil? Net::HTTP.start "www.crossref.org" do |http| response = http.get "/SimpleTextQuery" @@cookie = response["Set-Cookie"] end end end |
.find(ref) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/references/resolve.rb', line 54 def self.find ref create_session post = Net::HTTP::Post.new "/SimpleTextQuery" post.add_field "Cookie", @@cookie post.add_field "Referer", "http://www.crossref.org/SimpleTextQuery" post.set_form_data({ "command" => "Submit", "freetext" => ref, #"emailField" => "[email protected]", "doiField" => "", #"username" => "", #"password" => "" }) response = Net::HTTP.start "www.crossref.org" do |http| http.request post end doc = Nokogiri::HTML response.body doi = doc.at_css "td.resultB > a" if doi.nil? {} else {:doi => doi.content.sub("doi:", "")} end end |