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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8024a11ef6429ca95c92e25f64702723e4ef490
4
- data.tar.gz: aefa68138e1a5f9bd4b764628c51577f2d82e887
3
+ metadata.gz: 67327f1838111f1bed4ca3182d8cc835ea4e90a1
4
+ data.tar.gz: f8d7f4f997ea1e8e75dcf218722e75bccc05943c
5
5
  SHA512:
6
- metadata.gz: fe5bc76004bc8dca7530f87ac9b2c719c14bf45e81b9285da6e6f08c2b894c2e24e6baf8a5242a46611ec6e359c16c9be87088420e4da24077dc0e6dce04dca4
7
- data.tar.gz: 951a31d710ac2e3a69c10b37bb4e07a456e5bf6a77e5607f06f5eb46ccaf7bbaaf13612d34d5169119cebcd60dfde8cf036448311e0228bb92b203c4809c9730
6
+ metadata.gz: 233353d769eb80065b44c2e18f109431d471f84b93daf5257f3de460a6d21f0deb581764cfc949c7431f89ec6e6db77b75a8d8f988ace6f8f1d26305a591f0f4
7
+ data.tar.gz: 95cbac02fbe073e72b0ec9a2f6b8cd1874279492f83842c8ae1e166e9d000018f63fe02749be704fce9b3ab0a6c9455dbf31254bc1f79a9ef5a202ac7d5f4845
@@ -24,4 +24,4 @@ Style/SymbolArray:
24
24
  Enabled: false
25
25
 
26
26
  Metrics/ClassLength:
27
- Max: 120
27
+ Max: 125
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wikipedia-client (1.7.1)
4
+ wikipedia-client (1.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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"]
@@ -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:Flower.png
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Wikipedia
2
- VERSION = '1.7.1'.freeze
2
+ VERSION = '1.8.0'.freeze
3
3
  end
@@ -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.7.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-10-06 00:00:00.000000000 Z
16
+ date: 2017-12-01 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake