wikipedia-client 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc643a753689499852495f809ef17e63ecdc968b
4
- data.tar.gz: 5c6271d1b84337745ffa2379e375adb1d55e5f82
3
+ metadata.gz: e089650b23ba504667789874fd323f5b1d390748
4
+ data.tar.gz: dca70f883ac007d84802bb7a60ddae8139683f93
5
5
  SHA512:
6
- metadata.gz: 162151de9346486e71d8c2e531141a5cb13b8efab0813681f673f0b3024145ece60d53470936a9e93d079988831f92918b8197f92a3d7c7ade7bf6cacaf55c50
7
- data.tar.gz: 38482ca139a614462b2b55cff1e9bb69e17a4ba45cc0befb9ffd5171eb5ab20b2966d9e40a77cf2b2bdd290c4e48f3914e48a32c142497747d6b98ff17341244
6
+ metadata.gz: 3493584b84a4c54b164a0cc97c9499574394bb50014b4ab88764c569a20520daf0666cb9878c3dafab6d8225b6c4c196af73697ae3f6ed7f9ef85f704a3da060
7
+ data.tar.gz: 1606ba0242ff30cbd0ff9ad405ab3efa734c2d22c1f51764b1e93b6140b578d65f61e2e7810e347b95200dfe4d082314b350b5a986def757e8cc7b94639ecfc6
data/.editorconfig ADDED
@@ -0,0 +1,12 @@
1
+ ; This file is for unifying the coding style for different editors and IDEs.
2
+ ; More information at http://EditorConfig.org
3
+
4
+ root = true
5
+ ; Use 2 spaces for indentation in all files
6
+ [*]
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ indent_style = space
11
+ indent_size = 2
12
+ insert_final_newline = true
data/.gitignore CHANGED
@@ -5,3 +5,5 @@
5
5
  *.tmp
6
6
  *.log
7
7
  pkg/*
8
+ coverage/
9
+ rdoc/
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ AllowURI: true
4
+
5
+ Metrics/MethodLength:
6
+ Max: 15
7
+
8
+ Style/SpaceInsideParens:
9
+ Enabled: false
10
+
11
+ Style/RescueModifier:
12
+ Enabled: false
13
+
14
+ Style/SpaceInsidePercentLiteralDelimiters:
15
+ Enabled: false
16
+
17
+ Style/RegexpLiteral:
18
+ AllowInnerSlashes: true
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ Style/SymbolArray:
24
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wikipedia-client (1.6.1)
4
+ wikipedia-client (1.6.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  addressable (2.3.5)
10
+ ast (2.3.0)
10
11
  builder (3.2.2)
11
12
  diff-lcs (1.2.4)
12
13
  faraday (0.8.8)
@@ -45,7 +46,12 @@ GEM
45
46
  multi_json (~> 1.0)
46
47
  multi_xml (~> 0.5)
47
48
  rack (~> 1.2)
49
+ parser (2.4.0.0)
50
+ ast (~> 2.2)
51
+ powerpack (0.1.1)
48
52
  rack (1.5.2)
53
+ rainbow (2.2.2)
54
+ rake
49
55
  rake (10.1.0)
50
56
  rdoc (4.0.1)
51
57
  json (~> 1.4)
@@ -57,7 +63,15 @@ GEM
57
63
  rspec-expectations (2.14.3)
58
64
  diff-lcs (>= 1.1.3, < 2.0)
59
65
  rspec-mocks (2.14.3)
66
+ rubocop (0.48.1)
67
+ parser (>= 2.3.3.1, < 3.0)
68
+ powerpack (~> 0.1)
69
+ rainbow (>= 1.99.1, < 3.0)
70
+ ruby-progressbar (~> 1.7)
71
+ unicode-display_width (~> 1.0, >= 1.0.1)
72
+ ruby-progressbar (1.8.1)
60
73
  thoughtbot-shoulda (2.11.1)
74
+ unicode-display_width (1.2.1)
61
75
 
62
76
  PLATFORMS
63
77
  ruby
@@ -67,8 +81,9 @@ DEPENDENCIES
67
81
  rake
68
82
  rdoc
69
83
  rspec
84
+ rubocop
70
85
  thoughtbot-shoulda
71
86
  wikipedia-client!
72
87
 
73
88
  BUNDLED WITH
74
- 1.10.5
89
+ 1.15.0
data/README.textile CHANGED
@@ -76,7 +76,7 @@ h2. Configuration
76
76
 
77
77
  This is by default configured like this:
78
78
 
79
- <pre><code>Wikipedia.Configure {
79
+ <pre><code>Wikipedia.configure {
80
80
  domain 'en.wikipedia.org'
81
81
  path 'w/api.php'
82
82
  }</code></pre>
@@ -115,8 +115,6 @@ h3. Pushing a new release of the Gem
115
115
 
116
116
  Edit <code>lib/wikipedia/version.rb</code>, changing <code>VERSION</code>.
117
117
 
118
- Edit <code>wikipedia-client.gemspec</code>, changing <code>s.date</code> to today's date.
119
-
120
118
  Build the gem: <code>bundle exec gem build wikipedia-client.gemspec</code>
121
119
 
122
120
  Commit the changes: <code>git commit -a -m 'Version bump to 1.4.0' && git push</code>
@@ -138,6 +136,7 @@ Christian Hellsten <christian.hellsten@gmail.com>
138
136
  Christopher Quackenbush <christopher@quackenbush.me>
139
137
  Cyril David
140
138
  Francesco Serra <afnecors@gmail.com>
139
+ Harman Singh
141
140
  ivobenedito <ivobenedito@gmail.com>
142
141
  Justin Harrison <justin@matthin.com>
143
142
  Ken Pratt <ken@kenpratt.net>
data/Rakefile CHANGED
@@ -1,38 +1,24 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
- require 'rubygems'
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
2
  require 'rake'
3
+ require 'rubocop/rake_task'
4
+ require 'rspec/core/rake_task'
5
+ require 'rdoc/task'
6
+ require 'wikipedia/version'
4
7
 
5
- require 'rake/testtask'
6
- Rake::TestTask.new(:test) do |test|
7
- test.libs << 'lib' << 'test'
8
- test.pattern = 'test/**/test_*.rb'
9
- test.verbose = true
10
- end
11
-
8
+ task default: [:spec, :rubocop]
12
9
 
