All Projects → kenpratt → Wikipedia Client

kenpratt / Wikipedia Client

Licence: mit
Ruby client for the Wikipedia API

Programming Languages

ruby
36898 projects - #4 most used programming language

h1. Wikipedia

!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

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

Wikipedia API reference: "http://en.wikipedia.org/w/api.php":http://en.wikipedia.org/w/api.php

Adopted from: "http://code.google.com/p/wikipedia-client/":http://code.google.com/p/wikipedia-client/

h2. Installation

gem install wikipedia-client

h2. Examples

require 'wikipedia'
page = Wikipedia.find( 'Getting Things Done' )

=> #

page.title

=> 'Getting Things Done'

page.fullurl

=> 'http://en.wikipedia.org/wiki/Getting_Things_Done'

page.text

=> 'Getting Things Done is a time-management method...'

page.content

=> # all the wiki markup appears here...

page.summary

=> # only the wiki summary appears here...

page.categories

=> [..., "Category:Self-help books", ...]

page.links

=> [..., "Business", "Cult following", ...]

page.extlinks

=> [..., "http://www.example.com/", ...]

page.images

=> ["File:Getting Things Done.jpg", ...]

page.image_urls

=> ["http://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"]

default width: 200

page.image_thumburls

=> ["https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/Getting_Things_Done.jpg/200px-Getting_Things_Done.jpg"]

or with custom width argument:

page.image_thumburls(100)

=> ["https://upload.wikimedia.org/wikipedia/en/thumb/e/e1/Getting_Things_Done.jpg/100px-Getting_Things_Done.jpg"]

page.image_descriptionurls

=> ["http://en.wikipedia.org/wiki/File:Getting_Things_Done.jpg"]

page.main_image_url

=> "https://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"

page.coordinates

=> [48.853, 2.3498, "", "earth"]

page.templates

=> [..., "Template:About", ...]

page.langlinks

=> {..., "de"=>"Getting Things Done", "eo"=>"Igi aferojn finitaj",  "zh"=>"尽管去做", ...}

h2. Configuration

This is by default configured like this:

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

h2. Advanced

See the API spec at "http://en.wikipedia.org/w/api.php":http://en.wikipedia.org/w/api.php

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

For example, to retrieve only the page info:

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}}}}

h2. Contributing

h3. Getting the code, and running the tests

git clone [email protected]:kenpratt/wikipedia-client.git
cd wikipedia-client
gem install bundler
bundle exec rake spec

h3. Pushing a new release of the Gem

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

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

Commit the changes: git commit -a -m 'Version bump to 1.4.0' && git push

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

h2. Thanks!

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

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

h3. Contributors

Aishwarya Subramanian [email protected] Bryce [email protected] cdr-data [email protected] Christian Hellsten [email protected] Christopher Quackenbush [email protected] Cyril David Francesco Serra [email protected] Harman Singh ivobenedito [email protected] Justin Harrison [email protected] Ken Pratt [email protected] Manu Manu [email protected] Mike Haugland [email protected] Pietro F. Menna [email protected] Sophie Rapoport [email protected] tsukasaoishi [email protected] V [email protected] Ilgiz Mustafin [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].