wikipedia-client 1.14.0 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -24
- data/lib/wikipedia.rb +3 -11
- data/lib/wikipedia/client.rb +6 -5
- data/lib/wikipedia/configuration.rb +14 -7
- data/lib/wikipedia/version.rb +1 -1
- data/spec/lib/client_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af50d4fda3d70e5bd837bde17b2ca86ec4c653c92891a5088246772da4ca45b5
|
4
|
+
data.tar.gz: 6366ad0bf999ed51533fd49963b4fa6d36e7181d49fc9bab227407cc3f76300f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f6e70ee49591fb4fb1238cd35ede198ff14e6efd89ddfbc972e4c7b03ff3aeabc2770c80f7981af5ec30d820ffbd5ca4a4870da944686d612134d34dacde87
|
7
|
+
data.tar.gz: 701089ac1c06f95ea5b67afba9b7d6754c967d0d4411f7b95b3f8a8f456b9adabc4ab67036be5024c70a1d21022144a5e88d4693c76d719ab3ad4bff0cd01e9d
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# Wikipedia API
|
1
|
+
# Wikipedia API Client
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/wikipedia-client.svg)](https://badge.fury.io/rb/wikipedia-client)
|
4
4
|
[![Build Status](https://github.com/kenpratt/wikipedia-client/workflows/Test/badge.svg)](https://github.com/kenpratt/wikipedia-client/actions?query=workflow%3ATest)
|
5
5
|
|
6
|
-
|
7
6
|
Allows you to get wikipedia content through their API. This uses the
|
8
7
|
alpha API, not the deprecated query.php API type.
|
9
8
|
|
@@ -79,6 +78,8 @@ page.langlinks
|
|
79
78
|
|
80
79
|
## Configuration
|
81
80
|
|
81
|
+
### Global
|
82
|
+
|
82
83
|
This is by default configured like this:
|
83
84
|
|
84
85
|
```ruby
|
@@ -88,6 +89,21 @@ Wikipedia.configure {
|
|
88
89
|
}
|
89
90
|
```
|
90
91
|
|
92
|
+
### Local
|
93
|
+
|
94
|
+
If you need to query multiple wikis indiviual clients with individual configurations can be
|
95
|
+
used:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
config_en = Wikipedia::Configuration.new(domain: 'en.wikipedia.org')
|
99
|
+
config_de = Wikipedia::Configuration.new(domain: 'de.wikipedia.org')
|
100
|
+
|
101
|
+
client_en = Wikipedia::Client.new(config_en)
|
102
|
+
client_de = Wikipedia::Client.new(config_de)
|
103
|
+
client_en.find( 'Getting Things Done' )
|
104
|
+
client_de.find( 'Buch' )
|
105
|
+
```
|
106
|
+
|
91
107
|
## Advanced
|
92
108
|
|
93
109
|
See the API spec at <http://en.wikipedia.org/w/api.php>.
|
@@ -116,43 +132,47 @@ page.raw_data
|
|
116
132
|
git clone git@github.com:kenpratt/wikipedia-client.git
|
117
133
|
cd wikipedia-client
|
118
134
|
bundle install
|
119
|
-
bundle exec
|
135
|
+
bundle exec rspec
|
120
136
|
```
|
121
137
|
|
122
138
|
### Pushing a new release of the Gem
|
123
139
|
|
124
140
|
1. Edit `lib/wikipedia/version.rb`, changing `VERSION`.
|
125
141
|
2. Test that the current branch will work as a gem, by testing in an external directory:
|
126
|
-
|
127
|
-
|
128
|
-
```
|
129
|
-
source 'https://rubygems.org'
|
142
|
+
3. Make a test directory.
|
143
|
+
4. Add a `Gemfile` with:
|
130
144
|
|
131
|
-
|
132
|
-
|
145
|
+
```
|
146
|
+
source 'https://rubygems.org'
|
133
147
|
|
134
|
-
|
135
|
-
|
136
|
-
require 'wikipedia'
|
148
|
+
gem 'wikipedia-client', :path => '/path/to/local/wikipedia-client'
|
149
|
+
```
|
137
150
|
|
138
|
-
|
139
|
-
|
140
|
-
|
151
|
+
5. And a `test.rb` file with:
|
152
|
+
|
153
|
+
```
|
154
|
+
require 'wikipedia'
|
155
|
+
|
156
|
+
page = Wikipedia.find('Ruby')
|
157
|
+
puts page.title
|
158
|
+
```
|
159
|
+
|
160
|
+
6. And then run `bundle install && bundle exec ruby test.rb`
|
161
|
+
7. Build the gem: `bundle exec gem build wikipedia-client.gemspec`.
|
162
|
+
8. Commit the changes: `git commit -a -m 'Version bump to 1.4.0' && git tag v1.4.0 && git push && git push --tag`
|
163
|
+
9. Publish the result to RubyGems: `bundle exec gem push wikipedia-client-1.4.0.gem`.
|
164
|
+
10. Test the released gem in an external directory:
|
165
|
+
11. Make a test directory.
|
166
|
+
12. Add a `Gemfile` with:
|
141
167
|
|
142
|
-
4. And then run `bundle install && bundle exec ruby test.rb`
|
143
|
-
3. Build the gem: `bundle exec gem build wikipedia-client.gemspec`.
|
144
|
-
4. Commit the changes: `git commit -a -m 'Version bump to 1.4.0' && git tag v1.4.0 && git push && git push --tag`
|
145
|
-
5. Publish the result to RubyGems: `bundle exec gem push wikipedia-client-1.4.0.gem`.
|
146
|
-
6. Test the released gem in an external directory:
|
147
|
-
1. Make a test directory.
|
148
|
-
2. Add a `Gemfile` with:
|
149
168
|
```
|
150
169
|
source 'https://rubygems.org'
|
151
170
|
|
152
171
|
gem 'wikipedia-client'
|
153
172
|
```
|
154
173
|
|
155
|
-
|
174
|
+
13. And a `test.rb` file with:
|
175
|
+
|
156
176
|
```
|
157
177
|
require 'wikipedia'
|
158
178
|
|
@@ -160,7 +180,7 @@ bundle exec spec
|
|
160
180
|
puts page.title
|
161
181
|
```
|
162
182
|
|
163
|
-
|
183
|
+
14. And then run `bundle install && bundle exec ruby test.rb`
|
164
184
|
|
165
185
|
## Thanks!
|
166
186
|
|
data/lib/wikipedia.rb
CHANGED
@@ -24,7 +24,7 @@ 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
30
|
# rubocop:disable Style/MethodName
|
@@ -32,20 +32,12 @@ module Wikipedia
|
|
32
32
|
configure(&block)
|
33
33
|
end
|
34
34
|
|
35
|
-
configure do
|
36
|
-
protocol 'https'
|
37
|
-
domain 'en.wikipedia.org'
|
38
|
-
path 'w/api.php'
|
39
|
-
user_agent(
|
40
|
-
'wikipedia-client/1.7 (https://github.com/kenpratt/wikipedia-client)'
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
35
|
class << self
|
45
36
|
private
|
46
37
|
|
47
38
|
def client
|
48
|
-
@
|
39
|
+
@configuration ||= Wikipedia::Configuration.new
|
40
|
+
@client ||= Wikipedia::Client.new @configuration
|
49
41
|
end
|
50
42
|
end
|
51
43
|
end
|
data/lib/wikipedia/client.rb
CHANGED
@@ -11,7 +11,8 @@ module Wikipedia
|
|
11
11
|
|
12
12
|
attr_accessor :follow_redirects
|
13
13
|
|
14
|
-
def initialize
|
14
|
+
def initialize(configuration = Wikipedia::Configuration.new)
|
15
|
+
@configuration = configuration
|
15
16
|
self.follow_redirects = true
|
16
17
|
end
|
17
18
|
|
@@ -72,16 +73,16 @@ module Wikipedia
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def request( options )
|
75
|
-
URI.parse( url_for( options ) ).read( 'User-Agent' =>
|
76
|
+
URI.parse( url_for( options ) ).read( 'User-Agent' => @configuration[:user_agent] )
|
76
77
|
end
|
77
78
|
|
78
79
|
protected
|
79
80
|
|
80
81
|
def configuration_options
|
81
82
|
{
|
82
|
-
protocol:
|
83
|
-
domain:
|
84
|
-
path:
|
83
|
+
protocol: @configuration[:protocol],
|
84
|
+
domain: @configuration[:domain],
|
85
|
+
path: @configuration[:path]
|
85
86
|
}
|
86
87
|
end
|
87
88
|
|
@@ -1,8 +1,19 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
|
3
1
|
module Wikipedia
|
4
2
|
class Configuration
|
5
|
-
|
3
|
+
DEFAULT = {
|
4
|
+
protocol: 'https',
|
5
|
+
domain: 'en.wikipedia.org',
|
6
|
+
path: 'w/api.php',
|
7
|
+
user_agent: 'wikipedia-client/1.7 (https://github.com/kenpratt/wikipedia-client)'
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def initialize(configuration = DEFAULT)
|
11
|
+
DEFAULT.merge(configuration).each { |args| send(*args) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](directive)
|
15
|
+
send(directive)
|
16
|
+
end
|
6
17
|
|
7
18
|
def self.directives(*directives)
|
8
19
|
directives.each do |directive|
|
@@ -14,10 +25,6 @@ module Wikipedia
|
|
14
25
|
end
|
15
26
|
end
|
16
27
|
|
17
|
-
def self.[](directive)
|
18
|
-
instance.send(directive)
|
19
|
-
end
|
20
|
-
|
21
28
|
directives :protocol, :domain, :path, :user_agent
|
22
29
|
end
|
23
30
|
end
|
data/lib/wikipedia/version.rb
CHANGED
data/spec/lib/client_spec.rb
CHANGED
@@ -285,3 +285,21 @@ describe Wikipedia::Client, 'page.langlinks' do
|
|
285
285
|
)
|
286
286
|
end
|
287
287
|
end
|
288
|
+
|
289
|
+
describe Wikipedia::Client, 'multiple configs' do
|
290
|
+
before(:each) do
|
291
|
+
config_en = Wikipedia::Configuration.new(domain: 'en.wikipedia.org')
|
292
|
+
config_de = Wikipedia::Configuration.new(domain: 'de.wikipedia.org')
|
293
|
+
|
294
|
+
@client_en = Wikipedia::Client.new(config_en)
|
295
|
+
@client_de = Wikipedia::Client.new(config_de)
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'should return a page with the correct URL' do
|
299
|
+
@page_en = @client_en.find('Edsger_Dijkstra')
|
300
|
+
expect(@page_en.fullurl).to eq('https://en.wikipedia.org/wiki/Edsger_W._Dijkstra')
|
301
|
+
|
302
|
+
@page_de = @client_de.find('Edsger_Dijkstra')
|
303
|
+
expect(@page_de.fullurl).to eq('https://de.wikipedia.org/wiki/Edsger_W._Dijkstra')
|
304
|
+
end
|
305
|
+
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.15.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: 2021-
|
16
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: addressable
|