wiki_fetch 0.0.1.alpha.2 → 0.0.1.alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/wiki_fetch/global.rb +1 -0
- data/lib/wiki_fetch/url_formatter.rb +19 -0
- data/lib/wiki_fetch/version.rb +1 -1
- data/lib/wiki_fetch.rb +14 -4
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7de7d57c3cc25d25d9a6db410f7ff97b02933c8e
|
4
|
+
data.tar.gz: d44815f82b967de40fc28abff46ea31df0d9da04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab4019c046cdee3763c47176176e2c32cdbbc73015e163e40d052c7a02416beaf1495a76fbcfd39aacd986363102fece4e59daf413cc590d36667bc4c6d14466
|
7
|
+
data.tar.gz: 85f922043c2f748fe79e23435a6dd3980f90d61c409b5581066135b9f3b811d008d90087c8b3b9fbac04c6e7ca21a5ff9ea644aaa582724ad490e84782f4c8e1
|
@@ -0,0 +1 @@
|
|
1
|
+
$wiki_base_url = "http://en.wikipedia.org/w/api.php"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module UrlFormatter
|
2
|
+
def self.create_url(options)
|
3
|
+
format = options[:format] || "json"
|
4
|
+
case options[:method]
|
5
|
+
when "search_title"
|
6
|
+
query = options[:options][:action] || "query"
|
7
|
+
extracts = options[:options][:prop] || "extracts"
|
8
|
+
exsentences = (options[:options][:exsentences] || 10).to_i
|
9
|
+
return "#{$wiki_base_url}?format=#{format}&action=#{query}&prop=#{extracts}&exsentences=#{exsentences}&titles=#{options[:options][:name]}"
|
10
|
+
when "search_suggestions"
|
11
|
+
query = options[:options][:action] || "opensearch"
|
12
|
+
limit = (options[:options][:limit] || 10).to_i
|
13
|
+
namespace = (options[:options][:namespace] || 0).to_i
|
14
|
+
return "#{$wiki_base_url}?action=#{query}&search=#{options[:options][:name]}&limit=#{limit}&namespace=#{namespace}&format=#{format}"
|
15
|
+
else
|
16
|
+
puts "You gave me -- I have no idea what to do with that."
|
17
|
+
end
|
18
|
+
end
|
19
|
+
en
|
data/lib/wiki_fetch/version.rb
CHANGED
data/lib/wiki_fetch.rb
CHANGED
@@ -6,12 +6,22 @@ class Wiki
|
|
6
6
|
@@agent = Mechanize.new
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def search_title(name, options)
|
10
|
+
url = UrlFormatter.create_url({:name => name, :method => "search_title", :options => options})
|
11
|
+
fetch_url(url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def search_suggestions(name, options)
|
15
|
+
url = UrlFormatter.create_url({:name => name, :method => "search_suggestions", :options => options})
|
16
|
+
fetch_url(url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def fetch_url(url)
|
10
20
|
begin
|
11
21
|
page_data = @@agent.get url
|
12
|
-
page_data.body
|
13
|
-
rescue
|
14
|
-
|
22
|
+
return page_data.body
|
23
|
+
rescue => e
|
24
|
+
e.message
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiki_fetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.alpha.
|
4
|
+
version: 0.0.1.alpha.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nileshpatil47
|
@@ -65,6 +65,8 @@ files:
|
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
67
|
- lib/wiki_fetch.rb
|
68
|
+
- lib/wiki_fetch/global.rb
|
69
|
+
- lib/wiki_fetch/url_formatter.rb
|
68
70
|
- lib/wiki_fetch/version.rb
|
69
71
|
- wiki_fetch.gemspec
|
70
72
|
homepage: ''
|