13
10
  desc 'Test the wikipedia plugin.'
14
- task :spec do
15
- spec_path = File.expand_path(File.dirname(__FILE__) + '/spec/**/*.rb')
16
- system("rspec -cfs #{spec_path}")
17
- end
11
+ RSpec::Core::RakeTask.new(:spec)
18
12
 
19
- begin
20
- require 'rcov/rcovtask'
21
- Rcov::RcovTask.new do |test|
22
- test.libs << 'test'
23
- test.pattern = 'test/**/test_*.rb'
24
- test.verbose = true
25
- end
26
- rescue LoadError
27
- task :rcov do
28
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
29
- end
13
+ desc 'Run spec with coverage'
14
+ task :coverage do
15
+ ENV['COVERAGE'] = 'true'
16
+ Rake::Task['spec'].execute
30
17
  end
31
18
 
32
- task :default => :spec
19
+ desc 'Run rubocop'
20
+ RuboCop::RakeTask.new(:rubocop)
33
21
 
34
- require 'rdoc/task'
35
- require "wikipedia/version"
36
22
  Rake::RDocTask.new do |rdoc|
37
23
  version = Wikipedia::VERSION
38
24
 
data/install.rb CHANGED
@@ -1 +1 @@
1
- puts File.read(File.dirname(__FILE__) + '/README')
1
+ puts File.read(File.dirname(__FILE__) + '/README')
data/lib/wikipedia.rb CHANGED
@@ -25,22 +25,29 @@ module Wikipedia
25
25
  client.find_random( options )
26
26
  end
27
27
 
28
- def self.Configure(&block)
28
+ def self.configure(&block)
29
29
  Configuration.instance.instance_eval(&block)
30
30
  end
31
31
 
32
- Configure {
32
+ # rubocop:disable Style/MethodName
33
+ def self.Configure(&block)
34
+ configure(&block)
35
+ end
36
+
37
+ configure do
33
38
  protocol 'https'
34
39
  domain 'en.wikipedia.org'
35
40
  path 'w/api.php'
36
41
  user_agent(
37
42
  'wikipedia-client/1.3 (https://github.com/kenpratt/wikipedia-client)'
38
43
  )
39
- }
44
+ end
40
45
 
41
- private
46
+ class << self
47
+ private
42
48
 
43
- def self.client
44
- @client ||= Wikipedia::Client.new
49
+ def client
50
+ @client ||= Wikipedia::Client.new
51
+ end
45
52
  end
46
53
  end
@@ -1,7 +1,7 @@
1
1
  module Wikipedia
2
2
  class Client
3
3
  # see http://en.wikipedia.org/w/api.php
4
- BASE_URL = ":protocol://:domain/:path?action=:action&format=json"
4
+ BASE_URL = ':protocol://:domain/:path?action=:action&format=json'.freeze
5
5
 
6
6
  attr_accessor :follow_redirects
7
7
 
@@ -12,7 +12,7 @@ module Wikipedia
12
12
  def find( title, options = {} )
13
13
  title = Url.new(title).title rescue title
14
14
  page = Page.new( request_page( title, options ) )
15
- while follow_redirects and page.redirect?
15
+ while follow_redirects && page.redirect?
16
16
  page = Page.new( request_page( page.redirect_title, options ) )
17
17
  end
18
18
  page
@@ -25,87 +25,88 @@ module Wikipedia
25
25
 
26
26
  def find_random( options = {} )
27
27
  require 'json'
28
- data = JSON::load( request_random( options ) )
29
- title = data["query"]["pages"].values[0]["title"]
28
+ data = JSON.parse( request_random( options ) )
29
+ title = data['query']['pages'].values[0]['title']
30
30
  find( title, options )
31
31
  end
32
32
 
33
33
  # http://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions%7Clinks%7Cimages%7Ccategories&rvprop=content&titles=Flower%20(video%20game)
34
34
  def request_page( title, options = {} )
35
35
  request( {
36
- :action => "query",
37
- :prop => %w{ info revisions links extlinks images categories coordinates templates extracts },
38
- :rvprop => "content",
39
- :inprop => "url",
40
- :explaintext => "",
41
- :titles => title
42
- }.merge( options ) )
36
+ action: 'query',
37
+ prop: %w[ info revisions links extlinks images categories coordinates templates extracts ],
38
+ rvprop: 'content',
39
+ inprop: 'url',
40
+ explaintext: '',
41
+ titles: title
42
+ }.merge( options ) )
43
43
  end
44
44
 
45
45
  # http://en.wikipedia.org/w/api.php?action=query&format=json&prop=imageinfo&iiprop=url&titles=File:Flower.png
46
46
  def request_image( title, options = {} )
47
47
  request( {
48
- :action => "query",
49
- :prop => "imageinfo",
50
- :iiprop => "url",
51
- :titles => title
52
- }.merge( options ) )
48
+ action: 'query',
49
+ prop: 'imageinfo',
50
+ iiprop: 'url',
51
+ titles: title
52
+ }.merge( options ) )
53
53
  end
54
54
 
