wikimedia-commoner 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +57 -0
  6. data/Rakefile +19 -0
  7. data/lib/wikimedia/commoner.rb +154 -0
  8. data/lib/wikimedia/commoner/version.rb +5 -0
  9. data/spec/author_spec.rb +82 -0
  10. data/spec/commoner_spec.rb +53 -0
  11. data/spec/details_spec.rb +87 -0
  12. data/spec/geolocation_spec.rb +24 -0
  13. data/spec/licence_spec.rb +62 -0
  14. data/spec/openplaques_id_spec.rb +27 -0
  15. data/spec/spec_helper.rb +9 -0
  16. data/spec/vcr_cassettes/categorised_images/a-base-category.yml +38189 -0
  17. data/spec/vcr_cassettes/details/of-August-Wilhelm-von-Hofmann.yml +834 -0
  18. data/spec/vcr_cassettes/details/of-Catherine-of-Aragon-portrait.yml +1090 -0
  19. data/spec/vcr_cassettes/details/of-Nahal-Zaror_-south-11.yml +968 -0
  20. data/spec/vcr_cassettes/details/of-Stepan-Blois-portrait.yml +1291 -0
  21. data/spec/vcr_cassettes/details/of-The-mohave-desert-near-the-fossil-beds.yml +808 -0
  22. data/spec/vcr_cassettes/details/of-a-Commons-file-page.yml +953 -0
  23. data/spec/vcr_cassettes/details/of-a-Delhi-portrait-of-a-man.yml +1941 -0
  24. data/spec/vcr_cassettes/details/of-a-Spanish-Civil-War-mass-grave.yml +2285 -0
  25. data/spec/vcr_cassettes/details/of-a-Wikipedia-image-preview-url.yml +960 -0
  26. data/spec/vcr_cassettes/details/of-a-Wikipedia-mobile-image-preview-url.yml +964 -0
  27. data/spec/vcr_cassettes/details/of-a-deleted-photo.yml +66 -0
  28. data/spec/vcr_cassettes/details/of-a-full-Commons-file-page-url.yml +953 -0
  29. data/spec/vcr_cassettes/details/of-an-unknown-page-name.yml +65 -0
  30. data/spec/vcr_cassettes/details/of-url-for-Jacob-with-unicode-in.yml +972 -0
  31. data/spec/vcr_cassettes/details/of-url-with-a-strange-character-in.yml +972 -0
  32. data/spec/vcr_cassettes/details/of-url-with-unicode-in.yml +65 -0
  33. data/spec/vcr_cassettes/details/photo-of-Stanley-Osher.yml +958 -0
  34. data/spec/vcr_cassettes/details/the-Fox-Gun-plaque.yml +1035 -0
  35. data/spec/vcr_cassettes/details/the-Sir-Harold-Gillies-plaque.yml +1008 -0
  36. data/spec/vcr_cassettes/images/on-a-known-term.yml +9357 -0
  37. data/spec/vcr_cassettes/images/on-an-unknown-term.yml +64 -0
  38. data/spec/vcr_cassettes/searching/on-a-known-term.yml +69 -0
  39. data/spec/vcr_cassettes/searching/on-an-unknown-term.yml +66 -0
  40. data/wikimedia-commoner.gemspec +29 -0
  41. metadata +213 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a227a091c7462e7ee5cbc5a4f5006fed5d7178cc
