gscholar 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/gscholar.gemspec +2 -1
- data/lib/gscholar/utils/fetcher.rb +5 -0
- data/lib/gscholar/utils/text_plain_parser.rb +12 -0
- data/lib/gscholar/utils.rb +1 -0
- data/test/test_paper.rb +9 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b3e7afc6e9b27fae3181575aa7476d31aa6fd99
|
4
|
+
data.tar.gz: 8dd9aae6331535de9c6495cfb6155393598629c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfd9f8bc016098917df22c1436aba774f2770883eed14f329d9aa413af78cd4e8650fc994fe53eac76c315a4786cd36375acd48f1ee5fcded76c7a93838992a7
|
7
|
+
data.tar.gz: 7ff03988617a7b508e72895af066257fd5fb6f95d7919772819ea5942086805c2cf3b85a7f461c59de92a2c5c97b912ddd6a2c2f756cc8d2ab90f8f0c9316f89
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/gscholar.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "gscholar"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Zifei Tong"]
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/gscholar/utils.rb",
|
32
32
|
"lib/gscholar/utils/fetcher.rb",
|
33
33
|
"lib/gscholar/utils/lazy_proxy.rb",
|
34
|
+
"lib/gscholar/utils/text_plain_parser.rb",
|
34
35
|
"test/helper.rb",
|
35
36
|
"test/test_fetcher.rb",
|
36
37
|
"test/test_lazy_proxy.rb",
|
@@ -7,6 +7,9 @@ module GScholar
|
|
7
7
|
def initialize
|
8
8
|
@cache = {}
|
9
9
|
@agent = Mechanize.new
|
10
|
+
@agent.pluggable_parser['text/plain'] = TextPlainParser
|
11
|
+
# Without changing user-agent, google will not return utf-8 page
|
12
|
+
@agent.user_agent_alias = 'Mac Safari'
|
10
13
|
|
11
14
|
# hack to enable BibTeX download
|
12
15
|
scisig = @agent.get('http://scholar.google.com/scholar_settings').
|
@@ -16,6 +19,8 @@ module GScholar
|
|
16
19
|
|
17
20
|
def fetch(url)
|
18
21
|
@cache[url] ||= @agent.get(url)
|
22
|
+
p @cache[url].response.to_hash
|
23
|
+
@cache[url]
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module GScholar
|
2
|
+
module Utils
|
3
|
+
class TextPlainParser < Mechanize::File
|
4
|
+
def initialize uri = nil, response = nil, body = nil, code = nil
|
5
|
+
super uri, response, body, code
|
6
|
+
encoding = response['content-type'][/;(?:\s*,)?\s*charset\s*=\s*([^()<>@,;:\\\"\/\[\]?={}\s]+)/i, 1]
|
7
|
+
@body.force_encoding encoding if encoding && encoding != 'none'
|
8
|
+
@body.encode! 'UTF-8'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/gscholar/utils.rb
CHANGED
data/test/test_paper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'helper'
|
2
4
|
|
3
5
|
# Helmer, Scott, et al. Curious george: The ubc semantic robot vision system. Vol. 2. Technical Report AAAI-WS-08-XX, AAAI Technical Report Series, 2007.
|
4
6
|
PAPER_0 = '8322442812667615406'
|
5
7
|
# Maxwell, Bruce A., Brian M. Leighton, and Leah R. Perlmutter. "A Responsive Vision System to Support Human-Robot Interaction."
|
6
8
|
PAPER_1 = '778988983414467064'
|
9
|
+
# 何祚庥. "量子力学的建立与科技创新的评价体系——纪念普朗克创立量子论 100 周年." 昆明理工大学学报 (社会科学版) 1.1 (2001).
|
10
|
+
PAPER_UTF8 = '11787577865338439018'
|
7
11
|
|
8
12
|
class TestPaper < Test::Unit::TestCase
|
9
13
|
def setup
|
@@ -35,4 +39,9 @@ class TestPaper < Test::Unit::TestCase
|
|
35
39
|
c1 = @p1.citations
|
36
40
|
assert_equal(c1.size, 0)
|
37
41
|
end
|
42
|
+
|
43
|
+
should "successfully get paper information with utf-8 encoding" do
|
44
|
+
@p = GScholar::Paper.new PAPER_UTF8
|
45
|
+
assert_equal(@p.author.first, '何祚庥')
|
46
|
+
end
|
38
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gscholar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zifei Tong
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/gscholar/utils.rb
|
160
160
|
- lib/gscholar/utils/fetcher.rb
|
161
161
|
- lib/gscholar/utils/lazy_proxy.rb
|
162
|
+
- lib/gscholar/utils/text_plain_parser.rb
|
162
163
|
- test/helper.rb
|
163
164
|
- test/test_fetcher.rb
|
164
165
|
- test/test_lazy_proxy.rb
|