wikidata-client 0.0.6 → 0.0.7

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: 481fea0ff50fb59f774077d355a116e013938acc
4
- data.tar.gz: b6c966efa34763559016e69a3fc5a8827631da48
3
+ metadata.gz: 036b3598b8288484b5aebf973b3ae366126b5162
4
+ data.tar.gz: 523725c269c4d52fbb0e366cffc44d18aa9e071c
5
5
  SHA512:
6
- metadata.gz: 7790f67d9bc9ddea9ff9ccb211776e63c49ea70bb9a74a9eba839f56f17b31d291727c99f3277e00be008676a6bd5155b8a63a2dc312dd691a286539ab19dc2d
7
- data.tar.gz: af37ed1e5cee7bc64fd7182826ef167d690f99858d01f9ed643942489a8b769846b93fc232663a8b73892f9a424a815882dfb416bcb567ef50146efa24e91869
6
+ metadata.gz: 013beb7a6398f8b26bd835f2338e51e4c2a2b37895cba4779e8dbfe6ea5a397c6ecaf348f63993f35d1dc9f7bed63839b9e6baf17e6fdb0f0d9eb0873c39060c
7
+ data.tar.gz: f9ebc57fcfce61f37b6d975030742897fcde8c0e77e0828ec8528f4affde1f762ccdaca202f3f0dc478eab6f5efdfc419af3a8e7060e589096add92d6dbc867c
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.7
4
+
5
+ * Added support for commonsMedia images
6
+
7
+ ## 0.0.6
8
+
9
+ - Various fixes
10
+
11
+ ## 0.0.5
12
+
13
+ - Various fixes
14
+
3
15
  ## 0.0.4
4
16
 
5
17
  - HTTP client options more easily configurable
data/README.md CHANGED
@@ -9,12 +9,13 @@
9
9
 