4
+ data.tar.gz: e64c81d9b390d41cb4781828b2752462ebe3e4fd
5
+ SHA512:
6
+ metadata.gz: 144dd7ff7a215bcb8ffb4d65e30bc8807d6ad3c6b1dab16fdaa72d4103ed7e074a693ff68d8979f83b8ab610b51c3f1704becb477f1415acb1d9ace351d55637
7
+ data.tar.gz: 9a2fbdee2ec60bdded019b15dfba94b7b17950d7099e8ba76e121af452319245b0a10df2f6cd029370a83b11faa67f676f59d96ebd36fbe3edcdd5ee458fad4d
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wikimedia-commoner.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Jez Nicholson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # Wikimedia::Commoner
2
+
3
+ A Wikimedia Commons page holds more details than the api provides, e.g. the name of the copyright holder. This can be scraped from the html as a standard format is encouraged with mediawiki templates. It is not foolproof, but will work for most of the images.
4
+
5
+ This gem is used by OpenPlaques.org to get hold of image links and appropriate copyright holder details so that an image can be legally displayed on a web page.
6
+
7
+ The idea is that users can copy and paste any Wikimedia filename to your system and you can get the details. It looks for anything with 'File:' in the url, so can cope with different formats coming from preview urls, etc.:
8
+ * https://commons.wikimedia.org/wiki/File:Ciconia_ciconia_-_01.jpg
9
+ * https://commons.wikimedia.org/wiki/Main_Page#/media/File:Ciconia_ciconia_-_01.jpg
10
+ * File:Ciconia_ciconia_-_01.jpg
11
+ * https://commons.wikimedia.org/wiki/File:Plaque_in_Fortune_Street.jpg#.7B.7Bint:filedesc.7D.7D
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'wikimedia-commoner'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install wikimedia-commoner
28
+
29
+ ## Usage
30
+
31
+ require 'wikimedia/commoner'
32
+
33
+ wikimedia = Wikimedia::Commoner.details(wikimedia_url)
34
+ wikimedia[:categories]
35
+ wikimedia[:url]
36
+ wikimedia[:page_url]
37
+ wikimedia[:description]
38
+ wikimedia[:author]
39
+ wikimedia[:author_url]
40
+ wikimedia[:licence]
41
+ wikimedia[:licence_url])
42
+
43
+ Wikimedia::Commoner.search 'term'
44
+
45
+ Wikimedia::Commoner.images 'term'
46
+
47
+ Wikimedia::Commoner.categorised_images 'category'
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/jnicho02/wikimedia-commoner/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
56
+
57
+ With thanks to Ross Cooperman for the inspiration with his 2013 commoner gem. I did try a pull request.
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Run with 'rake spec'
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
+ # task.rspec_opts = ['--color', '--format', 'nested']
8
+ end
9
+
10
+ # http://erniemiller.org/2014/02/05/7-lines-every-gems-rakefile-should-have/
11
+ task :console do
12
+ require 'irb'
13
+ require 'irb/completion'
14
+ require 'wikimedia/commoner'
15
+ ARGV.clear
16
+ IRB.start
17
+ end
18
+
19
+ task :default => :test
@@ -0,0 +1,154 @@
1
+ require 'wikimedia/commoner/version'
2
+ require 'httparty'
3
+ require 'sanitize'
4
+
5
+ module Wikimedia
6
+ class Commoner
7
+ def self.search(query)
8
+ new.search(query)
9
+ end
10
+
11
+ def self.images(term)
12
+ new.images(term)
13
+ end
14
+
15
+ def self.categorised_images(term)
16
+ new.categorised_images(term)
17
+ end
18
+
19
+ def self.details(title)
20
+ title = URI.unescape title
21
+ new.details(title)
22
+ end
23
+
24
+ def initialize(base_uri = nil)
25
+ @uri = (base_uri) ? base_uri : default_uri
26
+ end
27
+
28
+ def search(query)
29
+ json_get(search_uri(query))[1]
30
+ end
31
+
32
+ def images(term)
33
+ # get a list of titles for the given term
34
+ response = json_get(query_uri(term))
35
+ images = response['query']['pages'].map { |page_id, page| page['images'] }
36
+ if images!=[nil]
37
+ titles = images.flatten.map { |image| image['title'] }
38
+ titles.map do |title|
39
+ details(title)
40
+ end
41
+ end
42
+ end
43
+
44
+ def categorised_images(category)
45
+ # get a list of titles for the given term
46
+ response = json_get(category_uri(category))
47
+ images = response['query']['categorymembers']
48
+ if images!=[nil]
49
+ titles = images.flatten.map { |image| image['title'] }
50
+ titles.map do |title|
51
+ if title.start_with?('Category:')
52
+ categorised_images(title)
53
+ else
54
+ details(title)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def details(title)
61
+ return nil if /File:.*/.match(title) == nil
62
+ title = /File:[^#]*/.match(title)[0]
63
+ response = json_get(info_uri(title))
64
+ return {} if response == nil
65
+ pages = response['query']['pages'].map { |page_id, page| page }
66
+ return { description: 'missing' } if pages.first['missing']!=nil
67
+ categories = pages.first['categories'].map { |category| category['title'] }.flatten
68
+ categories = categories.map { |category| category.gsub(/^Category:/, '') }
69
+ descriptionurl = pages.first['imageinfo'].first['descriptionurl']
70
+ licence = pages.first['imageinfo'].first['extmetadata']['LicenseShortName']['value']
71
+ licence_url = pages.first['imageinfo'].first['extmetadata']['LicenseUrl']['value'] if pages.first['imageinfo'].first['extmetadata']['LicenseUrl']
72
+ if categories.include? 'CC-PD-Mark'
73
+ licence = 'CC-PD-Mark'
74
+ licence_url = 'http://creativecommons.org/publicdomain/mark/1.0'
75
+ end
76
+ licence_url = 'https://en.wikipedia.org/wiki/Public_domain' if licence == 'Public domain' && licence_url == nil
77
+ party = HTTParty.get(descriptionurl, :verify => false)
78
+ doc = Nokogiri::HTML(party.to_s)
79
+ an = doc.xpath('//span[@id="creator"]')
80
+ author_name = an[0].content if !an.empty?
81
+ if an.empty?
82
+ an = doc.xpath('//tr[td/@id="fileinfotpl_aut"]/td')
83
+ author_name = an[1].content if !an.empty? && an.size > 0
84
+ end
85
+ author_name = Sanitize.clean(author_name)
86
+ author_url = ""
87
+ au = doc.xpath('//span[@id="creator"]/*/a/@href')
88
+ au = doc.xpath('//tr[td/@id="fileinfotpl_aut"]/td/a/@href') if au.empty?
89
+ author_url = au[0].content if !au.empty? && au.size > 0
90
+ author_url = "http://commons.wikimedia.org" + author_url if author_url.start_with?('/wiki/User:')
91
+ description = ""
92
+ description_element = doc.xpath('//td[@class="description"]')
93
+ description = Sanitize.clean(description_element[0].content)[0,255].strip! if description_element.size > 0
94
+
95
+ geohack = doc.xpath("//a[contains(@href, 'tools.wmflabs.org/geohack')]/@href")
96
+ longitude = geohack[0] ? /params=.*_[NS]_(-*\d*.\d*)/.match(geohack[0].value)[1] : nil
97
+ latitude = geohack[0] ? /params=(\d*.\d*)/.match(geohack[0].value)[1] : nil
98
+
99
+ openplaques_url = doc.xpath("//a[contains(@href, 'openplaques.org/plaques')]/@href")
100
+ openplaques_id = openplaques_url[0] ? /plaques\/(\d*)/.match(openplaques_url[0].value)[1] : nil
101
+
102
+ page_url = "https://commons.wikimedia.org/wiki/"+title
103
+ {
104
+ categories: categories,
105
+ url: pages.first['imageinfo'].first['url'],
106
+ page_url: page_url,
107
+ description: description,
108
+ author: author_name,
109
+ author_url: author_url,
110
+ licence: licence,
111
+ licence_url: licence_url,
112
+ longitude: longitude,
113
+ latitude: latitude,
114
+ openplaques_id: openplaques_id
115
+ }
116
+ end
117
+
118
+ private
119
+
120
+ def json_get(uri)
121
+ response = HTTParty.get(uri, :verify => false)
122
+ if response.code == 200
123
+ JSON.parse(response.body)
124
+ else
125
+ raise Exception.new("bad status code from Wikimedia server (#{response.code}):\n#{response.body}")
126
+ end
127
+ end
128
+
129
+ def uri_for(params)
130
+ "#{@uri}?#{URI.encode_www_form(params)}"
131
+ end
132
+
133
+ def search_uri(query)
134
+ uri_for action: 'opensearch', search: query, limit: 100
135
+ end
136
+
137
+ def query_uri(term)
138
+ uri_for action: 'query', titles: term, prop: 'images', format: 'json'
139
+ end
140
+
141
+ def info_uri(image)
142
+ uri_for action: 'query', titles: image, prop: 'imageinfo|categories', iiprop: 'url|extmetadata', format: 'json'
143
+ end
144
+
145
+ def category_uri(term)
146
+ uri_for action: 'query', list: 'categorymembers', format: 'json', cmtitle: term
147
+ end
148
+
149
+ def default_uri
150
+ @default_uri ||= "https://commons.wikimedia.org/w/api.php"
151
+ end
152
+
153
+ end
154
+ end
@@ -0,0 +1,5 @@
1
+ module Wikimedia
2
+ class Commoner
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikimedia::Commoner do
4
+
5
+ describe '#author' do
6
+ context 'of a Delhi portrait of a man' do
7
+ it 'is Jorge Royan' do
8
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
9
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:India_-_Delhi_portrait_of_a_man_-_4780.jpg'
10
+ expect(image[:author]).to eq 'Jorge Royan'
11
+ end
12
+ end
13
+ end
14
+ context 'of Nahal Zaror, south 11' do
15
+ it 'is Daniel Baránek' do
16
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
17
+ image = Wikimedia::Commoner.details 'File:Nahal_Zaror,_south_11.jpg'
18
+ expect(image[:author]).to eq 'Daniel Baránek'
19
+ end
20
+ end
21
+ it 'is linked to Daniel Baránek wikimedia user page' do
22
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
23
+ image = Wikimedia::Commoner.details 'File:Nahal_Zaror,_south_11.jpg'
24
+ expect(image[:author_url]).to eq 'http://commons.wikimedia.org/wiki/User:Daniel_Bar%C3%A1nek'
25
+ end
26
+ end
27
+ end
28
+ context 'of The mohave desert near the fossil beds' do
29
+ it 'is unknown' do
30
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
31
+ image = Wikimedia::Commoner.details 'File:PSM_V86_D252_The_mohave_desert_near_the_fossil_beds.jpg'
32
+ expect(image[:author]).to eq 'Unknown'
33
+ end
34
+ end
35
+ end
36
+ context 'of a Spanish Civil War mass grave' do
37
+ it 'is Mario Modesto Mata' do
38
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
39
+ image = Wikimedia::Commoner.details 'File:Spanish_Civil_War_-_Mass_grave_-_Estépar,_Burgos.jpg'
40
+ expect(image[:author]).to eq 'Mario Modesto Mata'
41
+ end
42
+ end
43
+ end
44
+ context 'of August Wilhelm von Hofmann' do
45
+ it 'is unknown' do
46
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
47
+ image = Wikimedia::Commoner.details 'File:Hoffman_August_Wilhelm_von.jpg'
48
+ expect(image[:author]).to eq 'Unknown'
49
+ end
50
+ end
51
+ it 'is not linked to an author url' do
52
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
53
+ image = Wikimedia::Commoner.details 'File:Hoffman_August_Wilhelm_von.jpg'
54
+ expect(image[:author_url]).to eq ''
55
+ end
56
+ end
57
+ end
58
+ context 'of Catherine of Aragon portrait' do
59
+ it 'is Lucas Hornebolte' do
60
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
61
+ image = Wikimedia::Commoner.details 'File:Catherine_aragon.jpg'
62
+ expect(image[:author]).to eq 'Lucas Hornebolte'
63
+ end
64
+ end
65
+ end
66
+ context 'of Stepan Blois portrait' do
67
+ it 'is Matthew Paris' do
68
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
69
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:Stepan_Blois.jpg'
70
+ expect(image[:author]).to eq 'Matthew Paris'
71
+ end
72
+ end
73
+ it 'is linked to Matthew Paris Wikipedia page' do
74
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
75
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:Stepan_Blois.jpg'
76
+ expect(image[:author_url]).to eq '//en.wikipedia.org/wiki/Matthew_Paris'
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikimedia::Commoner do
4
+
5
+ describe '#searching' do
6
+ context 'on an unknown term' do
7
+ it 'finds nothing' do
8
+ VCR.use_cassette ('searching/' + self.class.description).gsub(" ","-") do
9
+ titles = Wikimedia::Commoner.search 'badger'
10
+ expect(titles).to eq([])
11
+ end
12
+ end
13
+ end
14
+ context 'on a known term' do
15
+ it 'finds some titles' do
16
+ VCR.use_cassette ('searching/' + self.class.description).gsub(" ","-") do
17
+ titles = Wikimedia::Commoner.search 'Meles meles'
18
+ expect(titles.size).to be > 0
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#images' do
25
+ context 'on a known term' do
26
+ it 'finds at least one image' do
27
+ VCR.use_cassette ('images/' + self.class.description).gsub(" ","-") do
28
+ images = Wikimedia::Commoner.images 'Meles meles'
29
+ first = images[0]
30
+ expect(first[:url].start_with?("https:")).to be(true)
31
+ end
32
+ end
33
+ end
34
+ context 'on an unknown term' do
35
+ it 'finds nothing' do
36
+ VCR.use_cassette ('images/' + self.class.description).gsub(" ","-") do
37
+ images = Wikimedia::Commoner.images 'plaques'
38
+ expect(images).to eq nil
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '#categorised_images' do
45
+ context 'a base category' do
46
+ it 'lists images categorised as this and within subcategories' do
47
+ VCR.use_cassette ('categorised_images/' + self.class.description).gsub(" ","-") do
48
+ images = Wikimedia::Commoner.categorised_images 'Category:Stolperstein-Plagiate'
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikimedia::Commoner do
4
+
5
+ describe '#details' do
6
+ context 'of a non-file page name' do
7
+ it 'gives details of a title' do
8
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
9
+ images = Wikimedia::Commoner.details 'Meles meles'
10
+ end
11
+ end
12
+ end
13
+ context 'of an unknown page name' do
14
+ it 'gives details of a title' do
15
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
16
+ image = Wikimedia::Commoner.details 'File:Does_not_exist.jpg'
17
+ expect(image[:description]).to eq 'missing'
18
+ end
19
+ end
20
+ end
21
+ context 'of a Commons file page' do
22
+ it 'gives details of a title' do
23
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
24
+ image = Wikimedia::Commoner.details 'File:Badger 25-07-09.jpg'
25
+ end
26
+ end
27
+ it 'gives has a page url' do
28
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
29
+ image = Wikimedia::Commoner.details 'File:Badger 25-07-09.jpg'
30
+ expect(image[:page_url]).to eq 'https://commons.wikimedia.org/wiki/File:Badger 25-07-09.jpg'
31
+ end
32
+ end
33
+ end
34
+ context 'of a full Commons file page url' do
35
+ it 'gives details of a title' do
36
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
37
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:Badger 25-07-09.jpg'
38
+ end
39
+ end
40
+ end
41
+ context 'of a Wikipedia image preview url' do
42
+ it 'gives details of a title' do
43
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
44
+ image = Wikimedia::Commoner.details 'https://en.wikipedia.org/wiki/Main_Page#mediaviewer/File:Suillus_pungens_123004.jpg'
45
+ end
46
+ end
47
+ end
48
+ context 'of a Wikipedia mobile image preview url' do
49
+ it 'gives details of a title' do
50
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
51
+ image = Wikimedia::Commoner.details 'https://en.m.wikipedia.org/wiki/Main_Page#mediaviewer/File:Suillus_pungens_123004.jpg'
52
+ end
53
+ end
54
+ end
55
+ context 'of url with a strange character in' do
56
+ it 'gives details of a title' do
57
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
58
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:Jacobäerschild_in_Bautzen.JPG'
59
+ end
60
+ end
61
+ end
62
+ context 'of url for Jacob with unicode in' do
63
+ it 'gives details of a title' do
64
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
65
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:Jacob%C3%A4erschild_in_Bautzen.JPG'
66
+ end
67
+ end
68
+ end
69
+ context 'of a deleted photo' do
70
+ it 'gives a description of "missing"' do
71
+ VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
72
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:Vancouver_-_Gastown_Steam_Clock_plaque.jpg'
73
+ expect(image[:description]).to eq 'missing'
74
+ end
75
+ end
76
+ end
77
+ context 'of a photo with extra bits on the end of the url' do
78
+ it 'gives a description of "missing"' do
79
+ # VCR.use_cassette ('details/' + self.class.description).gsub(" ","-") do
80
+ image = Wikimedia::Commoner.details 'https://commons.wikimedia.org/wiki/File:Plaque_in_Fortune_Street.jpg#.7B.7Bint:filedesc.7D.7D'
81
+ expect(image[:page_url]).to eq 'https://commons.wikimedia.org/wiki/File:Plaque_in_Fortune_Street.jpg'
82
+ # end
83
+ end
84
+ end
85
+ end
86
+
87
+ end