wikifari 0.1
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 +7 -0
- data/lib/wikifari/helper.rb +18 -0
- data/lib/wikifari/page.rb +36 -0
- data/lib/wikifari/request.rb +31 -0
- data/lib/wikifari/search.rb +16 -0
- data/lib/wikifari.rb +23 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 61c547b9abdd5c59c3e94f4576560441e8a2d29c
|
4
|
+
data.tar.gz: 6b165201ec26349ae8ae530f08ea2b8730808262
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4bfd391bfe718308738deabf9cdbc798971a98432e506c706328533592f0e3b1dab90622923d61c078b7b7e5b555efa4c8ae487e84a4db781dcefb193fc64809
|
7
|
+
data.tar.gz: 1be148f0cf5eb1982992b43407d4cfe7f899c55299e8c70853654be6331df98cf5dae94c8521d2781401791de55a0b2d7e690f6da629be047a4d73bc9cfbff60
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module WikiFari
|
2
|
+
class Helper
|
3
|
+
# Thanks, CGI!
|
4
|
+
def encode(string)
|
5
|
+
string.gsub(/([^\sa-zA-Z0-9\_\.\-\+]+)/) do
|
6
|
+
"%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
|
7
|
+
end.tr(" ", "+")
|
8
|
+
end
|
9
|
+
|
10
|
+
def query(hash)
|
11
|
+
string = ""
|
12
|
+
|
13
|
+
hash.each { |key, val| string << "#{key.to_s}=#{val}&" }
|
14
|
+
|
15
|
+
string.sub /\&$/, ""
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module WikiFari
|
2
|
+
class Page
|
3
|
+
def initialize(data)
|
4
|
+
@data = JSON.parse data
|
5
|
+
@raw = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def content
|
9
|
+
self.page["revisions"].first["*"] if self.page["revisions"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def id
|
13
|
+
self.page["pageid"].to_s if self.page["pageid"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def page
|
17
|
+
@data["query"]["pages"].values.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def raw
|
21
|
+
@raw
|
22
|
+
end
|
23
|
+
|
24
|
+
def redirect?
|
25
|
+
self.content && self.content.match(/\#REDIRECT\s+\[\[(.*?)\]\]/i)
|
26
|
+
end
|
27
|
+
|
28
|
+
def redirect
|
29
|
+
self.content.match(/\#REDIRECT\s+\[\[(.*?)\]\]/i)[1]
|
30
|
+
end
|
31
|
+
|
32
|
+
def title
|
33
|
+
self.page["title"] if self.page["title"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module WikiFari
|
2
|
+
class Request < Helper
|
3
|
+
def find(title)
|
4
|
+
data = self.read :action => "query",
|
5
|
+
:prop => "revisions",
|
6
|
+
:rvprop => "content",
|
7
|
+
:titles => self.encode(title)
|
8
|
+
|
9
|
+
page = Page.new data
|
10
|
+
|
11
|
+
return self.find(page.redirect) if page.redirect?
|
12
|
+
|
13
|
+
page
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(options)
|
17
|
+
site = Options[:site]
|
18
|
+
query = self.query options
|
19
|
+
|
20
|
+
URI.parse("#{site}?format=json&#{query}").read
|
21
|
+
end
|
22
|
+
|
23
|
+
def search(title)
|
24
|
+
data = self.read :action => "opensearch",
|
25
|
+
:limit => "10",
|
26
|
+
:search => self.encode(title)
|
27
|
+
|
28
|
+
Search.new data
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/wikifari.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "open-uri"
|
5
|
+
|
6
|
+
require "wikifari/helper.rb"
|
7
|
+
require "wikifari/page.rb"
|
8
|
+
require "wikifari/request.rb"
|
9
|
+
require "wikifari/search.rb"
|
10
|
+
|
11
|
+
module WikiFari
|
12
|
+
Options = {
|
13
|
+
:site => "http://en.wikipedia.org/w/api.php"
|
14
|
+
}
|
15
|
+
|
16
|
+
Version = "0.1"
|
17
|
+
|
18
|
+
class Config < Request
|
19
|
+
def initialize(site = nil)
|
20
|
+
Options[:site] = site if site
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wikifari
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oscar Palmér
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Read and search for content on MediaWiki-powered sites.
|
14
|
+
email: opalmer@me.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/wikifari/helper.rb
|
20
|
+
- lib/wikifari/page.rb
|
21
|
+
- lib/wikifari/request.rb
|
22
|
+
- lib/wikifari/search.rb
|
23
|
+
- lib/wikifari.rb
|
24
|
+
homepage: http://git.io/wf
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.0.3
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: WikiFari!
|
48
|
+
test_files: []
|