Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add extlinks method #10

Merged
merged 2 commits into from

2 participants

@afnecors

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

@kenpratt kenpratt merged commit c55378a into kenpratt:master
@kenpratt
Owner

Thanks again! Merged, and published new gem release.

@afnecors

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. @afnecors

    add method extlinks

    afnecors authored
  2. @afnecors

    update README extlinks

    afnecors authored
This page is out of date. Refresh to see the latest.
View
5 README.textile
@@ -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
View
4 lib/wikipedia/client.rb
@@ -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 ) )
View
4 lib/wikipedia/page.rb
@@ -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.