wikipedia-client 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.textile +12 -0
- data/lib/wikipedia/client.rb +2 -1
- data/lib/wikipedia/page.rb +11 -2
- data/lib/wikipedia/version.rb +1 -1
- data/spec/lib/client_spec.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67327f1838111f1bed4ca3182d8cc835ea4e90a1
|
4
|
+
data.tar.gz: f8d7f4f997ea1e8e75dcf218722e75bccc05943c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 233353d769eb80065b44c2e18f109431d471f84b93daf5257f3de460a6d21f0deb581764cfc949c7431f89ec6e6db77b75a8d8f988ace6f8f1d26305a591f0f4
|
7
|
+
data.tar.gz: 95cbac02fbe073e72b0ec9a2f6b8cd1874279492f83842c8ae1e166e9d000018f63fe02749be704fce9b3ab0a6c9455dbf31254bc1f79a9ef5a202ac7d5f4845
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.textile
CHANGED
@@ -60,6 +60,18 @@ page.image_urls
|
|
60
60
|
|
61
61
|
=> ["http://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"]
|
62
62
|
|
63
|
+
default width: 200
|
64
|
+
|
65
|
+
page.image_thumburls
|
66
|
+
|
67
|
+
=> ["https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/Getting_Things_Done.jpg/200px-Getting_Things_Done.jpg"]
|
68
|
+
|
69
|
+
or with custom width argument:
|
70
|
+
|
71
|
+
page.image_thumburls(100)
|
72
|
+
|
73
|
+
=> ["https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/Getting_Things_Done.jpg/100px-Getting_Things_Done.jpg"]
|
74
|
+
|
63
75
|
page.image_descriptionurls
|
64
76
|
|
65
77
|
=> ["http://en.wikipedia.org/wiki/File:Getting_Things_Done.jpg"]
|
data/lib/wikipedia/client.rb
CHANGED
@@ -42,12 +42,13 @@ module Wikipedia
|
|
42
42
|
}.merge( options ) )
|
43
43
|
end
|
44
44
|
|
45
|
-
# http://en.wikipedia.org/w/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=File:
|
45
|
+
# http://en.wikipedia.org/w/api.php?action=query&format=json&prop=imageinfo&iiprop=url&iiurlwidth=200&titles=File:Albert%20Einstein%20Head.jpg
|
46
46
|
def request_image( title, options = {} )
|
47
47
|
request( {
|
48
48
|
action: 'query',
|
49
49
|
prop: 'imageinfo',
|
50
50
|
iiprop: 'url',
|
51
|
+
iiurlwidth: options && options[:iiurlwidth] ? options[:iiurlwidth] : 200,
|
51
52
|
titles: title
|
52
53
|
}.merge( options ) )
|
53
54
|
end
|
data/lib/wikipedia/page.rb
CHANGED
@@ -68,6 +68,10 @@ module Wikipedia
|
|
68
68
|
page['imageinfo'].first['url'] if page['imageinfo']
|
69
69
|
end
|
70
70
|
|
71
|
+
def image_thumburl
|
72
|
+
page['imageinfo'].first['thumburl'] if page['imageinfo']
|
73
|
+
end
|
74
|
+
|
71
75
|
def image_descriptionurl
|
72
76
|
page['imageinfo'].first['descriptionurl'] if page['imageinfo']
|
73
77
|
end
|
@@ -76,6 +80,11 @@ module Wikipedia
|
|
76
80
|
image_metadata.map(&:image_url) unless image_metadata.nil?
|
77
81
|
end
|
78
82
|
|
83
|
+
def image_thumburls( width = nil )
|
84
|
+
options = width.nil? ? {} : { iiurlwidth: width }
|
85
|
+
image_metadata( options ).map(&:image_thumburl) unless image_metadata( options ).nil?
|
86
|
+
end
|
87
|
+
|
79
88
|
def image_descriptionurls
|
80
89
|
image_metadata.map(&:image_descriptionurl) unless image_metadata.nil?
|
81
90
|
end
|
@@ -92,11 +101,11 @@ module Wikipedia
|
|
92
101
|
@data
|
93
102
|
end
|
94
103
|
|
95
|
-
def image_metadata
|
104
|
+
def image_metadata( options = {} )
|
96
105
|
unless @cached_image_metadata
|
97
106
|
return if images.nil?
|
98
107
|
filtered = images.select { |i| i =~ /:.+\.(jpg|jpeg|png|gif|svg)$/i && !i.include?('LinkFA-star') }
|
99
|
-
@cached_image_metadata = filtered.map { |title| Wikipedia.find_image(title) }
|
108
|
+
@cached_image_metadata = filtered.map { |title| Wikipedia.find_image(title, options) }
|
100
109
|
end
|
101
110
|
@cached_image_metadata || []
|
102
111
|
end
|
data/lib/wikipedia/version.rb
CHANGED
data/spec/lib/client_spec.rb
CHANGED
@@ -150,6 +150,38 @@ describe Wikipedia::Client, '.find page (Edsger_Dijkstra)' do
|
|
150
150
|
expect(@page.image_urls).to include('https://upload.wikimedia.org/wikipedia' + image)
|
151
151
|
end
|
152
152
|
end
|
153
|
+
|
154
|
+
it 'should collect the image thumbnail urls with default width' do
|
155
|
+
@client.follow_redirects = true
|
156
|
+
@page = @client.find('Edsger Dijkstra')
|
157
|
+
[
|
158
|
+
'/en/thumb/4/4a/Commons-logo.svg/200px-Commons-logo.svg.png',
|
159
|
+
'/en/thumb/4/48/Folder_Hexagonal_Icon.svg/200px-Folder_Hexagonal_Icon.svg.png',
|
160
|
+
'/commons/thumb/5/57/Dijkstra_Animation.gif/200px-Dijkstra_Animation.gif',
|
161
|
+
'/commons/thumb/c/c9/Edsger_Dijkstra_1994.jpg/200px-Edsger_Dijkstra_1994.jpg',
|
162
|
+
'/commons/thumb/d/d9/Edsger_Wybe_Dijkstra.jpg/200px-Edsger_Wybe_Dijkstra.jpg',
|
163
|
+
'/commons/thumb/0/00/Complex-adaptive-system.jpg/200px-Complex-adaptive-system.jpg',
|
164
|
+
'/en/thumb/4/4d/Centrum-wiskunde-informatica-logo.png/200px-Centrum-wiskunde-informatica-logo.png'
|
165
|
+
].each do |image|
|
166
|
+
expect(@page.image_thumburls).to include('https://upload.wikimedia.org/wikipedia' + image)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should collect the image thumbnail urls with specified width' do
|
171
|
+
@client.follow_redirects = true
|
172
|
+
@page = @client.find('Edsger Dijkstra')
|
173
|
+
[
|
174
|
+
'/en/thumb/4/4a/Commons-logo.svg/100px-Commons-logo.svg.png',
|
175
|
+
'/en/thumb/4/48/Folder_Hexagonal_Icon.svg/100px-Folder_Hexagonal_Icon.svg.png',
|
176
|
+
'/commons/thumb/5/57/Dijkstra_Animation.gif/100px-Dijkstra_Animation.gif',
|
177
|
+
'/commons/thumb/c/c9/Edsger_Dijkstra_1994.jpg/100px-Edsger_Dijkstra_1994.jpg',
|
178
|
+
'/commons/thumb/d/d9/Edsger_Wybe_Dijkstra.jpg/100px-Edsger_Wybe_Dijkstra.jpg',
|
179
|
+
'/commons/thumb/0/00/Complex-adaptive-system.jpg/100px-Complex-adaptive-system.jpg',
|
180
|
+
'/en/thumb/4/4d/Centrum-wiskunde-informatica-logo.png/100px-Centrum-wiskunde-informatica-logo.png'
|
181
|
+
].each do |image|
|
182
|
+
expect(@page.image_thumburls(100)).to include('https://upload.wikimedia.org/wikipedia' + image)
|
183
|
+
end
|
184
|
+
end
|
153
185
|
end
|
154
186
|
|
155
187
|
describe Wikipedia::Client, '.find page (Rails) at jp' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wikipedia-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril David
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2017-
|
16
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: rake
|