55
55
  # http://en.wikipedia.org/w/api.php?action=query&generator=random&grnnamespace=0&prop=info
56
56
  def request_random( options = {} )
57
57
  request( {
58
- :action => "query",
59
- :generator => "random",
60
- :grnnamespace => "0",
61
- :prop => "info"
62
- }.merge( options ) )
58
+ action: 'query',
59
+ generator: 'random',
60
+ grnnamespace: '0',
61
+ prop: 'info'
62
+ }.merge( options ) )
63
63
  end
64
64
 
65
65
  def request( options )
66
66
  require 'open-uri'
67
- URI.parse( url_for( options ) ).read( "User-Agent" => Configuration[:user_agent] )
67
+ URI.parse( url_for( options ) ).read( 'User-Agent' => Configuration[:user_agent] )
68
68
  end
69
69
 
70
70
  protected
71
- def configuration_options
72
- {
73
- :protocol => Configuration[:protocol],
74
- :domain => Configuration[:domain],
75
- :path => Configuration[:path],
76
- }
77
- end
78
71
 
79
- def url_for( options )
80
- url = BASE_URL.dup
81
- options = configuration_options.merge( options )
82
- options.each do |key, val|
83
- value = urlify_value( val )
84
- if url.include?( ":#{key}" )
85
- url.sub! ":#{key}", value
86
- else
87
- url << "&#{key}=#{value}"
88
- end
89
- end
90
- url
91
- end
72
+ def configuration_options
73
+ {
74
+ protocol: Configuration[:protocol],
75
+ domain: Configuration[:domain],
76
+ path: Configuration[:path]
77
+ }
78
+ end
92
79
 
93
- def urlify_value( val )
94
- case val
95
- when Array
96
- encode( val.flatten.join( '|' ) )
80
+ def url_for( options )
81
+ url = BASE_URL.dup
82
+ options = configuration_options.merge( options )
83
+ options.each do |key, val|
84
+ value = urlify_value( val )
85
+ if url.include?( ":#{key}" )
86
+ url.sub! ":#{key}", value
97
87
  else
98
- encode( val )
88
+ url << "&#{key}=#{value}"
99
89
  end
100
90
  end
91
+ url
92
+ end
101
93
 
102
- def encode( val )
103
- case val
104
- when String
105
- URI.encode( val ).gsub( '&', '%26' )
106
- else
107
- val
108
- end
94
+ def urlify_value( val )
95
+ case val
96
+ when Array
97
+ encode( val.flatten.join( '|' ) )
98
+ else
99
+ encode( val )
109
100
  end
101
+ end
102
+
103
+ def encode( val )
104
+ case val
105
+ when String
106
+ URI.encode( val ).gsub( '&', '%26' )
107
+ else
108
+ val
109
+ end
110
+ end
110
111
  end
111
112
  end
@@ -7,11 +7,9 @@ module Wikipedia
7
7
  def self.directives(*directives)
8
8
  directives.each do |directive|
9
9
  define_method directive do |*args|
10
- if args.empty?
11
- return instance_variable_get("@#{directive}")
12
- else
13
- instance_variable_set("@#{directive}", args.first)
14
- end
10
+ return instance_variable_get("@#{directive}") if args.empty?
11
+
12
+ instance_variable_set("@#{directive}", args.first)
15
13
  end
16
14
  end
17
15
  end
@@ -1,13 +1,15 @@
1
1
  module Wikipedia
2
2
  class Page
3
+ attr_reader :json
4
+
3
5
  def initialize(json)
4
6
  require 'json'
5
7
  @json = json
6
- @data = JSON::load(json)
8
+ @data = JSON.parse(json)
7
9
  end
8
10
 
9
11
  def page
10
- @data['query']['pages'].values.first
12
+ @data['query']['pages'].values.first if @data['query']['pages']
11
13
  end
12
14
 
13
15
  def content
@@ -23,9 +25,7 @@ module Wikipedia
23
25
  end
24
26
 
25
27
  def redirect_title
26
- if matches = redirect?
27
- matches[1]
28
- end
28
+ redirect?[1] rescue nil
29
29
  end
30
30
 
31
31
  def title
@@ -45,23 +45,23 @@ module Wikipedia
45
45
  end
46
46
 
47
47
  def summary
48
- (page['extract'].split("=="))[0].strip if page['extract']
48
+ page['extract'].split('==')[0].strip if page['extract'] && page['extract'] != ''
49
49
  end
50
50
 
51
51
  def categories
52
- page['categories'].map {|c| c['title'] } if page['categories']
52
+ page['categories'].map { |c| c['title'] } if page['categories']
53
53
  end
54
54
 
55
55
  def links
56
- page['links'].map {|c| c['title'] } if page['links']
56
+ page['links'].map { |c| c['title'] } if page['links']
57
57
  end
58
58
 
59
59
  def extlinks
60
- page['extlinks'].map {|c| c['*'] } if page['extlinks']
60
+ page['extlinks'].map { |c| c['*'] } if page['extlinks']
61
61
  end
62
62
 
63
63
  def images
64
- page['images'].map {|c| c['title'] } if page['images']
64
+ page['images'].map { |c| c['title'] } if page['images']
65
65
  end
66
66
 
67
67
  def image_url
@@ -73,11 +73,11 @@ module Wikipedia
73
73
  end
74
74
 
75
75
  def image_urls
76
- image_metadata.map {|img| img.image_url }
76
+ image_metadata.map(&:image_url)
77
77
  end
78
78
 
79
79
  def image_descriptionurls
80
- image_metadata.map {|img| img.image_descriptionurl }
80
+ image_metadata.map(&:image_descriptionurl)
81
81
  end
82
82
 
83
83
  def coordinates
@@ -90,61 +90,54 @@ module Wikipedia
90
90
 
