bibsync 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 656b20418877066a48f7e30f3f702b47e71c7a5d
4
+ data.tar.gz: af9f5d4f088255dccc86bd12655a009830050ac3
5
+ SHA512:
6
+ metadata.gz: 55e6153fa4ffa968cbf1f08dba256c2a0c3b427f6a84babc16d99e62bb519e2450335191dd6ce0c4bc8eac1a830d1ba27999215a517b35feb24f4eda2ed92cd5
7
+ data.tar.gz: 4f9a2308012649be07f5bf3c8549c1a9ae9a1c0410e8c1f33de47e7991dcd1f067e83ea3e96a5c67e518a7b67980ad358bfa24f641a9f6f12740bff76da35449
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = %w(lib)
19
19
 
20
20
  s.add_runtime_dependency('nokogiri')
21
+ s.add_runtime_dependency('faraday')
22
+ s.add_runtime_dependency('faraday_middleware')
21
23
  s.add_development_dependency('rake')
22
24
  s.add_development_dependency('minitest')
23
25
  end
@@ -1,4 +1,6 @@
1
1
  require 'nokogiri'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
2
4
  require 'shellwords'
3
5
  require 'date'
4
6
  require 'pathname'
@@ -16,7 +16,7 @@ module BibSync
16
16
  notice 'Check for newer version on arXiv'
17
17
  @bib.select {|e| e[:arxiv] }.each_slice(SliceSize) do |entry|
18
18
  begin
19
- xml = fetch_xml("http://export.arxiv.org/api/query?id_list=#{entry.map{|e| arxiv_id(e, version: false, prefix: true) }.join(',')}&max_results=#{SliceSize}")
19
+ xml = fetch_xml('http://export.arxiv.org/api/query', id_list: entry.map{|e| arxiv_id(e, version: false, prefix: true) }.join(','), max_results: SliceSize)
20
20
  xml.xpath('//entry/id').map(&:content).each_with_index do |id, i|
21
21
  id.gsub!('http://arxiv.org/abs/', '')
22
22
  if id != entry[i][:arxiv]
@@ -48,7 +48,7 @@ module BibSync
48
48
  if !entry[:arxiv] && entry[:doi]
49
49
  begin
50
50
  info('Fetch missing arXiv identifier', key: entry)
51
- xml = fetch_xml("http://export.arxiv.org/api/query?search_query=doi:#{entry[:doi]}&max_results=1")
51
+ xml = fetch_xml('http://export.arxiv.org/api/query', search_query: "doi:#{entry[:doi]}", max_results: 1)
52
52
  if xml.xpath('//entry/doi').map(&:content).first == entry[:doi]
53
53
  id = xml.xpath('//entry/id').map(&:content).first
