wikifari 0.2.2 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e576da6b575751378139da5e1445ddcad2791bd6
4
- data.tar.gz: 5fcde8bad3ad2a1880a75e2bd3aba9a8dce4f56e
3
+ metadata.gz: 5eaf41bae5e5fb6453179ba9e6b2c8f1e9cd5ad8
4
+ data.tar.gz: 348d8cc42436b226f19fa68f9e67f6a6f96c2d84
5
5
  SHA512:
6
- metadata.gz: e8b70e658e1461159ede5e6c2be419bdb5cd1d4ac30fac85971e71405956f89a4a115c5e64559198f02cf7307099b630ea1da3285b7520958d62a2cf9a55db44
7
- data.tar.gz: 026dfdd0d9635bf583e3fcb5d1691c4f365ca2e75752294f9a36fa62adafb97d3fc206931ca2d50186e052ccde0c0b73683d1c7b1e24b16395b2c3b2c8eebaef
6
+ metadata.gz: a4729a858b002b30b600edd9b94d2ab864f192aea7e3bd8c4ff7eea565e7d77f09b27ef0a5085847f8fc8ded552d2c73a564f3f7b3c8b11713b52a9c8eeff9ef
7
+ data.tar.gz: 9c8db822004edbb796168a12fb5da448a68c70833abceb8ce7b75fd3f02d59f2463da5bfc1a0eccd2de73a5e1ba88582c0833c2a489cb4473667d90789e960b9
@@ -1,25 +1,24 @@
1
- LIB = File.expand_path(File.dirname(__FILE__))
2
- $:.unshift(LIB) unless $:.include?(LIB)
1
+ WF_LIB = File.expand_path(File.dirname(__FILE__))
2
+ $:.unshift(WF_LIB) unless $:.include?(WF_LIB)
3
3
 
4
4
  require "json"
5
5
  require "open-uri"
6
6
 
7
- require "wikifari/custom"
8
7
  require "wikifari/helper"
9
8
  require "wikifari/page"
10
9
  require "wikifari/request"
11
10
  require "wikifari/search"
12
11
 
13
12
  module WikiFari
14
- Options = {
13
+ OPTIONS = {
15
14
  :site => "http://en.wikipedia.org/w/api.php"
16
15
  }
17
16
 
18
- Version = "0.2.2"
17
+ VERSION = "0.3.0"
19
18
 
20
19
  class Config < Request
21
20
  def initialize(site = nil)
22
- Options[:site] = site if site
21
+ OPTIONS[:site] = site if site
23
22
  end
24
23
  end
25
24
  end
@@ -1,18 +1,4 @@
1
1
  module WikiFari
2
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(" ", "+").gsub(/\%25/, "%")
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
3
  end
18
4
  end
@@ -22,11 +22,11 @@ module WikiFari
22
22
  end
23
23
 
24
24
  def redirect?
25
- self.content && self.content.match(/\#REDIRECT\s*\[\[(.*?)\]\]/i)
25
+ self.content && self.content.match(/\#redirect\s*\[\[(.*?)\]\]/i)
26
26
  end
27
27
 
28
28
  def redirect
29
- self.content.match(/\#REDIRECT\s*\[\[(.*?)\]\]/i)[1]
29
+ self.content.match(/\#redirect\s*\[\[(.*?)\]\]/i)[1]
30
30
  end
31
31
 
32
32
  def title
@@ -1,35 +1,25 @@
1
1
  module WikiFari
2
2
  class Request < Helper
3
- def api_request(options = {})
4
- site = Options[:site]
5
- query = self.query options
3
+ READ_QUERY = "action=query&prop=revisions&rvlimit=1&rvprop=content&titles"
4
+ SEARCH_QUERY = "action=opensearch&limit=25&search"
6
5
 
7
- URI.parse("#{site}?format=json&#{query}").read
8
- end
9
-
10
- def custom(options = {})
11
- data = self.api_request options
6
+ def api_request(query, title)
7
+ site = OPTIONS[:site]
8
+ title = URI.escape title
12
9
 
13
- Custom.new data
10
+ URI.parse("#{site}?format=json&#{query}=#{title}").read
14
11
  end
15
12
 
16
- def read(title, redirect = false)
17
- data = self.api_request :action => "query",
18
- :prop => "revisions",
19
- :rvprop => "content",
20
- :titles => self.encode(title)
13
+ def read(title, redirect = true)
14
+ data = self.api_request READ_QUERY, title
21
15
 
22
16
  page = Page.new data
23
17
 
24
- return self.read(page.redirect) if page.redirect? and redirect
25
-
26
- page
18
+ page.redirect? && redirect ? self.read(page.redirect) : page
27
19
  end
28
20
 
29
21
  def search(title)
30
- data = self.api_request :action => "opensearch",
31
- :limit => "10",
32
- :search => self.encode(title)
22
+ data = self.api_request SEARCH_QUERY, title
33
23
 
34
24
  Search.new data
35
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikifari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Palmér
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-04 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Read and search for content on MediaWiki-powered sites.
14
14
  email: opalmer@me.com
@@ -16,12 +16,11 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - lib/wikifari/custom.rb
19
+ - lib/wikifari.rb
20
20
  - lib/wikifari/helper.rb
21
21
  - lib/wikifari/page.rb
22
22
  - lib/wikifari/request.rb
23
23
  - lib/wikifari/search.rb
24
- - lib/wikifari.rb
25
24
  homepage: http://git.io/wf
26
25
  licenses:
27
26
  - MIT
@@ -32,17 +31,17 @@ require_paths:
32
31
  - lib
33
32
  required_ruby_version: !ruby/object:Gem::Requirement
34
33
  requirements:
35
- - - '>='
34
+ - - ">="
36
35
  - !ruby/object:Gem::Version
37
36
  version: '0'
38
37
  required_rubygems_version: !ruby/object:Gem::Requirement
39
38
  requirements:
40
- - - '>='
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  version: '0'
43
42
  requirements: []
44
43
  rubyforge_project:
45
- rubygems_version: 2.0.3
44
+ rubygems_version: 2.2.2
46
45
  signing_key:
47
46
  specification_version: 4
48
47
  summary: WikiFari!
@@ -1,16 +0,0 @@
1
- module WikiFari
2
- class Custom
3
- def initialize(data)
4
- @data = JSON.parse data
5
- @raw = data
6
- end
7
-
8
- def json
9
- @data
10
- end
11
-
12
- def raw
13
- @raw
14
- end
15
- end
16
- end