91
91
  def image_metadata
92
92
  unless @cached_image_metadata
93
- if list = images
94
- filtered = list.select {|i| i =~ /:.+\.(jpg|jpeg|png|gif|svg)$/i && !i.include?("LinkFA-star") }
95
- @cached_image_metadata = filtered.map {|title| Wikipedia.find_image(title) }
96
- end
93
+ return if images.nil?
94
+ filtered = images.select { |i| i =~ /:.+\.(jpg|jpeg|png|gif|svg)$/i && !i.include?('LinkFA-star') }
95
+ @cached_image_metadata = filtered.map { |title| Wikipedia.find_image(title) }
97
96
  end
98
97
  @cached_image_metadata || []
99
98
  end
100
99
 
101
100
  def templates
102
- page['templates'].map {|c| c['title'] } if page['templates']
103
- end
104
-
105
- def json
106
- @json
101
+ page['templates'].map { |c| c['title'] } if page['templates']
107
102
  end
108
103
 
104
+ # rubocop:disable Metrics/MethodLength
105
+ # rubocop:disable Metrics/AbcSize
109
106
  def self.sanitize( s )
110
- if s
111
- s = s.dup
112
-
113
- # strip anything inside curly braces!
114
- while s =~ /\{\{[^\{\}]+?\}\}/
115
- s.gsub!(/\{\{[^\{\}]+?\}\}/, '')
116
- end
117
-
118
- # strip info box
119
- s.sub!(/^\{\|[^\{\}]+?\n\|\}\n/, '')
120
-
121
- # strip internal links
122
- s.gsub!(/\[\[([^\]\|]+?)\|([^\]\|]+?)\]\]/, '\2')
123
- s.gsub!(/\[\[([^\]\|]+?)\]\]/, '\1')
124
-
125
- # strip images and file links
126
- s.gsub!(/\[\[Image:[^\[\]]+?\]\]/, '')
127
- s.gsub!(/\[\[File:[^\[\]]+?\]\]/, '')
128
-
129
- # convert bold/italic to html
130
- s.gsub!(/'''''(.+?)'''''/, '<b><i>\1</i></b>')
131
- s.gsub!(/'''(.+?)'''/, '<b>\1</b>')
132
- s.gsub!(/''(.+?)''/, '<i>\1</i>')
133
-
134
- # misc
135
- s.gsub!(/<ref[^<>]*>[\s\S]*?<\/ref>/, '')
136
- s.gsub!(/<!--[^>]+?-->/, '')
137
- s.gsub!(' ', ' ')
138
- s.strip!
139
-
140
- # create paragraphs
141
- sections = s.split("\n\n")
142
- if sections.size > 1
143
- s = sections.map {|paragraph| "<p>#{paragraph.strip}</p>" }.join("\n")
144
- end
145
-
146
- s
107
+ return unless s
108
+
109
+ # strip anything inside curly braces!
110
+ s.gsub!(/\{\{[^\{\}]+?\}\}/, '') while s =~ /\{\{[^\{\}]+?\}\}/
111
+
112
+ # strip info box
113
+ s.sub!(/^\{\|[^\{\}]+?\n\|\}\n/, '')
114
+
115
+ # strip internal links
116
+ s.gsub!(/\[\[([^\]\|]+?)\|([^\]\|]+?)\]\]/, '\2')
117
+ s.gsub!(/\[\[([^\]\|]+?)\]\]/, '\1')
118
+
119
+ # strip images and file links
120
+ s.gsub!(/\[\[Image:[^\[\]]+?\]\]/, '')
121
+ s.gsub!(/\[\[File:[^\[\]]+?\]\]/, '')
122
+
123
+ # convert bold/italic to html
124
+ s.gsub!(/'''''(.+?)'''''/, '<b><i>\1</i></b>')
125
+ s.gsub!(/'''(.+?)'''/, '<b>\1</b>')
126
+ s.gsub!(/''(.+?)''/, '<i>\1</i>')
127
+
128
+ # misc
129
+ s.gsub!(/<ref[^<>]*>[\s\S]*?<\/ref>/, '')
130
+ s.gsub!(/<!--[^>]+?-->/, '')
131
+ s.gsub!(' ', ' ')
132
+ s.strip!
133
+
134
+ # create paragraphs
135
+ sections = s.split("\n\n")
136
+ if sections.size > 1
137
+ s = sections.map { |paragraph| "<p>#{paragraph.strip}</p>" }.join("\n")
147
138
  end
139
+
140
+ s
148
141
  end
149
142
  end
150
143
  end
data/lib/wikipedia/url.rb CHANGED
@@ -3,10 +3,10 @@ module Wikipedia
3
3
  def initialize(wiki_url)
4
4
  @wiki_url = wiki_url
5
5
  end
6
-
6
+
7
7
  def title
8
8
  return @title if @title
9
-
9
+
10
10
  uri = URI.parse( @wiki_url )
11
11
  @title = URI.decode( uri.path.split('/').last )
12
12
  end
@@ -1,3 +1,3 @@
1
1
  module Wikipedia
2
- VERSION = "1.6.3"
2
+ VERSION = '1.6.4'.freeze
3
3
  end
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
- require "wikipedia"
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'wikipedia'
5
5
 
6
- SANITIZATION_SAMPLE_PATH = File.join(File.dirname(__FILE__), "..", "spec", "fixtures", "sanitization_samples")
6
+ SANITIZATION_SAMPLE_PATH = File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures', 'sanitization_samples')
7
7
 
8
8
  def add_sanitization_test(url)
9
9
  title = Wikipedia::Url.new(url).title