54
54
  if id =~ %r{\Ahttp://arxiv.org/abs/(.+)\Z}
@@ -37,7 +37,7 @@ module BibSync
37
37
  notice 'Downloading from arXiv'
38
38
  arxivs.each_slice(SliceSize) do |ids|
39
39
  begin
40
- xml = fetch_xml("http://export.arxiv.org/api/query?id_list=#{ids.join(',')}&max_results=#{SliceSize}")
40
+ xml = fetch_xml('http://export.arxiv.org/api/query', id_list: ids.join(','), max_results: SliceSize)
41
41
  xml.xpath('//entry/id').map(&:content).each_with_index do |id, i|
42
42
  id.gsub!('http://arxiv.org/abs/', '')
43
43
  info 'arXiv download', key: id
@@ -12,7 +12,7 @@ module BibSync
12
12
  def run
13
13
  notice 'Synchronize with arXiv and DOI'
14
14
 
15
- @bib.each do |entry|
15
+ @bib.to_a.each do |entry|
16
16
  next if entry.comment?
17
17
 
18
18
  if @force || !(entry[:title] && entry[:author] && entry[:year])
@@ -27,7 +27,7 @@ module BibSync
27
27
  update_doi(entry) if entry[:doi]
28
28
  end
29
29
 
30
- if @force || (!entry[:abstract] && entry[:doi] =~ /\A10\.1103\//)
30
+ if entry[:doi] =~ /\A10\.1103\// && (@force || !entry[:abstract])
31
31
  update_aps_abstract(entry)
32
32
  end
33
33
 
@@ -47,7 +47,7 @@ module BibSync
47
47
 
48
48
  def update_doi(entry)
49
49
  info('Downloading DOI metadata', key: entry)
50
- text = fetch("http://dx.doi.org/#{entry[:doi]}", 'Accept' => 'text/bibliography; style=bibtex')
50
+ text = fetch("http://dx.doi.org/#{entry[:doi]}", nil, 'Accept' => 'text/bibliography; style=bibtex')
51
51
  raise text if text == 'Unknown DOI'
52
52
  Entry.parse(text).each {|k, v| entry[k] = v }
53
53
  rescue => ex
@@ -96,7 +96,7 @@ module BibSync
96
96
 
97
97
  def update_arxiv(entry)
98
98
  info('Downloading arXiv metadata', key: entry)
99
- xml = fetch_xml("http://export.arxiv.org/oai2?verb=GetRecord&identifier=oai:arXiv.org:#{arxiv_id(entry, prefix: true, version: false)}&metadataPrefix=arXiv")
99
+ xml = fetch_xml('http://export.arxiv.org/oai2', verb: 'GetRecord', identifier: "oai:arXiv.org:#{arxiv_id(entry, prefix: true, version: false)}", metadataPrefix: 'arXiv')
100
100
  error = xml.xpath('//error').map(&:content).first
101
101
  raise error if error
102
102
 
@@ -5,29 +5,35 @@ module BibSync
5
5
  $1
6
6
  end
7
7
 
8
- def fetch(url, headers = {})
9
- # open(url, headers) {|f| f.read }
10
- headers = headers.map {|k,v| '-H ' + Shellwords.escape("#{k}: #{v}") }.join(' ')
11
- result = `curl --stderr - -S -s -L #{headers} #{Shellwords.escape url}`
12
- raise result.chomp if $? != 0
13
- result
8
+ def fetch(url, params = nil, headers = nil)
9
+ client = Faraday.new(url) do |c|
10
+ c.use FaradayMiddleware::FollowRedirects, limit: 3
11
+ c.use Faraday::Response::RaiseError
12
+ c.use Faraday::Adapter::NetHttp
13
+ end
14
+ response = client.get(url, params, headers)
15
+ raise "HTTP error #{response.status}" unless response.status == 200
16
+ body = response.body
17
+ encoding = body.encoding
18
+ body.force_encoding(Encoding::UTF_8)
19
+ body.force_encoding(encoding) unless body.valid_encoding?
20
+ body
14
21
  end
15
22
 
16
23
  def arxiv_download(dir, id)
17
- url = "http://arxiv.org/pdf/#{id}"
18
- file = File.join(dir, "#{arxiv_id(id, version: true, prefix: false)}.pdf")
19
- result = `curl --stderr - -S -s -L -o #{Shellwords.escape file} #{Shellwords.escape url}`
20
- raise result.chomp if $? != 0
24
+ File.open(File.join(dir, "#{arxiv_id(id, version: true, prefix: false)}.pdf"), 'wb') do |o|
25
+ o.write(fetch("http://arxiv.org/pdf/#{id}"))
26
+ end
21
27
  end
22
28
 
23
- def fetch_xml(url, headers = {})
24
- xml = Nokogiri::XML(fetch(url, headers))
29
+ def fetch_xml(url, params = nil, headers = nil)
30
+ xml = Nokogiri::XML(fetch(url, params, headers))
25
31
  xml.remove_namespaces!
26
32
  xml
27
33
  end
28
34
 
29
- def fetch_html(url, headers = {})
30
- Nokogiri::HTML(fetch(url, headers))
35
+ def fetch_html(url, params = nil, headers = nil)
36
+ Nokogiri::HTML(fetch(url, params, headers))
31
37
  end
32
38
 
33
39
  def arxiv_id(arxiv, opts = {})
@@ -1,3 +1,3 @@
1
1
  module BibSync
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -15,7 +15,7 @@ describe BibSync::Utils do
15
15
  end
16
16
 
17
17
  it 'fetches page with header' do
18
- fetch('http://dx.doi.org/10.1098/rspa.1984.0023', 'Accept' => 'text/bibliography; style=bibtex').include?('Berry').must_equal true
18
+ fetch('http://dx.doi.org/10.1098/rspa.1984.0023', nil, 'Accept' => 'text/bibliography; style=bibtex').include?('Berry').must_equal true
19
19
  end
20
20
  end
21
21
 
@@ -24,7 +24,7 @@ describe BibSync::Utils do
24
24
 
25
25
  describe '#fetch_xml' do
26
26
  it 'fetches xml' do
27
- fetch_xml('http://export.arxiv.org/oai2?verb=GetRecord&identifier=oai:arXiv.org:1208.2881&metadataPrefix=arXiv').must_be_instance_of Nokogiri::XML::Document
27
+ fetch_xml('http://export.arxiv.org/oai2', verb: 'GetRecord', identifier: 'oai:arXiv.org:1208.2881', metadataPrefix: 'arXiv').must_be_instance_of Nokogiri::XML::Document
28
28
  end
29
29
  end
30
30
 
metadata CHANGED
@@ -1,62 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel Mendler
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-09 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
28
53
  - !ruby/object:Gem::Version
29
54
  version: '0'
30
55
  - !ruby/object:Gem::Dependency
31
56
  name: rake
32
57
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
58
  requirements:
35
- - - ! '>='
59
+ - - '>='
36
60
  - !ruby/object:Gem::Version
37
61
  version: '0'
38
62
  type: :development
39
63
  prerelease: false
40
64
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
65
  requirements:
43
- - - ! '>='
66
+ - - '>='
44
67
  - !ruby/object:Gem::Version
45
68
  version: '0'
46
69
  - !ruby/object:Gem::Dependency
47
70
  name: minitest
48
71
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
72
  requirements:
51
- - - ! '>='
73
+ - - '>='
52
74
  - !ruby/object:Gem::Version
53
75
  version: '0'
54
76
  type: :development
55
77
  prerelease: false
56
78
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
79
  requirements:
59
- - - ! '>='
80
+ - - '>='
60
81
  - !ruby/object:Gem::Version
61
82
  version: '0'
62
83
  description: BibSync is a tool to synchronize scientific papers and BibTeX bibliography
@@ -115,27 +136,26 @@ files:
115
136
  - test/test_utils.rb
116
137
  homepage: https://github.com/minad/bibsync
117
138
  licenses: []
139
+ metadata: {}
118
140
  post_install_message:
119
141
  rdoc_options: []
120
142
  require_paths:
121
143
  - lib
122
144
  required_ruby_version: !ruby/object:Gem::Requirement
123
- none: false
124
145
  requirements:
125
- - - ! '>='
146
+ - - '>='
126
147
  - !ruby/object:Gem::Version
127
148
  version: '0'
128
149
  required_rubygems_version: !ruby/object:Gem::Requirement
129
- none: false
130
150
  requirements:
131
- - - ! '>='
151
+ - - '>='
132
152
  - !ruby/object:Gem::Version
133
153
  version: '0'
134
154
  requirements: []
135
155
  rubyforge_project: bibsync
136
- rubygems_version: 1.8.24
156
+ rubygems_version: 2.0.0
137
157
  signing_key:
138
- specification_version: 3
158
+ specification_version: 4
139
159
  summary: BibSync is a tool to synchronize scientific papers and BibTeX bibliography
140
160
  files
141
161
  test_files: []