百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
W

wikipedia-client

> 编程语言
开源

用于维基百科 API 的 Ruby 客户端

309 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于维基百科 API 的 Ruby 客户端

Wikipedia API Client

Allows you to get wikipedia content through their API. This uses the alpha API, not the deprecated query.php API type.

Wikipedia API reference:

Adopted from:

Installation

gem install wikipedia-client

Usage

…

Configuration

Global

This is by default configured like this:

ruby
Wikipedia.configure {
  domain 'en.wikipedia.org'
  path   'w/api.php'
}

Local

If you need to query multiple wikis indiviual clients with individual configurations can be used:

ruby
config_en = Wikipedia::Configuration.new(domain: 'en.wikipedia.org')
config_de = Wikipedia::Configuration.new(domain: 'de.wikipedia.org')

client_en = Wikipedia::Client.new(config_en)
client_de = Wikipedia::Client.new(config_de)
client_en.find( 'Getting Things Done' )
client_de.find( 'Buch' )

Advanced

See the API spec at .

If you need data that is not already present, you can override parameters.

For example, to retrieve only the page info:

ruby
page = Wikipedia.find( 'Getting Things Done', :prop => "info" )

page.title
#=> "Getting Things Done"

page.raw_data
#=> {"query"=>{"pages"=>{"959928"=>{"pageid"=>959928, "ns"=>0,
"title"=>"Getting Things Done", "touched"=>"2010-03-10T00:04:09Z",
"lastrevid"=>348481810, "counter"=>0, "length"=>7891}}}}

Additional HTTP headers

Some API features require tweaking HTTP headers. You can add additional headers via configuration.

For example, to retrieve the same page in different language variants:

ruby
Wikipedia.configure do
   domain 'zh.wikipedia.org'
   headers({ 'Accept-Language' => 'zh-tw' })
end

Wikipedia.find('牛肉').summary #=> "牛肉是指從牛身上得出的肉,為常見的肉品之一。肌肉部分可以切成牛排、牛肉塊或牛仔骨,也可以與其他的肉混合做成香腸或血腸。"

Wikipedia.configure do
   domain 'zh.wikipedia.org'
   headers({ 'Accept-Language' => 'zh-cn' })
end

Wikipedia.find('牛肉').summary #=> "牛肉是指从牛身上得出的肉,为常见的肉品之一。肌肉部分可以切成牛排、牛肉块或牛仔骨,也可以与其他的肉混合做成香肠或血肠。"

Contributing

Getting the code, and running the tests

bash
git clone [email protected]:kenpratt/wikipedia-client.git
cd wikipedia-client
bundle install
bundle exec rspec

Pushing a new release of the Gem

  1. Edit lib/wikipedia/version.rb, changing VERSION.

  2. Test that the current branch will work as a gem, by testing in an external directory:

  3. Make a test directory.

  4. Add a Gemfile with:

    source 'https://rubygems.org'
    
    gem 'wikipedia-client', :path => '/path/to/local/wikipedia-client'
  5. And a test.rb file with:

    require 'wikipedia'
    
    page = Wikipedia.find('Ruby')
    puts page.title
  6. And then run bundle install && bundle exec ruby test.rb

  7. Build the gem: bundle exec gem build wikipedia-client.gemspec.

  8. Commit the changes: git commit -a -m 'Version bump to 1.4.0' && git tag v1.4.0 && git push && git push --tag

  9. Publish the result to RubyGems: bundle exec gem push wikipedia-client-1.4.0.gem.

  10. Test the released gem in an external directory:

  11. Make a test directory.

  12. Add a Gemfile with:

    source 'https://rubygems.org'
    
    gem 'wikipedia-client'
  13. And a test.rb file with:

    require 'wikipedia'
    
    page = Wikipedia.find('Ruby')
    puts page.title
  14. And then run bundle install && bundle exec ruby test.rb

Thanks!

Copyright (c) 2008 Cyril David, released under the MIT license

Adopted by Ken Pratt ([email protected]) in 2010/03

Thanks to all the Contributors.

Issues· 9 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言