10
- page = Wikipedia.find(title, :rvsection => 0)
11
- File.open(File.join(SANITIZATION_SAMPLE_PATH, "#{title}-raw.txt"), 'w') {|f| f << page.content }
12
- File.open(File.join(SANITIZATION_SAMPLE_PATH, "#{title}-sanitized.txt"), 'w') {|f| f << page.sanitized_content }
10
+ page = Wikipedia.find(title, rvsection: 0)
11
+ File.open(File.join(SANITIZATION_SAMPLE_PATH, "#{title}-raw.txt"), 'w') { |f| f << page.content }
12
+ File.open(File.join(SANITIZATION_SAMPLE_PATH, "#{title}-sanitized.txt"), 'w') { |f| f << page.sanitized_content }
13
13
  end
14
14
 
15
- if __FILE__ == $0
15
+ if __FILE__ == $PROGRAM_NAME
16
16
  unless ARGV.size == 1
17
- puts "Usage: #{$0} http://en.wikipedia.org/wiki/Social_Democratic_Party_of_Kyrgyzstan"
17
+ puts "Usage: #{$PROGRAM_NAME} http://en.wikipedia.org/wiki/Social_Democratic_Party_of_Kyrgyzstan"
18
18
  exit 0
19
19
  end
20
20
  url = ARGV[0]
@@ -1,164 +1,203 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'json'
3
3
 
4
- describe Wikipedia::Client, ".find page (mocked)" do
4
+ # rubocop:disable Metrics/BlockLength
5
+ describe Wikipedia::Client, '.find page (mocked)' do
5
6
  before(:each) do
6
7
  @client = Wikipedia::Client.new
7
8
  @edsger_dijkstra = File.read(File.dirname(__FILE__) + '/../fixtures/Edsger_Dijkstra.json')
8
- @edsger_content = JSON::load(File.read(File.dirname(__FILE__) + '/../fixtures/Edsger_content.txt'))['content']
9
+ @edsger_content = JSON.parse(File.read(File.dirname(__FILE__) + '/../fixtures/Edsger_content.txt'))['content']
9
10
  @client.should_receive(:request).and_return(@edsger_dijkstra)
10
11
  end
11
12
 
12
- it "should execute a request for the page" do
13
+ it 'should execute a request for the page' do
13
14
  @client.find('Edsger_Dijkstra')
14
15
  end
15
16
 
16
- it "should return a page object" do
17
+ it 'should return a page object' do
17
18
  @client.find('Edsger_Dijkstra').should be_an_instance_of(Wikipedia::Page)
18
19
  end
19
20
 
20
- it "should return a page with the correct content" do
21
+ it 'should return a page with the correct content' do
21
22
  @page = @client.find('Edsger_Dijkstra')
22
23
  @page.content.should == @edsger_content
23
24
  end
24
25
 
25
- it "should return a page with a title of Edsger W. Dijkstra" do
26
+ it 'should return a page with a title of Edsger W. Dijkstra' do
26
27
  @page = @client.find('Edsger_Dijkstra')
27
28
  @page.title.should == 'Edsger W. Dijkstra'
28
29
  end
29
30
 
30
- it "should return a page with the correct URL" do
31
+ it 'should return a page with the correct URL' do
31
32
  @page = @client.find('Edsger_Dijkstra')
32
33
  @page.fullurl.should == 'http://en.wikipedia.org/wiki/Edsger_W._Dijkstra'
33
34
  end
34
35
 
35
- it "should return a page with the correct plain text extract" do
36
+ it 'should return a page with the correct plain text extract' do
36
37
  @page = @client.find('Edsger_Dijkstra')
37
38
  @page.text.should start_with 'Edsger Wybe Dijkstra (Dutch pronunciation: '
38
39
  end
39
40
 
40
- it "should return a page with categories" do
41
+ it 'should return a page with categories' do
41
42
  @page = @client.find('Edsger_Dijkstra')
42
- @page.categories.should == ["Category:1930 births", "Category:2002 deaths", "Category:All pages needing cleanup", "Category:Articles needing cleanup from April 2009", "Category:Articles with close paraphrasing from April 2009", "Category:Computer pioneers", "Category:Dutch computer scientists", "Category:Dutch physicists", "Category:Eindhoven University of Technology faculty", "Category:Fellows of the Association for Computing Machinery"]
43
- end
44
-
45
- it "should return a page with links" do
43
+ [
44
+ 'Category:1930 births', 'Category:Fellows of the Association for Computing Machinery',
45
+ 'Category:2002 deaths', 'Category:Articles with close paraphrasing from April 2009',
46
+ 'Category:Computer pioneers', 'Category:Eindhoven University of Technology faculty',
47
+ 'Category:Dutch physicists', 'Category:Articles needing cleanup from April 2009',
48
+ 'Category:All pages needing cleanup', 'Category:Dutch computer scientists'
49
+ ].each do |category|
50
+ @page.categories.should include(category)
51
+ end
52
+ end
53
+
54
+ it 'should return a page with links' do
46
55
  @page = @client.find('Edsger_Dijkstra')
47
- @page.links.should == ["ACM Turing Award", "ALGOL", "ALGOL 60", "Adi Shamir", "Adriaan van Wijngaarden", "Agile software development", "Alan Kay", "Alan Perlis", "Algorithm", "Allen Newell"]
56
+ [
57
+ 'ALGOL', 'Alan Kay', 'ALGOL 60', 'Agile software development', 'ACM Turing Award',
58
+ 'Algorithm', 'Adi Shamir', 'Alan Perlis', 'Allen Newell', 'Adriaan van Wijngaarden'
59
+ ].each do |link|
60
+ @page.links.should include(link)
61
+ end
48
62
  end
49
63
 
50
- it "should return a page with images" do
64
+ it 'should return a page with images' do
51
65
  @page = @client.find('Edsger_Dijkstra')