10
10
  [Wikidata](http://www.wikidata.org/) client library for Ruby.
11
11
 
12
- It provide an easy way to search for wikidata pages and read their contents.
12
+ It provide an easy way to search for wikidata and wikipedia pages and read
13
+ their contents.
13
14
 
14
15
 
15
16
  ## Installation
16
17
 
17
- In bunler: `gem 'wikidata-client', '~> 0.0.6', require: 'wikidata'`
18
+ In bunler: `gem 'wikidata-client', '~> 0.0.7', require: 'wikidata'`
18
19
 
19
20
  Otherwise: `gem install wikidata-client`
20
21
 
@@ -0,0 +1,41 @@
1
+ module Wikidata
2
+ module Property
3
+ class CommonsMedia < Wikidata::Property::Base
4
+ BASE_PAGE_URL = "https://commons.wikimedia.org/wiki/File:%s.%s".freeze
5
+ IMAGE_URL = "https://upload.wikimedia.org/wikipedia/commons/%s/%s/%s.%s"
6
+ THUMB_IMAGE_URL = "https://upload.wikimedia.org/wikipedia/commons/thumb/%s/%s/%s.%s/%ipx-%s.%s"
7
+
8
+ def page_url
9
+ @_page_url ||= sprintf BASE_PAGE_URL, basename, extension
10
+ end
11
+
12
+ def url size = nil
13
+ if size
14
+ sprintf THUMB_IMAGE_URL, md5[0], md5[0..1], basename, extension, size, basename, extension, thumb_extension
15
+ else
16
+ sprintf IMAGE_URL, md5[0], md5[0..1], basename, extension
17
+ end
18
+ end
19
+
20
+ def md5
21
+ @_md5 ||= Digest::MD5.hexdigest "#{basename}.#{extension}"
22
+ end
23
+
24
+ def basename
25
+ @_basename ||= name.gsub ' ', '_'
26
+ end
27
+
28
+ def name
29
+ @_name ||= File.basename(value, ".#{extension}")
30
+ end
31
+
32
+ def thumb_extension
33
+ @_thumb_ext ||= extension == 'svg' ? 'svg.png' : extension
34
+ end
35
+
36
+ def extension
37
+ @_ext ||= File.extname(value).tr '.', ''
38
+ end
39
+ end
40
+ end
41
+ end
@@ -13,6 +13,8 @@ module Wikidata
13
13
  Wikidata::Property::Url.new attribute
14
14
  when 'wikibase-item'
15
15
  Wikidata::Item.find Wikidata::Entity.entity_id(attribute)
16
+ when 'commonsMedia'
17
+ Wikidata::Property::CommonsMedia.new attribute
16
18
  else
17
19
  puts "Unkown property type #{attribute.mainsnak.datatype}"
18
20
  end
@@ -1,3 +1,3 @@
1
1
  module Wikidata
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
  end
data/lib/wikidata.rb CHANGED
@@ -36,6 +36,7 @@ require 'wikidata/property/string'
36
36
  require 'wikidata/property/time'
37
37
  require 'wikidata/property/url'
38
38
  require 'wikidata/property/globe_coordinate'
39
+ require 'wikidata/property/commons_media'
39
40
  require 'wikidata/entity'
40
41
  require 'wikidata/item'
41
42
  require 'wikidata/response'
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wikidata::Property::CommonsMedia do
4
+ let(:image) {
5
+ described_class.new(
6
+ {
7
+ 'id' => 'Q6882$8CB12994-045E-4EB3-98F8-3975EA1BF9A7',
8
+ 'mainsnak' => {
9
+ 'snaktype' => 'value',
10
+ 'property' => 'P18',
11
+ 'datatype' => 'commonsMedia',
12
+ 'datavalue' => {
13
+ 'value' => 'Revolutionary Joyce Better Contrast.jpg',
14
+ 'type' => 'string'
15
+ }
16
+ },
17
+ 'type' => 'statement',
18
+ 'rank' => 'normal',
19
+ 'references' => [
20
+ {
21
+ 'hash' => 'd6e3ab4045fb3f3feea77895bc6b27e663fc878a',
22
+ 'snaks' => {
23
+ 'P143' => [
24
+ {
25
+ 'snaktype' => 'value',
26
+ 'property' => 'P143',
27
+ 'datatype' => 'wikibase-item',
28
+ 'datavalue' => {
29
+ 'value' => {
30
+ 'entity-type' => 'item',
31
+ 'numeric-id' => 206855
32
+ },
33
+ 'type' => 'wikibase-entityid'
34
+ }
35
+ }
36
+ ]
37
+ },
38
+ 'snaks-order' => ['P143']
39
+ }
40
+ ]
41
+ }
42
+ )
43
+ }
44
+
45
+ describe 'image' do
46
+ it "should return image page url" do
47
+ image.page_url.should eq "https://commons.wikimedia.org/wiki/File:Revolutionary_Joyce_Better_Contrast.jpg"
48
+ end
49
+
50
+ it "should return image extension" do
51
+ image.extension.should eq "jpg"
52
+ end
53
+
54
+ it "should return image name" do
55
+ image.name.should eq "Revolutionary Joyce Better Contrast"
56
+ end
57
+
58
+ it "should return image file base name" do
59
+ image.basename.should eq "Revolutionary_Joyce_Better_Contrast"
60
+ end
61
+
62
+ it "should return image url" do
63
+ image.url.should eq "https://upload.wikimedia.org/wikipedia/commons/1/1e/Revolutionary_Joyce_Better_Contrast.jpg"
64
+ end
65
+
66
+ it "should return image url for a given size" do
67
+ image.url(200).should eq "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/Revolutionary_Joyce_Better_Contrast.jpg/200px-Revolutionary_Joyce_Better_Contrast.jpg"
68
+ end
69
+ end
70
+ end
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency("faraday", "~> 0.9")
19
19
  s.add_dependency("faraday_middleware", "~> 0.9")
20
20
  s.add_dependency("hashie", "~> 3.3")
21
- s.add_development_dependency("excon", "~> 0.40")
21
+ s.add_dependency("excon", "~> 0.40")
22
+
22
23
  s.add_development_dependency("rspec", "~> 3.1")
23
24
  s.add_development_dependency("webmock", "~> 1.18")
24
25
  s.add_development_dependency("vcr", "~> 2.9")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikidata-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kévin Lacointe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-22 00:00:00.000000000 Z
11
+ date: 2015-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.40'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -142,11 +142,11 @@ executables: []
142
142
  extensions: []
143
143
  extra_rdoc_files: []
144
144
  files:
145
+ - ".gitignore"
145
146
  - ".rspec"
146
147
  - ".travis.yml"
147
148
  - CHANGELOG.md
148
149
  - Gemfile
149
- - Gemfile.lock
150
150
  - LICENCE
151
151
  - README.md
152
152
  - Rakefile
@@ -159,6 +159,7 @@ files:
159
159
  - lib/wikidata/item.rb
160
160
  - lib/wikidata/property.rb
161
161
  - lib/wikidata/property/base.rb
162
+ - lib/wikidata/property/commons_media.rb
162
163
  - lib/wikidata/property/globe_coordinate.rb
163
164
  - lib/wikidata/property/string.rb
164
165
  - lib/wikidata/property/time.rb
@@ -201,6 +202,7 @@ files:
201
202
  - spec/wikidata/client_spec.rb
202
203
  - spec/wikidata/entity_spec.rb
203
204
  - spec/wikidata/item_spec.rb
205
+ - spec/wikidata/property/common_media_spec.rb
204
206
  - spec/wikidata/property/time_spec.rb
205
207
  - spec/wikidata_spec.rb
206
208
  - wikidata-client.gemspec
@@ -264,5 +266,6 @@ test_files:
264
266
  - spec/wikidata/client_spec.rb
265
267
  - spec/wikidata/entity_spec.rb
266
268
  - spec/wikidata/item_spec.rb
269
+ - spec/wikidata/property/common_media_spec.rb
267
270
  - spec/wikidata/property/time_spec.rb
268
271
  - spec/wikidata_spec.rb
data/Gemfile.lock DELETED
@@ -1,78 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- wikidata-client (0.0.6)
5
- faraday (~> 0.9)
6
- faraday_middleware (~> 0.9)
7
- hashie (~> 3.3)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- addressable (2.3.6)
13
- codeclimate-test-reporter (0.4.1)
14
- simplecov (>= 0.7.1, < 1.0.0)
15
- coderay (1.1.0)
16
- crack (0.4.2)
17
- safe_yaml (~> 1.0.0)
18
- diff-lcs (1.2.5)
19
- docile (1.1.5)
20
- excon (0.40.0)
21
- faraday (0.9.1)
22
- multipart-post (>= 1.2, < 3)
23
- faraday_middleware (0.9.1)
24
- faraday (>= 0.7.4, < 0.10)
25
- ffi (1.9.5-java)
26
- hashie (3.4.1)
27
- method_source (0.8.2)
28
- multi_json (1.10.1)
29
- multipart-post (2.0.0)
30
- pry (0.10.1)
31
- coderay (~> 1.1.0)
32
- method_source (~> 0.8.1)
33
- slop (~> 3.4)
34
- pry (0.10.1-java)
35
- coderay (~> 1.1.0)
36
- method_source (~> 0.8.1)
37
- slop (~> 3.4)
38
- spoon (~> 0.0)
39
- rake (10.3.2)
40
- rspec (3.1.0)
41
- rspec-core (~> 3.1.0)
42
- rspec-expectations (~> 3.1.0)
43
- rspec-mocks (~> 3.1.0)
44
- rspec-core (3.1.4)
45
- rspec-support (~> 3.1.0)
46
- rspec-expectations (3.1.1)
47
- diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.1.0)
49
- rspec-mocks (3.1.1)
50
- rspec-support (~> 3.1.0)
51
- rspec-support (3.1.0)
52
- safe_yaml (1.0.4)
53
- simplecov (0.9.1)
54
- docile (~> 1.1.0)
55
- multi_json (~> 1.0)
56
- simplecov-html (~> 0.8.0)
57
- simplecov-html (0.8.0)
58
- slop (3.6.0)
59
- spoon (0.0.4)
60
- ffi
61
- vcr (2.9.3)
62
- webmock (1.19.0)
63
- addressable (>= 2.3.6)
64
- crack (>= 0.3.2)
65
-
66
- PLATFORMS
67
- java
68
- ruby
69
-
70
- DEPENDENCIES
71
- codeclimate-test-reporter
72
- excon (~> 0.40)
73
- pry (~> 0.10)
74
- rake (~> 10.3)
75
- rspec (~> 3.1)
76
- vcr (~> 2.9)
77
- webmock (~> 1.18)
78
- wikidata-client!