wikipedia-client 1.15.0 → 1.17.0
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/.github/workflows/test.yml +2 -2
- data/.rubocop.yml +57 -2
- data/Gemfile +1 -2
- data/README.md +23 -0
- data/lib/wikipedia/client.rb +7 -1
- data/lib/wikipedia/configuration.rb +3 -2
- data/lib/wikipedia/url.rb +6 -1
- data/lib/wikipedia/version.rb +1 -1
- data/lib/wikipedia-client.rb +2 -0
- data/lib/wikipedia.rb +7 -4
- data/spec/lib/client_spec.rb +1 -5
- data/spec/lib/url_spec.rb +7 -0
- data/spec/lib/wikipedia_spec.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36017e939b6473fd18fa5f2fd9703518d65308da4c945a1fc5684a22c341dc27
|
4
|
+
data.tar.gz: 6d0b8ae5850085c7fdebb24a7e6f1906c4df5b2c03ca29566aa010cc0d5bec73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 478d443be7e1f2ed909ef247f6ea5dd20ae9b5b06ae2d0205094df8d6ea97849d7cb222aefcd8bfc77eb294106007f24c290217a3530a6629f4a4bbad84c6e6a
|
7
|
+
data.tar.gz: c88caabd2ee0b32936211e5c3cc1ce006cb4afa687b5671511df56430e5081b9717f34711e501e9c9e4732028de382f34d7091bda8ddac087c7fbe7cdcee555d
|
data/.github/workflows/test.yml
CHANGED
@@ -8,11 +8,11 @@ jobs:
|
|
8
8
|
name: Ruby ${{ matrix.ruby }}
|
9
9
|
runs-on: ubuntu-latest
|
10
10
|
strategy:
|
11
|
-
matrix: { ruby: ['2.5', '2.6', '2.7', '3.0'] }
|
11
|
+
matrix: { ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2'] }
|
12
12
|
|
13
13
|
steps:
|
14
14
|
- name: Checkout code
|
15
|
-
uses: actions/checkout@
|
15
|
+
uses: actions/checkout@v3
|
16
16
|
|
17
17
|
- name: Setup Ruby
|
18
18
|
uses: ruby/setup-ruby@v1
|
data/.rubocop.yml
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: disable
|
3
|
+
|
1
4
|
Metrics/LineLength:
|
2
5
|
Max: 120
|
3
6
|
AllowURI: true
|
@@ -5,13 +8,13 @@ Metrics/LineLength:
|
|
5
8
|
Metrics/MethodLength:
|
6
9
|
Max: 15
|
7
10
|
|
8
|
-
|
11
|
+
Layout/SpaceInsideParens:
|
9
12
|
Enabled: false
|
10
13
|
|
11
14
|
Style/RescueModifier:
|
12
15
|
Enabled: false
|
13
16
|
|
14
|
-
|
17
|
+
Layout/SpaceInsidePercentLiteralDelimiters:
|
15
18
|
Enabled: false
|
16
19
|
|
17
20
|
Style/RegexpLiteral:
|
@@ -25,3 +28,55 @@ Style/SymbolArray:
|
|
25
28
|
|
26
29
|
Metrics/ClassLength:
|
27
30
|
Max: 130
|
31
|
+
|
32
|
+
# TODO: Remove each of the rules below once fixed.
|
33
|
+
Style/FrozenStringLiteralComment:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/StringConcatenation:
|
37
|
+
Enabled: false
|
38
|
+
|
39
|
+
Metrics/BlockLength:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/ExpandPathArguments:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Lint/MissingCopEnableDirective:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/FormatStringToken:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Style/RedundantRegexpEscape:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Naming/MethodParameterName:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/RedundantAssignment:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/SafeNavigation:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/WhileUntilModifier:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Layout/HashAlignment:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Layout/EmptyLineAfterGuardClause:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Layout/LeadingEmptyLines:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Gemspec/RequiredRubyVersion:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Style/Encoding:
|
79
|
+
Enabled: false
|
80
|
+
|
81
|
+
Lint/NonDeterministicRequireOrder:
|
82
|
+
Enabled: false
|
data/Gemfile
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'jeweler'
|
4
3
|
gem 'pry'
|
5
4
|
gem 'rake'
|
6
5
|
gem 'rdoc'
|
7
6
|
gem 'rspec'
|
8
7
|
# FIXME: Remove rubocop version restriction and fix or disable cops
|
9
|
-
gem 'rubocop', '
|
8
|
+
gem 'rubocop', '~> 1.22', require: false
|
10
9
|
gem 'thoughtbot-shoulda'
|
11
10
|
|
12
11
|
gemspec
|
data/README.md
CHANGED
@@ -124,6 +124,29 @@ page.raw_data
|
|
124
124
|
"lastrevid"=>348481810, "counter"=>0, "length"=>7891}}}}
|
125
125
|
```
|
126
126
|
|
127
|
+
### Additional HTTP headers
|
128
|
+
|
129
|
+
Some API features require tweaking HTTP headers. You can add additional headers via configuration.
|
130
|
+
|
131
|
+
For example, to retrieve the same page in different language variants:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
Wikipedia.configure do
|
135
|
+
domain 'zh.wikipedia.org'
|
136
|
+
headers({ 'Accept-Language' => 'zh-tw' })
|
137
|
+
end
|
138
|
+
|
139
|
+
Wikipedia.find('牛肉').summary #=> "牛肉是指從牛身上得出的肉,為常見的肉品之一。肌肉部分可以切成牛排、牛肉塊或牛仔骨,也可以與其他的肉混合做成香腸或血腸。"
|
140
|
+
|
141
|
+
Wikipedia.configure do
|
142
|
+
domain 'zh.wikipedia.org'
|
143
|
+
headers({ 'Accept-Language' => 'zh-cn' })
|
144
|
+
end
|
145
|
+
|
146
|
+
Wikipedia.find('牛肉').summary #=> "牛肉是指从牛身上得出的肉,为常见的肉品之一。肌肉部分可以切成牛排、牛肉块或牛仔骨,也可以与其他的肉混合做成香肠或血肠。"
|
147
|
+
```
|
148
|
+
|
149
|
+
|
127
150
|
## Contributing
|
128
151
|
|
129
152
|
### Getting the code, and running the tests
|
data/lib/wikipedia/client.rb
CHANGED
@@ -73,7 +73,7 @@ module Wikipedia
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def request( options )
|
76
|
-
URI.parse( url_for( options ) ).read(
|
76
|
+
URI.parse( url_for( options ) ).read( headers )
|
77
77
|
end
|
78
78
|
|
79
79
|
protected
|
@@ -114,5 +114,11 @@ module Wikipedia
|
|
114
114
|
end
|
115
115
|
[h1, h2]
|
116
116
|
end
|
117
|
+
|
118
|
+
def headers
|
119
|
+
{
|
120
|
+
'User-Agent' => @configuration[:user_agent]
|
121
|
+
}.merge( @configuration[:headers] )
|
122
|
+
end
|
117
123
|
end
|
118
124
|
end
|
@@ -4,7 +4,8 @@ module Wikipedia
|
|
4
4
|
protocol: 'https',
|
5
5
|
domain: 'en.wikipedia.org',
|
6
6
|
path: 'w/api.php',
|
7
|
-
user_agent: 'wikipedia-client/1.7 (https://github.com/kenpratt/wikipedia-client)'
|
7
|
+
user_agent: 'wikipedia-client/1.7 (https://github.com/kenpratt/wikipedia-client)',
|
8
|
+
headers: {}
|
8
9
|
}.freeze
|
9
10
|
|
10
11
|
def initialize(configuration = DEFAULT)
|
@@ -25,6 +26,6 @@ module Wikipedia
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
directives :protocol, :domain, :path, :user_agent
|
29
|
+
directives :protocol, :domain, :path, :user_agent, :headers
|
29
30
|
end
|
30
31
|
end
|
data/lib/wikipedia/url.rb
CHANGED
@@ -11,7 +11,12 @@ module Wikipedia
|
|
11
11
|
return @title if @title
|
12
12
|
|
13
13
|
uri = URI.parse( @wiki_url )
|
14
|
-
@title =
|
14
|
+
@title =
|
15
|
+
if uri.path.empty?
|
16
|
+
@wiki_url
|
17
|
+
else
|
18
|
+
Addressable::URI.unencode( uri.path.sub(/\/wiki\//, '') )
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/wikipedia/version.rb
CHANGED
data/lib/wikipedia.rb
CHANGED
@@ -24,10 +24,10 @@ module Wikipedia
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.configure(&block)
|
27
|
-
|
27
|
+
configuration.instance_eval(&block)
|
28
28
|
end
|
29
29
|
|
30
|
-
# rubocop:disable
|
30
|
+
# rubocop:disable Naming/MethodName
|
31
31
|
def self.Configure(&block)
|
32
32
|
configure(&block)
|
33
33
|
end
|
@@ -35,9 +35,12 @@ module Wikipedia
|
|
35
35
|
class << self
|
36
36
|
private
|
37
37
|
|
38
|
-
def
|
38
|
+
def configuration
|
39
39
|
@configuration ||= Wikipedia::Configuration.new
|
40
|
-
|
40
|
+
end
|
41
|
+
|
42
|
+
def client
|
43
|
+
@client ||= Wikipedia::Client.new configuration
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
data/spec/lib/client_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
# rubocop:disable Metrics/BlockLength
|
5
4
|
describe Wikipedia::Client, '.find page (mocked)' do
|
6
5
|
before(:each) do
|
7
6
|
@client = Wikipedia::Client.new
|
@@ -161,7 +160,6 @@ describe Wikipedia::Client, '.find page (Edsger_Dijkstra)' do
|
|
161
160
|
@client.follow_redirects = true
|
162
161
|
@page = @client.find('Edsger Dijkstra')
|
163
162
|
[
|
164
|
-
'/commons/5/57/Dijkstra_Animation.gif',
|
165
163
|
'/commons/c/c9/Edsger_Dijkstra_1994.jpg',
|
166
164
|
'/commons/d/d9/Edsger_Wybe_Dijkstra.jpg'
|
167
165
|
].each do |image|
|
@@ -173,7 +171,6 @@ describe Wikipedia::Client, '.find page (Edsger_Dijkstra)' do
|
|
173
171
|
@client.follow_redirects = true
|
174
172
|
@page = @client.find('Edsger Dijkstra')
|
175
173
|
[
|
176
|
-
'/commons/thumb/5/57/Dijkstra_Animation.gif/200px-Dijkstra_Animation.gif',
|
177
174
|
'/commons/thumb/c/c9/Edsger_Dijkstra_1994.jpg/200px-Edsger_Dijkstra_1994.jpg',
|
178
175
|
'/commons/thumb/d/d9/Edsger_Wybe_Dijkstra.jpg/200px-Edsger_Wybe_Dijkstra.jpg'
|
179
176
|
].each do |image|
|
@@ -185,7 +182,6 @@ describe Wikipedia::Client, '.find page (Edsger_Dijkstra)' do
|
|
185
182
|
@client.follow_redirects = true
|
186
183
|
@page = @client.find('Edsger Dijkstra')
|
187
184
|
[
|
188
|
-
'/commons/thumb/5/57/Dijkstra_Animation.gif/100px-Dijkstra_Animation.gif',
|
189
185
|
'/commons/thumb/c/c9/Edsger_Dijkstra_1994.jpg/100px-Edsger_Dijkstra_1994.jpg',
|
190
186
|
'/commons/thumb/d/d9/Edsger_Wybe_Dijkstra.jpg/100px-Edsger_Wybe_Dijkstra.jpg'
|
191
187
|
].each do |image|
|
@@ -196,7 +192,7 @@ describe Wikipedia::Client, '.find page (Edsger_Dijkstra)' do
|
|
196
192
|
it 'should collect the main image thumburl' do
|
197
193
|
@client.follow_redirects = true
|
198
194
|
@page = @client.find('Edsger Dijkstra')
|
199
|
-
image = '/commons/thumb/d/d9/Edsger_Wybe_Dijkstra.jpg/
|
195
|
+
image = '/commons/thumb/d/d9/Edsger_Wybe_Dijkstra.jpg/200px-Edsger_Wybe_Dijkstra.jpg'
|
200
196
|
expect(@page.main_image_thumburl).to include('https://upload.wikimedia.org/wikipedia' + image)
|
201
197
|
end
|
202
198
|
end
|
data/spec/lib/url_spec.rb
CHANGED
@@ -6,3 +6,10 @@ describe Wikipedia::Url, 'like http://en.wikipedia.org/wiki/Getting_Things_Done'
|
|
6
6
|
expect(url.title).to eq('Getting_Things_Done')
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
describe Wikipedia::Url, 'like "? (Lost)"' do
|
11
|
+
it 'should return input as title' do
|
12
|
+
url = Wikipedia::Url.new('? (Lost)')
|
13
|
+
expect(url.title).to eq('? (Lost)')
|
14
|
+
end
|
15
|
+
end
|
data/spec/lib/wikipedia_spec.rb
CHANGED
@@ -18,3 +18,15 @@ describe Wikipedia, '.find' do
|
|
18
18
|
expect(page1.title).to eq(page2.title)
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe Wikipedia, '.configure' do
|
23
|
+
it 'should set configuration' do
|
24
|
+
Wikipedia.configure do
|
25
|
+
protocol 'https'
|
26
|
+
domain 'zh.wikipedia.org'
|
27
|
+
end
|
28
|
+
|
29
|
+
page = Wikipedia.find('Getting_Things_Done')
|
30
|
+
expect(page.fullurl).to start_with('https://zh.wikipedia.org')
|
31
|
+
end
|
32
|
+
end
|
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.17.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:
|
16
|
+
date: 2023-02-22 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: addressable
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- Rakefile
|
47
47
|
- init.rb
|
48
48
|
- install.rb
|
49
|
+
- lib/wikipedia-client.rb
|
49
50
|
- lib/wikipedia.rb
|
50
51
|
- lib/wikipedia/client.rb
|
51
52
|
- lib/wikipedia/configuration.rb
|