Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add extlinks method #10

Merged
merged 2 commits into from

2 participants

Francesco Serra Ken Pratt
Francesco Serra

Like categories, links and images methods, templates method returns an array of external links from the given page.

Ken Pratt kenpratt merged commit c55378a into from
Ken Pratt
Owner

Thanks again! Merged, and published new gem release.

Francesco Serra

it's a pleasure! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 30, 2013
  1. Francesco Serra

    add method extlinks

    afnecors authored
  2. Francesco Serra

    update README extlinks

    afnecors authored
This page is out of date. Refresh to see the latest.
5 README.textile
View
@@ -34,6 +34,10 @@ page.links
=> [..., "Business", "Cult following", ...]
+page.extlinks
+
+=> [..., "http://www.example.com/", ...]
+
page.images
=> ["File:Getting Things Done.jpg", ...]
@@ -43,6 +47,7 @@ page.image_urls
=> ["http://upload.wikimedia.org/wikipedia/en/e/e1/Getting_Things_Done.jpg"]
page.image_descriptionurls
+
=> ["http://en.wikipedia.org/wiki/File:Getting_Things_Done.jpg"]
page.coordinates
4 lib/wikipedia/client.rb
View
@@ -13,7 +13,7 @@ def find( title, options = {} )
title = Url.new(title).title rescue title
page = Page.new( request_page( title, options ) )
while follow_redirects and page.redirect?
- page = Page.new( request_page( page.redirect_title, options ))
+ page = Page.new( request_page( page.redirect_title, options ) )
end
page
end
@@ -27,7 +27,7 @@ def find_image( title, options = {} )
def request_page( title, options = {} )
request( {
:action => "query",
- :prop => %w{ revisions links images categories coordinates templates },
+ :prop => %w{ revisions links extlinks images categories coordinates templates },
:rvprop => "content",
:titles => title
}.merge( options ) )
4 lib/wikipedia/page.rb
View
@@ -40,6 +40,10 @@ def links
page['links'].map {|c| c['title'] } if page['links']
end
+ def extlinks
+ page['extlinks'].map {|c| c['*'] } if page['extlinks']
+ end
+
def images
page['images'].map {|c| c['title'] } if page['images']
end
Something went wrong with that request. Please try again.