eonu / arx

A Ruby interface for querying academic papers on the arXiv search API.
https://arxiv.org/help/api
MIT License
31 stars 1 forks source link

Could I download pdf with arx? #81

Closed Freakwill closed 3 years ago

Freakwill commented 3 years ago

Could I download pdf with arx? Is there a user-friendly API to do it?

eonu commented 3 years ago

Hi!

There isn't really an inbuilt feature like this, but you can do it quite easily by:

  1. checking if the paper has a PDF field with .pdf?,
  2. using open-uri to download the paper from its .pdf_url.
require 'open-uri'
require 'arx'

paper = Arx('1809.09415')

if paper.pdf?
  File.open('paper.pdf', 'wb') do |f|
    f.write URI.open(paper.pdf_url).read
  end
end

I'll look into adding this feature directly into the API at some point though, thanks for the suggestion!

eonu commented 3 years ago

Implemented in #90, you can now use Arx::Paper#save(path) to save the PDF for a paper object.