52
- @page.images.should == ["File:Copyright-problem.svg", "File:Dijkstra.ogg", "File:Edsger Wybe Dijkstra.jpg", "File:Speaker Icon.svg", "File:Wikiquote-logo-en.svg"]
66
+ [
67
+ 'File:Dijkstra.ogg',
68
+ 'File:Speaker Icon.svg',
69
+ 'File:Wikiquote-logo-en.svg',
70
+ 'File:Copyright-problem.svg',
71
+ 'File:Edsger Wybe Dijkstra.jpg'
72
+ ].each do |file|
73
+ @page.images.should include(file)
74
+ end
53
75
  end
54
76
  end
55
77
 
56
- describe Wikipedia::Client, ".find page with one section (mocked)" do
78
+ describe Wikipedia::Client, '.find page with one section (mocked)' do
57
79
  before(:each) do
58
80
  @client = Wikipedia::Client.new
59
- @edsger_dijkstra = File.read(File.dirname(__FILE__) + '/../fixtures/Edsger_Dijkstra_section_0.json')
60
- @edsger_content = File.read(File.dirname(__FILE__) + '/../fixtures/sanitization_samples/Edsger_W_Dijkstra-sanitized.txt').strip
81
+ dir_name = File.dirname(__FILE__)
82
+ @edsger_dijkstra = File.read(dir_name + '/../fixtures/Edsger_Dijkstra_section_0.json')
83
+ @edsger_content = File.read(dir_name + '/../fixtures/sanitization_samples/Edsger_W_Dijkstra-sanitized.txt').strip
61
84
  @client.should_receive(:request).and_return(@edsger_dijkstra)
62
85
  end
63
86
 
64
- it "should have the correct sanitized intro" do
65
- @page = @client.find('Edsger_Dijkstra', :rvsection => 0)
87
+ it 'should have the correct sanitized intro' do
88
+ @page = @client.find('Edsger_Dijkstra', rvsection: 0)
66
89
  @page.sanitized_content.should == @edsger_content
67
90
  end
68
91
  end
69
92
 
70
- describe Wikipedia::Client, ".find image (mocked)" do
93
+ describe Wikipedia::Client, '.find image (mocked)' do
71
94
  before(:each) do
72
95
  @client = Wikipedia::Client.new
73
96
  @edsger_dijkstra = File.read(File.dirname(__FILE__) + '/../fixtures/File_Edsger_Wybe_Dijkstra_jpg.json')
74
97
  @client.should_receive(:request).and_return(@edsger_dijkstra)
75
98
  end
76
99
 
77
- it "should execute a request for the image" do
100
+ it 'should execute a request for the image' do
78
101
  @client.find_image('File:Edsger Wybe Dijkstra.jpg')
79
102
  end
80
103
 
81
- it "should return a page object" do
104
+ it 'should return a page object' do
82
105
  @client.find_image('File:Edsger Wybe Dijkstra.jpg').should be_an_instance_of(Wikipedia::Page)
83
106
  end
84
107
 
85
- it "should return a page with a title of File:Edsger Wybe Dijkstra.jpg" do
108
+ it 'should return a page with a title of File:Edsger Wybe Dijkstra.jpg' do
86
109
  @page = @client.find_image('File:Edsger Wybe Dijkstra.jpg')
87
110
  @page.title.should == 'File:Edsger Wybe Dijkstra.jpg'
88
111
  end
89
112
 
90
- it "should return a page with an image url" do
113
+ it 'should return a page with an image url' do
91
114
  @page = @client.find_image('File:Edsger Wybe Dijkstra.jpg')
92
- @page.image_url.should == "http://upload.wikimedia.org/wikipedia/commons/d/d9/Edsger_Wybe_Dijkstra.jpg"
115
+ @page.image_url.should == 'http://upload.wikimedia.org/wikipedia/commons/d/d9/Edsger_Wybe_Dijkstra.jpg'
93
116
  end
94
117
  end
95
118
 
96
- describe Wikipedia::Client, ".find page (Edsger_Dijkstra)" do
119
+ describe Wikipedia::Client, '.find page (Edsger_Dijkstra)' do
97
120
  before(:each) do
98
121
  @client = Wikipedia::Client.new
99
122
  @client.follow_redirects = false
100
123
  end
101
124
 
102
- it "should get a redirect when trying Edsger Dijkstra" do
125
+ it 'should get a redirect when trying Edsger Dijkstra' do
103
126
  @page = @client.find('Edsger Dijkstra')
104
127
  @page.should be_redirect
105
128
  end
106
129
 
107
- it "should get a final page when follow_redirects is true" do
130
+ it 'should get a final page when follow_redirects is true' do
108
131
  @client.follow_redirects = true
109
132
  @page = @client.find('Edsger Dijkstra')
110
133
  @page.should_not be_redirect
111
134
  end
112
135
 
113
- it "should collect the image urls" do
136
+ it 'should collect the image urls' do
114
137
  @client.follow_redirects = true
115
138
  @page = @client.find('Edsger Dijkstra')
