wikipedia-client 1.12.0 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +27 -0
- data/.gitignore +1 -0
- data/Gemfile +10 -0
- data/README.md +214 -0
- data/lib/wikipedia/client.rb +36 -27
- data/lib/wikipedia/configuration.rb +16 -8
- data/lib/wikipedia/url.rb +9 -1
- data/lib/wikipedia/version.rb +1 -1
- data/lib/wikipedia-client.rb +2 -0
- data/lib/wikipedia.rb +6 -13
- data/spec/lib/client_spec.rb +18 -0
- data/spec/lib/url_spec.rb +7 -0
- data/spec/lib/wikipedia_spec.rb +12 -0
- data/wikipedia-client.gemspec +2 -21
- metadata +11 -101
- data/.travis.yml +0 -6
- data/Gemfile.lock +0 -109
- data/README.textile +0 -168
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bd75b9c5cb006f00a42ee85054e1cce3d61d942c6c2c8d55f01d46ce594ad0e
|
4
|
+
data.tar.gz: 594bdcb73afa6d02d3a6761bad0180df3b19896f1474bdfbcfed04382318afb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9dd0e851b81c6f59769eae01e7439c11efba75684c321eb26589b572ead963235b2b8a322169b7171908ef930a4fddcb61766e605acee5ae1d4fa3e08bea6d4
|
7
|
+
data.tar.gz: b54cd43b57dafc5409a3e4524623bebbc3c275c26c97c6aeed7ccb821a075025d3dd93f41e557155e219e7346b4138c72c012f1bd175c34b49679c0d8334a4ee
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Test
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
push: { branches: master }
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
name: Ruby ${{ matrix.ruby }}
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix: { ruby: ['2.5', '2.6', '2.7', '3.0'] }
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- name: Checkout code
|
15
|
+
uses: actions/checkout@v2
|
16
|
+
|
17
|
+
- name: Setup Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: '${{ matrix.ruby }}'
|
21
|
+
bundler-cache: true
|
22
|
+
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rspec
|
25
|
+
|
26
|
+
- name: Run rubocop
|
27
|
+
run: bundle exec rubocop
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
# Wikipedia API Client
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/wikipedia-client.svg)](https://badge.fury.io/rb/wikipedia-client)
|
4
|
+
[![Build Status](https://github.com/kenpratt/wikipedia-client/workflows/Test/badge.svg)](https://github.com/kenpratt/wikipedia-client/actions?query=workflow%3ATest)
|
5
|
+
|
6
|
+
Allows you to get wikipedia content through their API. This uses the
|
7
|
+
alpha API, not the deprecated query.php API type.
|
8
|
+
|
9
|
+
Wikipedia API reference: <http://en.wikipedia.org/w/api.php>
|
10
|
+
|
11
|
+
Adopted from: <http://code.google.com/p/wikipedia-client/>
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install wikipedia-client
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'wikipedia'
|
23
|
+
page = Wikipedia.find( 'Getting Things Done' )
|
24
|
+
#=> #<Wikipedia:Page>
|
25
|
+
|
26
|
+
page.title
|
27
|
+
#=> 'Getting Things Done'
|
28
|
+
|
29
|
+
page.fullurl
|
30
|
+
#=> 'http://en.wikipedia.org/wiki/Getting_Things_Done'
|
31
|
+
|
32
|
+
page.text
|
33
|
+
#=> 'Getting Things Done is a time-management method...'
|
34
|
+
|
35
|
+
page.content
|
36
|
+
#=> all the wiki markup appears here...
|
37
|
+
|
38
|
+
page.summary
|
39
|
+
#=> only the wiki summary appears here...
|
40
|
+
|
41
|
+
page.categories
|
42
|
+
#=> [..., "Category:Self-help books", ...]
|
43
|
+
|
44
|
+
page.links
|
45
|
+
#=> [..., "Business", "Cult following", ...]
|
46
|
+
|
47
|
+
page.extlinks
|
48
|
+
# => [..., "http://www.example.com/", ...]
|
49
|
+
|
50
|
+
page.images
|
51
|
+
#=> ["File:Getting Things Done.jpg", ...]
|
52
|
+
|
53
|
+
page.image_urls
|
54
|
+
#=> ["http://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"]
|
55
|
+
|
56
|
+
page.image_thumburls
|
57
|
+
#=> ["https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/Getting_Things_Done.jpg/200px-Getting_Things_Done.jpg"]
|
58
|
+
|
59
|
+
# or with custom width argument:
|
60
|
+
page.image_thumburls(100)
|
61
|
+
#=> ["https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/Getting_Things_Done.jpg/100px-Getting_Things_Done.jpg"]
|
62
|
+
|
63
|
+
page.image_descriptionurls
|
64
|
+
#=> ["http://en.wikipedia.org/wiki/File:Getting_Things_Done.jpg"]
|
65
|
+
|
66
|
+
page.main_image_url
|
67
|
+
#=> "https://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"
|
68
|
+
|
69
|
+
page.coordinates
|
70
|
+
#=> [48.853, 2.3498, "", "earth"]
|
71
|
+
|
72
|
+
page.templates
|
73
|
+
#=> [..., "Template:About", ...]
|
74
|
+
|
75
|
+
page.langlinks
|
76
|
+
#=> {..., "de"=>"Getting Things Done", "eo"=>"Igi aferojn finitaj", "zh"=>"尽管去做", ...}
|
77
|
+
```
|
78
|
+
|
79
|
+
## Configuration
|
80
|
+
|
81
|
+
### Global
|
82
|
+
|
83
|
+
This is by default configured like this:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
Wikipedia.configure {
|
87
|
+
domain 'en.wikipedia.org'
|
88
|
+
path 'w/api.php'
|
89
|
+
}
|
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
|
+
|
107
|
+
## Advanced
|
108
|
+
|
109
|
+
See the API spec at <http://en.wikipedia.org/w/api.php>.
|
110
|
+
|
111
|
+
If you need data that is not already present, you can override parameters.
|
112
|
+
|
113
|
+
For example, to retrieve only the page info:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
page = Wikipedia.find( 'Getting Things Done', :prop => "info" )
|
117
|
+
|
118
|
+
page.title
|
119
|
+
#=> "Getting Things Done"
|
120
|
+
|
121
|
+
page.raw_data
|
122
|
+
#=> {"query"=>{"pages"=>{"959928"=>{"pageid"=>959928, "ns"=>0,
|
123
|
+
"title"=>"Getting Things Done", "touched"=>"2010-03-10T00:04:09Z",
|
124
|
+
"lastrevid"=>348481810, "counter"=>0, "length"=>7891}}}}
|
125
|
+
```
|
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
|
+
|
150
|
+
## Contributing
|
151
|
+
|
152
|
+
### Getting the code, and running the tests
|
153
|
+
|
154
|
+
```
|
155
|
+
git clone git@github.com:kenpratt/wikipedia-client.git
|
156
|
+
cd wikipedia-client
|
157
|
+
bundle install
|
158
|
+
bundle exec rspec
|
159
|
+
```
|
160
|
+
|
161
|
+
### Pushing a new release of the Gem
|
162
|
+
|
163
|
+
1. Edit `lib/wikipedia/version.rb`, changing `VERSION`.
|
164
|
+
2. Test that the current branch will work as a gem, by testing in an external directory:
|
165
|
+
3. Make a test directory.
|
166
|
+
4. Add a `Gemfile` with:
|
167
|
+
|
168
|
+
```
|
169
|
+
source 'https://rubygems.org'
|
170
|
+
|
171
|
+
gem 'wikipedia-client', :path => '/path/to/local/wikipedia-client'
|
172
|
+
```
|
173
|
+
|
174
|
+
5. And a `test.rb` file with:
|
175
|
+
|
176
|
+
```
|
177
|
+
require 'wikipedia'
|
178
|
+
|
179
|
+
page = Wikipedia.find('Ruby')
|
180
|
+
puts page.title
|
181
|
+
```
|
182
|
+
|
183
|
+
6. And then run `bundle install && bundle exec ruby test.rb`
|
184
|
+
7. Build the gem: `bundle exec gem build wikipedia-client.gemspec`.
|
185
|
+
8. Commit the changes: `git commit -a -m 'Version bump to 1.4.0' && git tag v1.4.0 && git push && git push --tag`
|
186
|
+
9. Publish the result to RubyGems: `bundle exec gem push wikipedia-client-1.4.0.gem`.
|
187
|
+
10. Test the released gem in an external directory:
|
188
|
+
11. Make a test directory.
|
189
|
+
12. Add a `Gemfile` with:
|
190
|
+
|
191
|
+
```
|
192
|
+
source 'https://rubygems.org'
|
193
|
+
|
194
|
+
gem 'wikipedia-client'
|
195
|
+
```
|
196
|
+
|
197
|
+
13. And a `test.rb` file with:
|
198
|
+
|
199
|
+
```
|
200
|
+
require 'wikipedia'
|
201
|
+
|
202
|
+
page = Wikipedia.find('Ruby')
|
203
|
+
puts page.title
|
204
|
+
```
|
205
|
+
|
206
|
+
14. And then run `bundle install && bundle exec ruby test.rb`
|
207
|
+
|
208
|
+
## Thanks!
|
209
|
+
|
210
|
+
Copyright (c) 2008 Cyril David, released under the MIT license
|
211
|
+
|
212
|
+
Adopted by Ken Pratt (ken@kenpratt.net) in 2010/03
|
213
|
+
|
214
|
+
Thanks to all the [Contributors](https://github.com/kenpratt/wikipedia-client/graphs/contributors).
|
data/lib/wikipedia/client.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
+
require 'addressable'
|
2
|
+
require 'cgi'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'set'
|
5
|
+
|
1
6
|
module Wikipedia
|
2
7
|
class Client
|
3
8
|
# see http://en.wikipedia.org/w/api.php
|
4
|
-
|
9
|
+
BASE_URL_TEMPLATE = '%{protocol}://%{domain}/%{path}?action=%{action}&format=json'.freeze
|
10
|
+
BASE_URL_OPTIONS = Set.new([:protocol, :domain, :path, :action])
|
5
11
|
|
6
12
|
attr_accessor :follow_redirects
|
7
13
|
|
8
|
-
def initialize
|
14
|
+
def initialize(configuration = Wikipedia::Configuration.new)
|
15
|
+
@configuration = configuration
|
9
16
|
self.follow_redirects = true
|
10
17
|
end
|
11
18
|
|
@@ -66,50 +73,52 @@ module Wikipedia
|
|
66
73
|
end
|
67
74
|
|
68
75
|
def request( options )
|
69
|
-
|
70
|
-
URI.parse( url_for( options ) ).read( 'User-Agent' => Configuration[:user_agent] )
|
76
|
+
URI.parse( url_for( options ) ).read( headers )
|
71
77
|
end
|
72
78
|
|
73
79
|
protected
|
74
80
|
|
75
81
|
def configuration_options
|
76
82
|
{
|
77
|
-
protocol:
|
78
|
-
domain:
|
79
|
-
path:
|
83
|
+
protocol: @configuration[:protocol],
|
84
|
+
domain: @configuration[:domain],
|
85
|
+
path: @configuration[:path]
|
80
86
|
}
|
81
87
|
end
|
82
88
|
|
83
|
-
def url_for(
|
84
|
-
url = BASE_URL.dup
|
89
|
+
def url_for(options)
|
85
90
|
options = configuration_options.merge( options )
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
url
|
91
|
+
|
92
|
+
url_options, query_options = split_hash(options, BASE_URL_OPTIONS)
|
93
|
+
normalized_query_options = query_options.map { |k, v| [k, normalize_value(v)] }
|
94
|
+
|
95
|
+
base_url = BASE_URL_TEMPLATE % url_options
|
96
|
+
query_string = Addressable::URI.form_encode(normalized_query_options)
|
97
|
+
base_url + '&' + query_string
|
95
98
|
end
|
96
99
|
|
97
|
-
def
|
100
|
+
def normalize_value( val )
|
98
101
|
case val
|
99
102
|
when Array
|
100
|
-
|
103
|
+
val.flatten.join( '|' )
|
101
104
|
else
|
102
|
-
|
105
|
+
val
|
103
106
|
end
|
104
107
|
end
|
105
108
|
|
106
|
-
def
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
val
|
109
|
+
def split_hash(hash, keys)
|
110
|
+
h1 = {}
|
111
|
+
h2 = {}
|
112
|
+
hash.each do |k, v|
|
113
|
+
(keys.include?(k) ? h1 : h2).store(k, v)
|
112
114
|
end
|
115
|
+
[h1, h2]
|
116
|
+
end
|
117
|
+
|
118
|
+
def headers
|
119
|
+
{
|
120
|
+
'User-Agent' => @configuration[:user_agent]
|
121
|
+
}.merge( @configuration[:headers] )
|
113
122
|
end
|
114
123
|
end
|
115
124
|
end
|
@@ -1,8 +1,20 @@
|
|
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
|
+
headers: {}
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def initialize(configuration = DEFAULT)
|
12
|
+
DEFAULT.merge(configuration).each { |args| send(*args) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](directive)
|
16
|
+
send(directive)
|
17
|
+
end
|
6
18
|
|
7
19
|
def self.directives(*directives)
|
8
20
|
directives.each do |directive|
|
@@ -14,10 +26,6 @@ module Wikipedia
|
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
17
|
-
|
18
|
-
instance.send(directive)
|
19
|
-
end
|
20
|
-
|
21
|
-
directives :protocol, :domain, :path, :user_agent
|
29
|
+
directives :protocol, :domain, :path, :user_agent, :headers
|
22
30
|
end
|
23
31
|
end
|
data/lib/wikipedia/url.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'addressable'
|
3
|
+
|
1
4
|
module Wikipedia
|
2
5
|
class Url
|
3
6
|
def initialize(wiki_url)
|
@@ -8,7 +11,12 @@ module Wikipedia
|
|
8
11
|
return @title if @title
|
9
12
|
|
10
13
|
uri = URI.parse( @wiki_url )
|
11
|
-
@title =
|
14
|
+
@title =
|
15
|
+
if uri.path.empty?
|
16
|
+
@wiki_url
|
17
|
+
else
|
18
|
+
Addressable::URI.unencode( uri.path.sub(/\/wiki\//, '') )
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
14
22
|
end
|
data/lib/wikipedia/version.rb
CHANGED
data/lib/wikipedia.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
Dir[File.dirname(__FILE__) + '/wikipedia/**/*.rb'].each { |f| require f }
|
2
2
|
|
3
|
-
require 'uri'
|
4
|
-
|
5
3
|
module Wikipedia
|
6
4
|
# Examples :
|
7
5
|
# page = Wikipedia.find('Rails')
|
@@ -26,7 +24,7 @@ module Wikipedia
|
|
26
24
|
end
|
27
25
|
|
28
26
|
def self.configure(&block)
|
29
|
-
|
27
|
+
configuration.instance_eval(&block)
|
30
28
|
end
|
31
29
|
|
32
30
|
# rubocop:disable Style/MethodName
|
@@ -34,20 +32,15 @@ module Wikipedia
|
|
34
32
|
configure(&block)
|
35
33
|
end
|
36
34
|
|
37
|
-
configure do
|
38
|
-
protocol 'https'
|
39
|
-
domain 'en.wikipedia.org'
|
40
|
-
path 'w/api.php'
|
41
|
-
user_agent(
|
42
|
-
'wikipedia-client/1.7 (https://github.com/kenpratt/wikipedia-client)'
|
43
|
-
)
|
44
|
-
end
|
45
|
-
|
46
35
|
class << self
|
47
36
|
private
|
48
37
|
|
38
|
+
def configuration
|
39
|
+
@configuration ||= Wikipedia::Configuration.new
|
40
|
+
end
|
41
|
+
|
49
42
|
def client
|
50
|
-
@client ||= Wikipedia::Client.new
|
43
|
+
@client ||= Wikipedia::Client.new configuration
|
51
44
|
end
|
52
45
|
end
|
53
46
|
end
|
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
|
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
|
data/wikipedia-client.gemspec
CHANGED
@@ -4,7 +4,6 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
|
4
4
|
require 'wikipedia/version'
|
5
5
|
require 'date'
|
6
6
|
|
7
|
-
# rubocop:disable Metrics/BlockLength
|
8
7
|
Gem::Specification.new do |s|
|
9
8
|
s.name = 'wikipedia-client'
|
10
9
|
s.version = Wikipedia::VERSION
|
@@ -24,29 +23,11 @@ Gem::Specification.new do |s|
|
|
24
23
|
s.files = `git ls-files`.split("\n")
|
25
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
25
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
27
|
-
s.
|
28
|
-
s.extra_rdoc_files = ['README.textile']
|
26
|
+
s.extra_rdoc_files = ['README.md']
|
29
27
|
s.bindir = 'bin'
|
30
28
|
|
31
29
|
s.require_paths << 'lib'
|
32
30
|
s.rdoc_options << '--title' << 'wikipedia-client' << '--main' << '-ri'
|
33
31
|
|
34
|
-
s.
|
35
|
-
s.add_development_dependency('rake', '~> 13.0')
|
36
|
-
s.add_development_dependency('rspec', '~> 3.0')
|
37
|
-
s.add_development_dependency('rdoc', '~> 6.0')
|
38
|
-
s.add_development_dependency('jeweler', '~> 2.0')
|
39
|
-
s.add_development_dependency('rubocop', '~> 0.48')
|
40
|
-
|
41
|
-
if s.respond_to? :specification_version
|
42
|
-
s.specification_version = 3
|
43
|
-
|
44
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
|
45
|
-
s.add_development_dependency('thoughtbot-shoulda', '~> 2.11', ['>= 2.11'])
|
46
|
-
else
|
47
|
-
s.add_dependency('thoughtbot-shoulda', ['>= 0'])
|
48
|
-
end
|
49
|
-
else
|
50
|
-
s.add_dependency('thoughtbot-shoulda', ['>= 0'])
|
51
|
-
end
|
32
|
+
s.add_runtime_dependency 'addressable', '~> 2.7'
|
52
33
|
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.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril David
|
@@ -13,130 +13,40 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2021-
|
16
|
+
date: 2021-09-08 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
|
-
name:
|
19
|
+
name: addressable
|
20
20
|
requirement: !ruby/object:Gem::Requirement
|
21
21
|
requirements:
|
22
22
|
- - "~>"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '
|
25
|
-
type: :
|
24
|
+
version: '2.7'
|
25
|
+
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
28
28
|
requirements:
|
29
29
|
- - "~>"
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: '
|
32
|
-
- !ruby/object:Gem::Dependency
|
33
|
-
name: rake
|
34
|
-
requirement: !ruby/object:Gem::Requirement
|
35
|
-
requirements:
|
36
|
-
- - "~>"
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: '13.0'
|
39
|
-
type: :development
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
requirements:
|
43
|
-
- - "~>"
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '13.0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
requirements:
|
50
|
-
- - "~>"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '3.0'
|
53
|
-
type: :development
|
54
|
-
prerelease: false
|
55
|
-
version_requirements: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '3.0'
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: rdoc
|
62
|
-
requirement: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - "~>"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '6.0'
|
67
|
-
type: :development
|
68
|
-
prerelease: false
|
69
|
-
version_requirements: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '6.0'
|
74
|
-
- !ruby/object:Gem::Dependency
|
75
|
-
name: jeweler
|
76
|
-
requirement: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - "~>"
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '2.0'
|
81
|
-
type: :development
|
82
|
-
prerelease: false
|
83
|
-
version_requirements: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
85
|
-
- - "~>"
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '2.0'
|
88
|
-
- !ruby/object:Gem::Dependency
|
89
|
-
name: rubocop
|
90
|
-
requirement: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
92
|
-
- - "~>"
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '0.48'
|
95
|
-
type: :development
|
96
|
-
prerelease: false
|
97
|
-
version_requirements: !ruby/object:Gem::Requirement
|
98
|
-
requirements:
|
99
|
-
- - "~>"
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0.48'
|
102
|
-
- !ruby/object:Gem::Dependency
|
103
|
-
name: thoughtbot-shoulda
|
104
|
-
requirement: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - ">="
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '2.11'
|
109
|
-
- - "~>"
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '2.11'
|
112
|
-
type: :development
|
113
|
-
prerelease: false
|
114
|
-
version_requirements: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - ">="
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '2.11'
|
119
|
-
- - "~>"
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
version: '2.11'
|
31
|
+
version: '2.7'
|
122
32
|
description: Ruby client for the Wikipedia API
|
123
33
|
email: ken@kenpratt.net
|
124
34
|
executables: []
|
125
35
|
extensions: []
|
126
36
|
extra_rdoc_files:
|
127
|
-
- README.
|
37
|
+
- README.md
|
128
38
|
files:
|
129
39
|
- ".editorconfig"
|
40
|
+
- ".github/workflows/test.yml"
|
130
41
|
- ".gitignore"
|
131
42
|
- ".rubocop.yml"
|
132
|
-
- ".travis.yml"
|
133
43
|
- Gemfile
|
134
|
-
- Gemfile.lock
|
135
44
|
- MIT-LICENSE
|
136
|
-
- README.
|
45
|
+
- README.md
|
137
46
|
- Rakefile
|
138
47
|
- init.rb
|
139
48
|
- install.rb
|
49
|
+
- lib/wikipedia-client.rb
|
140
50
|
- lib/wikipedia.rb
|
141
51
|
- lib/wikipedia/client.rb
|
142
52
|
- lib/wikipedia/configuration.rb
|
@@ -211,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
121
|
requirements: []
|
212
122
|
rubygems_version: 3.0.3
|
213
123
|
signing_key:
|
214
|
-
specification_version:
|
124
|
+
specification_version: 4
|
215
125
|
summary: Ruby client for the Wikipedia API
|
216
126
|
test_files:
|
217
127
|
- spec/fixtures/Edsger_Dijkstra.json
|
data/.travis.yml
DELETED
data/Gemfile.lock
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
wikipedia-client (1.12.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
addressable (2.4.0)
|
10
|
-
ast (2.3.0)
|
11
|
-
builder (3.2.4)
|
12
|
-
coderay (1.1.3)
|
13
|
-
descendants_tracker (0.0.4)
|
14
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
15
|
-
diff-lcs (1.4.4)
|
16
|
-
faraday (0.9.2)
|
17
|
-
multipart-post (>= 1.2, < 3)
|
18
|
-
git (1.8.1)
|
19
|
-
rchardet (~> 1.8)
|
20
|
-
github_api (0.16.0)
|
21
|
-
addressable (~> 2.4.0)
|
22
|
-
descendants_tracker (~> 0.0.4)
|
23
|
-
faraday (~> 0.8, < 0.10)
|
24
|
-
hashie (>= 3.4)
|
25
|
-
mime-types (>= 1.16, < 3.0)
|
26
|
-
oauth2 (~> 1.0)
|
27
|
-
hashie (4.1.0)
|
28
|
-
highline (2.0.3)
|
29
|
-
jeweler (2.3.9)
|
30
|
-
builder
|
31
|
-
bundler
|
32
|
-
git (>= 1.2.5)
|
33
|
-
github_api (~> 0.16.0)
|
34
|
-
highline (>= 1.6.15)
|
35
|
-
nokogiri (>= 1.5.10)
|
36
|
-
psych
|
37
|
-
rake
|
38
|
-
rdoc
|
39
|
-
semver2
|
40
|
-
jwt (2.2.2)
|
41
|
-
method_source (1.0.0)
|
42
|
-
mime-types (2.99.3)
|
43
|
-
mini_portile2 (2.5.0)
|
44
|
-
multi_json (1.15.0)
|
45
|
-
multi_xml (0.6.0)
|
46
|
-
multipart-post (2.1.1)
|
47
|
-
nokogiri (1.11.2)
|
48
|
-
mini_portile2 (~> 2.5.0)
|
49
|
-
racc (~> 1.4)
|
50
|
-
oauth2 (1.4.7)
|
51
|
-
faraday (>= 0.8, < 2.0)
|
52
|
-
jwt (>= 1.0, < 3.0)
|
53
|
-
multi_json (~> 1.3)
|
54
|
-
multi_xml (~> 0.5)
|
55
|
-
rack (>= 1.2, < 3)
|
56
|
-
parser (2.4.0.0)
|
57
|
-
ast (~> 2.2)
|
58
|
-
powerpack (0.1.1)
|
59
|
-
pry (0.14.0)
|
60
|
-
coderay (~> 1.1)
|
61
|
-
method_source (~> 1.0)
|
62
|
-
psych (3.3.1)
|
63
|
-
racc (1.5.2)
|
64
|
-
rack (2.2.3)
|
65
|
-
rainbow (2.2.2)
|
66
|
-
rake
|
67
|
-
rake (13.0.3)
|
68
|
-
rchardet (1.8.0)
|
69
|
-
rdoc (6.3.0)
|
70
|
-
rspec (3.10.0)
|
71
|
-
rspec-core (~> 3.10.0)
|
72
|
-
rspec-expectations (~> 3.10.0)
|
73
|
-
rspec-mocks (~> 3.10.0)
|
74
|
-
rspec-core (3.10.1)
|
75
|
-
rspec-support (~> 3.10.0)
|
76
|
-
rspec-expectations (3.10.1)
|
77
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
78
|
-
rspec-support (~> 3.10.0)
|
79
|
-
rspec-mocks (3.10.2)
|
80
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
81
|
-
rspec-support (~> 3.10.0)
|
82
|
-
rspec-support (3.10.2)
|
83
|
-
rubocop (0.48.1)
|
84
|
-
parser (>= 2.3.3.1, < 3.0)
|
85
|
-
powerpack (~> 0.1)
|
86
|
-
rainbow (>= 1.99.1, < 3.0)
|
87
|
-
ruby-progressbar (~> 1.7)
|
88
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
89
|
-
ruby-progressbar (1.8.1)
|
90
|
-
semver2 (3.4.2)
|
91
|
-
thoughtbot-shoulda (2.11.1)
|
92
|
-
thread_safe (0.3.6)
|
93
|
-
unicode-display_width (1.2.1)
|
94
|
-
|
95
|
-
PLATFORMS
|
96
|
-
ruby
|
97
|
-
|
98
|
-
DEPENDENCIES
|
99
|
-
jeweler (~> 2.0)
|
100
|
-
pry (~> 0.14)
|
101
|
-
rake (~> 13.0)
|
102
|
-
rdoc (~> 6.0)
|
103
|
-
rspec (~> 3.0)
|
104
|
-
rubocop (~> 0.48)
|
105
|
-
thoughtbot-shoulda (~> 2.11, >= 2.11)
|
106
|
-
wikipedia-client!
|
107
|
-
|
108
|
-
BUNDLED WITH
|
109
|
-
2.0.2
|
data/README.textile
DELETED
@@ -1,168 +0,0 @@
|
|
1
|
-
h1. Wikipedia
|
2
|
-
|
3
|
-
!https://badge.fury.io/rb/wikipedia-client.svg!:https://badge.fury.io/rb/wikipedia-client !https://travis-ci.org/kenpratt/wikipedia-client.svg?branch=master!:https://travis-ci.org/kenpratt/wikipedia-client
|
4
|
-
|
5
|
-
Allows you to get wikipedia content through their API. This uses the
|
6
|
-
alpha API, not the deprecated query.php API type
|
7
|
-
|
8
|
-
Wikipedia API reference: "http://en.wikipedia.org/w/api.php":http://en.wikipedia.org/w/api.php
|
9
|
-
|
10
|
-
Adopted from: "http://code.google.com/p/wikipedia-client/":http://code.google.com/p/wikipedia-client/
|
11
|
-
|
12
|
-
h2. Installation
|
13
|
-
|
14
|
-
<pre><code>gem install wikipedia-client</code></pre>
|
15
|
-
|
16
|
-
h2. Examples
|
17
|
-
|
18
|
-
<pre><code>require 'wikipedia'
|
19
|
-
page = Wikipedia.find( 'Getting Things Done' )
|
20
|
-
|
21
|
-
=> #<Wikipedia:Page>
|
22
|
-
|
23
|
-
page.title
|
24
|
-
|
25
|
-
=> 'Getting Things Done'
|
26
|
-
|
27
|
-
page.fullurl
|
28
|
-
|
29
|
-
=> 'http://en.wikipedia.org/wiki/Getting_Things_Done'
|
30
|
-
|
31
|
-
page.text
|
32
|
-
|
33
|
-
=> 'Getting Things Done is a time-management method...'
|
34
|
-
|
35
|
-
page.content
|
36
|
-
|
37
|
-
=> # all the wiki markup appears here...
|
38
|
-
|
39
|
-
page.summary
|
40
|
-
|
41
|
-
=> # only the wiki summary appears here...
|
42
|
-
|
43
|
-
page.categories
|
44
|
-
|
45
|
-
=> [..., "Category:Self-help books", ...]
|
46
|
-
|
47
|
-
page.links
|
48
|
-
|
49
|
-
=> [..., "Business", "Cult following", ...]
|
50
|
-
|
51
|
-
page.extlinks
|
52
|
-
|
53
|
-
=> [..., "http://www.example.com/", ...]
|
54
|
-
|
55
|
-
page.images
|
56
|
-
|
57
|
-
=> ["File:Getting Things Done.jpg", ...]
|
58
|
-
|
59
|
-
page.image_urls
|
60
|
-
|
61
|
-
=> ["http://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"]
|
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
|
-
|
75
|
-
page.image_descriptionurls
|
76
|
-
|
77
|
-
=> ["http://en.wikipedia.org/wiki/File:Getting_Things_Done.jpg"]
|
78
|
-
|
79
|
-
page.main_image_url
|
80
|
-
|
81
|
-
=> "https://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"
|
82
|
-
|
83
|
-
page.coordinates
|
84
|
-
|
85
|
-
=> [48.853, 2.3498, "", "earth"]
|
86
|
-
|
87
|
-
page.templates
|
88
|
-
|
89
|
-
=> [..., "Template:About", ...]
|
90
|
-
|
91
|
-
page.langlinks
|
92
|
-
|
93
|
-
=> {..., "de"=>"Getting Things Done", "eo"=>"Igi aferojn finitaj", "zh"=>"尽管去做", ...}</code></pre>
|
94
|
-
|
95
|
-
h2. Configuration
|
96
|
-
|
97
|
-
This is by default configured like this:
|
98
|
-
|
99
|
-
<pre><code>Wikipedia.configure {
|
100
|
-
domain 'en.wikipedia.org'
|
101
|
-
path 'w/api.php'
|
102
|
-
}</code></pre>
|
103
|
-
|
104
|
-
h2. Advanced
|
105
|
-
|
106
|
-
See the API spec at "http://en.wikipedia.org/w/api.php":http://en.wikipedia.org/w/api.php
|
107
|
-
|
108
|
-
If you need data that is not already present, you can override parameters.
|
109
|
-
|
110
|
-
For example, to retrieve only the page info:
|
111
|
-
|
112
|
-
<pre><code>page = Wikipedia.find( 'Getting Things Done', :prop => "info" )
|
113
|
-
|
114
|
-
page.title
|
115
|
-
|
116
|
-
=> "Getting Things Done"
|
117
|
-
|
118
|
-
page.raw_data
|
119
|
-
|
120
|
-
=> {"query"=>{"pages"=>{"959928"=>{"pageid"=>959928, "ns"=>0,
|
121
|
-
"title"=>"Getting Things Done", "touched"=>"2010-03-10T00:04:09Z",
|
122
|
-
"lastrevid"=>348481810, "counter"=>0, "length"=>7891}}}}</code></pre>
|
123
|
-
|
124
|
-
h2. Contributing
|
125
|
-
|
126
|
-
h3. Getting the code, and running the tests
|
127
|
-
|
128
|
-
<pre><code>git clone git@github.com:kenpratt/wikipedia-client.git
|
129
|
-
cd wikipedia-client
|
130
|
-
gem install bundler
|
131
|
-
bundle exec rake spec</code></pre>
|
132
|
-
|
133
|
-
h3. Pushing a new release of the Gem
|
134
|
-
|
135
|
-
Edit <code>lib/wikipedia/version.rb</code>, changing <code>VERSION</code>.
|
136
|
-
|
137
|
-
Build the gem: <code>bundle exec gem build wikipedia-client.gemspec</code>
|
138
|
-
|
139
|
-
Commit the changes: <code>git commit -a -m 'Version bump to 1.4.0' && git push</code>
|
140
|
-
|
141
|
-
Publish the result to RubyGems: <code>bundle exec gem push wikipedia-client-1.4.0.gem</code>
|
142
|
-
|
143
|
-
h2. Thanks!
|
144
|
-
|
145
|
-
Copyright (c) 2008 [Cyril David], released under the MIT license
|
146
|
-
|
147
|
-
Adopted by Ken Pratt (ken@kenpratt.net) in 2010/03
|
148
|
-
|
149
|
-
h3. Contributors
|
150
|
-
|
151
|
-
Aishwarya Subramanian <aishwarya923@gmail.com>
|
152
|
-
Bryce <brycedneal@gmail.com>
|
153
|
-
cdr-data <b_rhettbarber@yahoo.com>
|
154
|
-
Christian Hellsten <christian.hellsten@gmail.com>
|
155
|
-
Christopher Quackenbush <christopher@quackenbush.me>
|
156
|
-
Cyril David
|
157
|
-
Francesco Serra <afnecors@gmail.com>
|
158
|
-
Harman Singh
|
159
|
-
ivobenedito <ivobenedito@gmail.com>
|
160
|
-
Justin Harrison <justin@matthin.com>
|
161
|
-
Ken Pratt <ken@kenpratt.net>
|
162
|
-
Manu Manu <manuisfunny@gmail.com>
|
163
|
-
Mike Haugland <mike.haugland@bravenet.com>
|
164
|
-
Pietro F. Menna <pietromenna@yahoo.com>
|
165
|
-
Sophie Rapoport <sfrapoport@gmail.com>
|
166
|
-
tsukasaoishi <tsukasa.oishi@gmail.com>
|
167
|
-
V <thevalentino@gmail.com>
|
168
|
-
Ilgiz Mustafin <ilgimustafin@gmail.com>
|