116
- @page.image_urls.should == ["https://upload.wikimedia.org/wikipedia/en/4/4a/Commons-logo.svg", "https://upload.wikimedia.org/wikipedia/commons/5/57/Dijkstra_Animation.gif", "https://upload.wikimedia.org/wikipedia/commons/6/6a/Dining_philosophers.png", "https://upload.wikimedia.org/wikipedia/commons/c/c9/Edsger_Dijkstra_1994.jpg", "https://upload.wikimedia.org/wikipedia/commons/d/d9/Edsger_Wybe_Dijkstra.jpg", "https://upload.wikimedia.org/wikipedia/en/4/48/Folder_Hexagonal_Icon.svg", "https://upload.wikimedia.org/wikipedia/commons/7/7b/Rail-semaphore-signal-Dave-F.jpg", "https://upload.wikimedia.org/wikipedia/commons/2/21/Speaker_Icon.svg", "https://upload.wikimedia.org/wikipedia/commons/f/fa/Wikiquote-logo.svg"]
139
+ [
140
+ '/en/4/4a/Commons-logo.svg',
141
+ '/en/4/48/Folder_Hexagonal_Icon.svg',
142
+ '/commons/5/57/Dijkstra_Animation.gif',
143
+ '/commons/c/c9/Edsger_Dijkstra_1994.jpg',
144
+ '/commons/d/d9/Edsger_Wybe_Dijkstra.jpg',
145
+ '/commons/0/00/Complex-adaptive-system.jpg',
146
+ '/en/4/4d/Centrum-wiskunde-informatica-logo.png',
147
+ '/commons/7/7b/An_illustration_of_the_dining_philosophers_problem.png',
148
+ '/commons/3/37/Detail_of_a_1Kb_ferrite_core_RAM-module_of_an_1960s_Electrologica_X1_computer.jpg'
149
+ ].each do |image|
150
+ @page.image_urls.should include('https://upload.wikimedia.org/wikipedia' + image)
151
+ end
117
152
  end
118
153
  end
119
154
 
120
- describe Wikipedia::Client, ".find page (Rails) at jp" do
155
+ describe Wikipedia::Client, '.find page (Rails) at jp' do
121
156
  before(:each) do
122
- Wikipedia.Configure { domain "ja.wikipedia.org" }
157
+ Wikipedia.configure { domain 'ja.wikipedia.org' }
123
158
  @client = Wikipedia::Client.new
124
159
  @client.follow_redirects = false
125
160
  end
126
161
 
127
- it "should get a redirect when trying Rails" do
162
+ it 'should get a redirect when trying Rails' do
128
163
  @page = @client.find('Rails')
129
164
  @page.should be_redirect
130
165
  end
131
166
 
132
- it "should get a final page when follow_redirects is true" do
167
+ it 'should get a final page when follow_redirects is true' do
133
168
  @client.follow_redirects = true
134
169
  @page = @client.find('Rails')
135
170
  @page.should_not be_redirect
136
171
  end
137
172
  end
138
173
 
139
- describe Wikipedia::Client, ".find random page" do
174
+ describe Wikipedia::Client, '.find random page' do
140
175
  before(:each) do
141
176
  @client = Wikipedia::Client.new
142
177
  end
143
178
 
144
- it "should get random pages" do
145
- @page1 = @client.find_random().title
146
- @page2 = @client.find_random().title
179
+ it 'should get random pages' do
180
+ @page1 = @client.find_random.title
181
+ @page2 = @client.find_random.title
147
182
  @page1.should_not == @page2
148
183
  end
149
184
  end
150
185
 
151
- describe Wikipedia::Client, "page.summary (mocked)" do
186
+ describe Wikipedia::Client, 'page.summary (mocked)' do
152
187
  before(:each) do
153
188
  @client = Wikipedia::Client.new
154
189
  @edsger_dijkstra = File.read(File.dirname(__FILE__) + '/../fixtures/Edsger_Dijkstra.json')
155
- @edsger_content = JSON::load(File.read(File.dirname(__FILE__) + '/../fixtures/Edsger_content.txt'))['content']
190
+ @edsger_content = JSON.parse(File.read(File.dirname(__FILE__) + '/../fixtures/Edsger_content.txt'))['content']
156
191
  @client.should_receive(:request).and_return(@edsger_dijkstra)
157
192
  end
158
193
 
159
- it "should return only the summary" do
194
+ it 'should return only the summary' do
160
195
  @page = @client.find('Edsger_Dijkstra')
161
- @page.summary.should == 'Edsger Wybe Dijkstra (Dutch pronunciation: [ˈɛtsxər ˈʋibə ˈdɛikstra] ( ); 11 May 1930 – 6 August 2002) was a Dutch computer scientist. He received the 1972 Turing Award for fundamental contributions to developing programming languages, and was the Schlumberger Centennial Chair of Computer Sciences at The University of Texas at Austin from 1984 until 2000.
162
- Shortly before his death in 2002, he received the ACM PODC Influential Paper Award in distributed computing for his work on self-stabilization of program computation. This annual award was renamed the Dijkstra Prize the following year, in his honor.'
196
+ @page.summary.should == 'Edsger Wybe Dijkstra (Dutch pronunciation: [ˈɛtsxər ˈʋibə ˈdɛikstra] ( );'\
197
+ ' 11 May 1930 6 August 2002) was a Dutch computer scientist. He received the 1972 Turing Award for fundamental'\
198
+ ' contributions to developing programming languages, and was the Schlumberger Centennial Chair of Computer'\
199
+ " Sciences at The University of Texas at Austin from 1984 until 2000.\nShortly before his death in 2002, he"\
200
+ ' received the ACM PODC Influential Paper Award in distributed computing for his work on self-stabilization of'\
201
+ ' program computation. This annual award was renamed the Dijkstra Prize the following year, in his honor.'
163
202
  end
164
203
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'json'
3
3
 
4
- describe Wikipedia::Page, ".sanitize wiki markup" do
4
+ describe Wikipedia::Page, '.sanitize wiki markup' do
5
5
  Dir[File.dirname(__FILE__) + '/../fixtures/sanitization_samples/*-raw.txt'].each do |raw_filename|
6
6
  name = raw_filename.sub(/\/(.+?)\-raw\.txt$/, '\1')
7
7
  sanitized_filename = raw_filename.sub('-raw', '-sanitized')
data/spec/lib/url_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe Wikipedia::Url, "like http://en.wikipedia.org/wiki/Getting_Things_Done" do
4
- it "should have a title of Getting_Things_Done" do
3
+ describe Wikipedia::Url, 'like http://en.wikipedia.org/wiki/Getting_Things_Done' do
4
+ it 'should have a title of Getting_Things_Done' do
5
5
  url = Wikipedia::Url.new('http://en.wikipedia.org/wiki/Getting_Things_Done')
6
6
  url.title.should == 'Getting_Things_Done'
7
7
  end
8
- end
8
+ end
@@ -1,19 +1,19 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
2
 
3
- describe Wikipedia, ".find" do
4
- it "should return a Wikipedia::Page instance" do
3
+ describe Wikipedia, '.find' do
4
+ it 'should return a Wikipedia::Page instance' do
5
5
  page = Wikipedia.find('Getting_Things_Done')
6
6
  page.should be_an_instance_of(Wikipedia::Page)
7
7
  end
8
-
9
- it "should return a Page with a title" do
8
+
9
+ it 'should return a Page with a title' do
10
10
  page = Wikipedia.find('Getting_Things_Done')
11
11
  page.title.should_not be_nil
12
12
  end
13
-
14
- it "should return a Page given a URL" do
13
+
14
+ it 'should return a Page given a URL' do
15
15
  page1 = Wikipedia.find('Getting_Things_Done')
16
-
16
+
17
17
  page2 = Wikipedia.find('http://en.wikipedia.org/wiki/Getting_Things_Done')
18
18
  page1.title.should == page2.title
19
19
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,12 @@
1
- require 'rubygems'
2
1
  require 'rspec'
3
2
 
3
+ if ENV['COVERAGE'] == 'true'
4
+ begin
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+ rescue LoadError
8
+ abort 'Coverage driver not available. In order to run coverage, you must run: gem install simplecov'
9
+ end
10
+ end
11
+
4
12
  require File.dirname(__FILE__) + '/../lib/wikipedia'
@@ -1,26 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "wikipedia/version"
4
2
 
5
- spec = Gem::Specification.new do |s|
6
- s.name = "wikipedia-client"
3
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
4
+ require 'wikipedia/version'
5
+ require 'date'
6
+
7
+ # rubocop:disable Metrics/BlockLength
8
+ Gem::Specification.new do |s|
9
+ s.name = 'wikipedia-client'
7
10
  s.version = Wikipedia::VERSION
8
11
 
9
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
13
 
11
14
  s.license = 'MIT'
12
- s.authors = ["Cyril David", "Ken Pratt", "Mike Haugland", "Aishwarya Subramanian", "Pietro Menna", "Sophie Rapoport"]
15
+ s.authors = ['Cyril David', 'Ken Pratt', 'Mike Haugland',
16
+ 'Aishwarya Subramanian', 'Pietro Menna', 'Sophie Rapoport']
13
17
  s.date = Date.today.to_s
14
- s.description = "Ruby client for the Wikipedia API"
15
- s.email = "ken@kenpratt.net"
18
+ s.description = 'Ruby client for the Wikipedia API'
19
+ s.email = 'ken@kenpratt.net'
16
20
 
17
- s.homepage = "http://github.com/kenpratt/wikipedia-client"
18
- s.rubygems_version = "1.8.23"
19
- s.summary = "Ruby client for the Wikipedia API"
21
+ s.homepage = 'http://github.com/kenpratt/wikipedia-client'
22
+ s.rubygems_version = '1.8.23'
23
+ s.summary = 'Ruby client for the Wikipedia API'
20
24
  s.platform = Gem::Platform::RUBY
21
25
  s.files = `git ls-files`.split("\n")
22
26
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
24
28
  s.has_rdoc = true
25
29
  s.extra_rdoc_files = ['README.textile']
26
30
  s.bindir = 'bin'
@@ -32,17 +36,17 @@ spec = Gem::Specification.new do |s|
32
36
  s.add_development_dependency('rspec')
33
37
  s.add_development_dependency('rdoc')
34
38
  s.add_development_dependency('jeweler')
39
+ s.add_development_dependency('rubocop')
35
40
 
36
-
37
- if s.respond_to? :specification_version then
41
+ if s.respond_to? :specification_version
38
42
  s.specification_version = 3
39
43
 
40
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
45
+ s.add_development_dependency('thoughtbot-shoulda', ['>= 0'])
42
46
  else
43
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
+ s.add_dependency('thoughtbot-shoulda', ['>= 0'])
44
48
  end
45
49
  else
46
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ s.add_dependency('thoughtbot-shoulda', ['>= 0'])
47
51
  end
48
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikipedia-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril David
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2016-10-08 00:00:00.000000000 Z
16
+ date: 2017-05-24 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rake
@@ -71,6 +71,20 @@ dependencies:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
+ - !ruby/object:Gem::Dependency
75
+ name: rubocop
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
74
88
  - !ruby/object:Gem::Dependency
75
89
  name: thoughtbot-shoulda
76
90
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +106,9 @@ extensions: []
92
106
  extra_rdoc_files:
93
107
  - README.textile
94
108
  files:
109
+ - ".editorconfig"
95
110
  - ".gitignore"
111
+ - ".rubocop.yml"
96
112
  - ".travis.yml"
97
113
  - Gemfile
98
114
  - Gemfile.lock
@@ -170,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
186
  version: '0'
171
187
  requirements: []
172
188
  rubyforge_project:
173
- rubygems_version: 2.5.1
189
+ rubygems_version: 2.6.12
174
190
  signing_key:
175
191
  specification_version: 3
176
192
  summary: Ruby client for the Wikipedia API